/
Report.java
469 lines (387 loc) · 13.3 KB
/
Report.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE file at the root of the source
* tree and available online at
*
* https://github.com/keeps/roda
*/
package org.roda.core.data.v2.jobs;
import java.io.Serial;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.roda.core.data.v2.IsModelObject;
import org.roda.core.data.v2.ip.AIPState;
import org.roda.core.data.v2.ip.HasId;
import org.roda.core.data.v2.ip.HasInstanceID;
import org.roda.core.data.v2.ip.SIPInformation;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Report implements IsModelObject, HasId, HasInstanceID {
@Serial
private static final long serialVersionUID = 4316398565678538090L;
public static final String NO_SOURCE_OBJECT_ID = "NO_SOURCE_ID";
public static final String NO_SOURCE_OBJECT_CLASS = "NO_SOURCE_CLASS";
public static final String NO_OUTCOME_OBJECT_ID = "NO_OUTCOME_ID";
public static final String NO_OUTCOME_OBJECT_CLASS = "NO_OUTCOME_CLASS";
private String id = "";
private String jobId = "";
private String sourceObjectId = NO_SOURCE_OBJECT_ID;
private String sourceObjectClass = NO_SOURCE_OBJECT_CLASS;
private List<String> sourceObjectOriginalIds = new ArrayList<>();
private String sourceObjectOriginalName = "";
private String outcomeObjectId = NO_OUTCOME_OBJECT_ID;
private String outcomeObjectClass = NO_OUTCOME_OBJECT_CLASS;
private AIPState outcomeObjectState = AIPState.getDefault();
private String title = "";
private Date dateCreated;
private Date dateUpdated;
private String ingestType = "";
private Integer completionPercentage = 0;
private Integer stepsCompleted = 0;
private Integer totalSteps = 0;
private String plugin = "";
private String pluginName = "";
private String pluginVersion = "";
private PluginState pluginState = PluginState.RUNNING;
private Boolean pluginIsMandatory = true;
private String pluginDetails = "";
private boolean htmlPluginDetails = false;
private String instanceId = null;
@JsonIgnore
private SIPInformation sipInformation = new SIPInformation();
private List<Report> reports = new ArrayList<>();
private String lineSeparator = "";
public Report() {
super();
dateCreated = new Date();
dateUpdated = null;
}
/**
* Copy constructor (only doesn't copy the reports)
*/
public Report(Report report) {
super();
this.id = report.getId();
this.jobId = report.getJobId();
this.sourceObjectId = report.getSourceObjectId();
this.sourceObjectClass = report.getSourceObjectClass();
this.sourceObjectOriginalIds = report.getSourceObjectOriginalIds();
this.sourceObjectOriginalName = report.getSourceObjectOriginalName();
this.outcomeObjectId = report.getOutcomeObjectId();
this.outcomeObjectClass = report.getOutcomeObjectClass();
this.outcomeObjectState = report.getOutcomeObjectState();
this.title = report.getTitle();
this.dateCreated = report.getDateCreated();
this.dateUpdated = report.getDateUpdated();
this.ingestType = report.getIngestType();
this.completionPercentage = report.getCompletionPercentage();
this.stepsCompleted = report.getStepsCompleted();
this.totalSteps = report.getTotalSteps();
this.plugin = report.getPlugin();
this.pluginName = report.getPluginName();
this.pluginVersion = report.getPluginVersion();
this.pluginState = report.getPluginState();
this.pluginIsMandatory = report.getPluginIsMandatory();
this.pluginDetails = report.getPluginDetails();
this.htmlPluginDetails = report.isHtmlPluginDetails();
this.reports = new ArrayList<>();
this.instanceId = report.getInstanceId();
}
@JsonIgnore
@Override
public int getClassVersion() {
return 1;
}
@Override
public String getId() {
return id;
}
@Override
public void setId(String id) {
this.id = id;
}
public String getJobId() {
return jobId;
}
public void setJobId(String jobId) {
this.jobId = jobId;
}
public String getSourceObjectId() {
return sourceObjectId;
}
/**
* 20180713 hsilva: to ensure that both source & outcome object ids are set,
* this method should only be used for PluginHelper & POJO related operations
* like marshalling, etc...
*/
@Deprecated
public Report setSourceObjectId(String sourceObjectId) {
this.sourceObjectId = sourceObjectId;
return this;
}
public String getSourceObjectClass() {
return sourceObjectClass;
}
/**
* 20180713 hsilva: to ensure that both source & outcome object ids class are
* this method should only be used for PluginHelper & POJO related operations
* like marshalling, etc...
*/
@Deprecated
public Report setSourceObjectClass(String sourceObjectClass) {
this.sourceObjectClass = sourceObjectClass;
return this;
}
public List<String> getSourceObjectOriginalIds() {
return sourceObjectOriginalIds;
}
public Report setSourceObjectOriginalIds(List<String> sourceObjectOriginalIds) {
this.sourceObjectOriginalIds = sourceObjectOriginalIds;
return this;
}
public String getSourceObjectOriginalName() {
return sourceObjectOriginalName;
}
public Report setSourceObjectOriginalName(String sourceObjectOriginalName) {
this.sourceObjectOriginalName = sourceObjectOriginalName;
return this;
}
public String getOutcomeObjectId() {
return outcomeObjectId;
}
/**
* 20180713 hsilva: to ensure that both source & outcome object ids are set,
* this method should only be used for PluginHelper & POJO related operations
* like marshalling, etc...
*/
@Deprecated
public Report setOutcomeObjectId(String outcomeObjectId) {
this.outcomeObjectId = outcomeObjectId;
return this;
}
public Report setSourceAndOutcomeObjectId(String sourceObjectId, String outcomeObjectId) {
this.sourceObjectId = sourceObjectId;
this.outcomeObjectId = outcomeObjectId;
return this;
}
public String getOutcomeObjectClass() {
return outcomeObjectClass;
}
/**
* 20180713 hsilva: to ensure that both source & outcome object ids class are
* this method should only be used for PluginHelper & POJO related operations
* like marshalling, etc...
*/
@Deprecated
public Report setOutcomeObjectClass(String outcomeObjectClass) {
this.outcomeObjectClass = outcomeObjectClass;
return this;
}
public Report setSourceAndOutcomeObjectClass(String sourceObjectClass, String outcomeObjectClass) {
this.sourceObjectClass = sourceObjectClass;
this.outcomeObjectClass = outcomeObjectClass;
return this;
}
public AIPState getOutcomeObjectState() {
return outcomeObjectState;
}
public Report setOutcomeObjectState(AIPState outcomeObjectState) {
this.outcomeObjectState = outcomeObjectState;
return this;
}
public String getTitle() {
return title;
}
public Report setTitle(String title) {
this.title = title;
return this;
}
public Date getDateCreated() {
return dateCreated;
}
public Report setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
return this;
}
public Date getDateUpdated() {
return dateUpdated;
}
public Report setDateUpdated(Date dateUpdated) {
this.dateUpdated = dateUpdated;
return this;
}
public Integer getCompletionPercentage() {
return completionPercentage;
}
public Report setCompletionPercentage(Integer completionPercentage) {
this.completionPercentage = completionPercentage;
return this;
}
public Integer getStepsCompleted() {
return stepsCompleted;
}
public Report setStepsCompleted(Integer stepsCompleted) {
this.stepsCompleted = stepsCompleted;
return this;
}
public Integer getTotalSteps() {
return totalSteps;
}
public Report setTotalSteps(Integer totalSteps) {
this.totalSteps = totalSteps;
return this;
}
public String getPlugin() {
return plugin;
}
public Report setPlugin(String plugin) {
this.plugin = plugin;
return this;
}
public String getPluginName() {
return pluginName;
}
public Report setPluginName(String pluginName) {
this.pluginName = pluginName;
return this;
}
public String getPluginVersion() {
return pluginVersion;
}
public Report setPluginVersion(String pluginVersion) {
this.pluginVersion = pluginVersion;
return this;
}
public PluginState getPluginState() {
return pluginState;
}
public Report setPluginState(PluginState pluginState) {
this.pluginState = pluginState;
return this;
}
public Boolean getPluginIsMandatory() {
return pluginIsMandatory;
}
public void setPluginIsMandatory(Boolean pluginIsMandatory) {
this.pluginIsMandatory = pluginIsMandatory;
}
public String getPluginDetails() {
return pluginDetails;
}
public Report setPluginDetails(String pluginDetails) {
this.pluginDetails = pluginDetails;
return this;
}
public Report addPluginDetails(String pluginDetails) {
this.pluginDetails += pluginDetails;
return this;
}
public boolean isHtmlPluginDetails() {
return htmlPluginDetails;
}
public Report setHtmlPluginDetails(boolean htmlPluginDetails) {
this.htmlPluginDetails = htmlPluginDetails;
return this;
}
public String getIngestType() { return ingestType; }
public void setIngestType(String status) { this.ingestType = status; }
public String getInstanceId() {
return instanceId;
}
public void setInstanceId(String instanceId) {
this.instanceId = instanceId;
}
@JsonIgnore
public SIPInformation getSipInformation() {
return sipInformation;
}
@JsonIgnore
public void setSipInformation(SIPInformation sipInformation) {
this.sipInformation = sipInformation;
}
public Report addReport(Report report) {
return addReport(report, true);
}
public Report addReport(Report report, boolean updateReportItemDateUpdated) {
// FIXME not quite sure that this is the best place for this logic but it's
// very handy
if (updateReportItemDateUpdated) {
report.setDateUpdated(new Date());
}
setDateUpdated(report.getDateUpdated());
if (totalSteps == 0 && report.getTotalSteps() != 0) {
setTotalSteps(report.getTotalSteps());
}
stepsCompleted = stepsCompleted + 1;
if (totalSteps != 0) {
completionPercentage = Math.round((100f / totalSteps) * stepsCompleted);
}
if ("".equals(getPlugin())) {
setPlugin(report.getPlugin());
}
if ("".equals(getPluginName())) {
setPluginName(report.getPluginName());
}
if ("".equals(getPluginVersion())) {
setPluginVersion(report.getPluginVersion());
}
setPluginState(
ReportUtils.calculatePluginState(getPluginState(), report.getPluginState(), report.getPluginIsMandatory()));
if (!"".equals(report.getPluginDetails()) && !getPluginDetails().equals(report.getPluginDetails())) {
setPluginDetails(
(!"".equals(getPluginDetails()) ? getPluginDetails() + lineSeparator : "") + report.getPluginDetails());
}
setOutcomeObjectState(report.getOutcomeObjectState());
reports.add(report);
return this;
}
/*
* @JsonIgnore private PluginState calculatePluginState(PluginState
* currentPluginState, PluginState newPluginState, Boolean pluginIsMandatory) {
* if (pluginIsMandatory) { if
* (currentPluginState.equals(PluginState.PARTIAL_SUCCESS)) { switch
* (newPluginState) { case SKIPPED: case RUNNING: case SUCCESS: return
* PluginState.PARTIAL_SUCCESS; case FAILURE: return PluginState.FAILURE; } }
* else if (newPluginState.equals(PluginState.SKIPPED)){ return
* currentPluginState; } else { return newPluginState; } } else { if
* (!currentPluginState.equals(PluginState.FAILURE)) { if
* (newPluginState.equals(PluginState.FAILURE)) { return
* PluginState.PARTIAL_SUCCESS; } } }
*
* return newPluginState; }
*/
public List<Report> getReports() {
return reports;
}
public Report setReports(List<Report> reports) {
this.reports = reports;
return this;
}
public void injectLineSeparator(String lineSeparator) {
this.lineSeparator = lineSeparator;
}
@JsonIgnore
public String getLineSeparator() {
return lineSeparator;
}
@JsonIgnore
public Report getLastRunPlugin() {
int size = reports.size();
if (size == 0)
return null;
return reports.get(size - 1);
}
@Override
public String toString() {
return "Report [id=" + id + ", jobId=" + jobId + ", sourceObjectId=" + sourceObjectId + ", sourceObjectClass="
+ sourceObjectClass + ", sourceObjectOriginalIds=" + sourceObjectOriginalIds + ", outcomeObjectId="
+ outcomeObjectId + ", outcomeObjectClass=" + outcomeObjectClass + ", outcomeObjectState=" + outcomeObjectState
+ ", title=" + title + ", dateCreated=" + dateCreated + ", dateUpdated=" + dateUpdated + ", completionPercentage="
+ completionPercentage + ", stepsCompleted=" + stepsCompleted + ", totalSteps=" + totalSteps + ", plugin="
+ plugin + ", pluginName=" + pluginName + ", pluginVersion=" + pluginVersion + ", pluginState=" + pluginState
+ ", pluginIsMandatory=" + pluginIsMandatory + ", pluginDetails=" + pluginDetails + ", htmlPluginDetails="
+ htmlPluginDetails + ", reports=" + reports + ", instanceId=" + instanceId + "]";
}
}