/
ShowJobReport.java
361 lines (305 loc) · 12.7 KB
/
ShowJobReport.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
/**
* 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.wui.client.ingest.process;
import java.util.ArrayList;
import java.util.List;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
import org.roda.core.data.v2.jobs.IndexedReport;
import org.roda.core.data.v2.jobs.Report;
import org.roda.wui.client.browse.BrowserService;
import org.roda.wui.client.common.UserLogin;
import org.roda.wui.client.common.lists.pagination.ListSelectionUtils;
import org.roda.wui.client.common.utils.HtmlSnippetUtils;
import org.roda.wui.client.common.utils.JavascriptUtils;
import org.roda.wui.client.process.IngestProcess;
import org.roda.wui.client.services.Services;
import org.roda.wui.common.client.HistoryResolver;
import org.roda.wui.common.client.tools.HistoryUtils;
import org.roda.wui.common.client.tools.Humanize;
import org.roda.wui.common.client.tools.Humanize.DHMSFormat;
import org.roda.wui.common.client.tools.ListUtils;
import org.roda.wui.common.client.tools.StringUtils;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import config.i18n.client.ClientMessages;
/**
* @author Luis Faria
*
*/
public class ShowJobReport extends Composite {
public static final HistoryResolver RESOLVER = new HistoryResolver() {
@Override
public void resolve(List<String> historyTokens, final AsyncCallback<Widget> callback) {
if (historyTokens.size() == 3) {
String jobId = historyTokens.get(0);
String jobReportId = historyTokens.get(2);
retrieveJobReport(jobId, jobReportId, callback);
} else {
HistoryUtils.newHistory(IngestProcess.RESOLVER);
callback.onSuccess(null);
}
}
@Override
public void isCurrentUserPermitted(AsyncCallback<Boolean> callback) {
// TODO check for show job permission
UserLogin.getInstance().checkRoles(new HistoryResolver[] {IngestProcess.RESOLVER}, false, callback);
}
@Override
public List<String> getHistoryPath() {
return ListUtils.concat(ShowJob.RESOLVER.getHistoryPath(), getHistoryToken());
}
@Override
public String getHistoryToken() {
return "report";
}
};
interface MyUiBinder extends UiBinder<Widget, ShowJobReport> {
}
private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
private static final ClientMessages messages = GWT.create(ClientMessages.class);
// empty to get all report information
private static final List<String> fieldsToReturn = new ArrayList<>();
private static IndexedReport jobReport = new IndexedReport();
@UiField
Label instanceIdLabel;
@UiField
Label instanceIdValue;
@UiField
Anchor job;
@UiField
Label outcomeObjectLabel;
@UiField
Anchor outcomeObject;
@UiField
HTML outcomeObjectState;
@UiField
Label sourceObjectLabel;
@UiField
Anchor sourceObject;
@UiField
Label dateCreated;
@UiField
Label dateUpdated;
@UiField
Label duration;
@UiField
HTML status;
// FIXME 20160606 hsilva: added jobStateDetails
@UiField
Label progress;
@UiField
FlowPanel reportAttributes;
@UiField
FlowPanel reportItems;
@UiField
FlowPanel ingestTypePanel;
@UiField
Label ingestType;
@UiField
Button searchPrevious, searchNext, buttonBack;
@UiField
FocusPanel keyboardFocus;
private static void retrieveJobReport(String jobId, String jobReportId, AsyncCallback<Widget> callback) {
Services services = new Services("Get job report items", "get");
services.jobsResource(s -> s.getJobReport(jobId, jobReportId)).thenCompose(report -> services.futureFromObjectClass(report.getOutcomeObjectClass(), s -> s.findByUuid(report.getOutcomeObjectId())))
.whenComplete((o, error) -> {
if (o != null) {
GWT.log("OBJECT: " + o);
} else if (error != null) {
GWT.log("error" + error);
callback.onFailure(error);
}
});
BrowserService.Util.getInstance().retrieve(IndexedReport.class.getName(), jobReportId, fieldsToReturn,
new AsyncCallback<IndexedReport>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(IndexedReport jobReport) {
GWT.log("INDEXED REPORT: " + jobReport.getOutcomeObjectLabel());
retrieveJobReportItems(jobReport, callback);
}
});
}
private static void retrieveJobReportItems(IndexedReport jobReport, AsyncCallback<Widget> callback) {
BrowserService.Util.getInstance().retrieveJobReportItems(jobReport.getJobId(), jobReport.getId(),
new AsyncCallback<List<Report>>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(List<Report> reports) {
jobReport.setReports(reports);
ShowJobReport showJob = new ShowJobReport(jobReport);
callback.onSuccess(showJob);
}
});
}
public ShowJobReport(IndexedReport jobReport) {
this.jobReport = jobReport;
initWidget(uiBinder.createAndBindUi(this));
if (jobReport.getInstanceId() != null) {
instanceIdValue.setText(jobReport.getInstanceId());
} else {
instanceIdLabel.setVisible(false);
instanceIdValue.setVisible(false);
}
job.setText(jobReport.getJobName());
job.setHref(HistoryUtils.createHistoryHashLink(ShowJob.RESOLVER, jobReport.getJobId()));
outcomeObjectState.setVisible(false);
boolean hasSource = !jobReport.getSourceObjectOriginalIds().isEmpty() || !jobReport.getSourceObjectId().isEmpty();
if (hasSource) {
String idText = !jobReport.getSourceObjectOriginalIds().isEmpty()
? " (" + StringUtils.prettyPrint(jobReport.getSourceObjectOriginalIds()) + ")"
: "";
if (StringUtils.isNotBlank(jobReport.getSourceObjectOriginalName())) {
sourceObject.setText(jobReport.getSourceObjectOriginalName() + idText);
} else if (StringUtils.isNotBlank(jobReport.getSourceObjectLabel())) {
sourceObject.setText(jobReport.getSourceObjectLabel() + idText);
} else if (StringUtils.isNotBlank(jobReport.getSourceObjectId())) {
sourceObject.setText(jobReport.getSourceObjectId() + idText);
} else {
hasSource = false;
}
// sourceObject.setTitle(jobReport.getSourceObjectOriginalName());
sourceObject.setHref(HistoryUtils.createHistoryHashLink(
HistoryUtils.getHistoryUuidResolver(jobReport.getSourceObjectClass(), jobReport.getSourceObjectId())));
sourceObjectLabel.setText(messages.jobReportSource(jobReport.getSourceObjectClass()));
}
sourceObjectLabel.setVisible(hasSource);
sourceObject.setVisible(hasSource);
boolean hasOutcome = StringUtils.isNotBlank(jobReport.getOutcomeObjectId())
&& !jobReport.getOutcomeObjectId().equals(jobReport.getSourceObjectId());
if (hasOutcome) {
if (jobReport.getOutcomeObjectLabel() != null) {
outcomeObject.setText(jobReport.getOutcomeObjectLabel());
} else if (jobReport.getOutcomeObjectId() != null) {
outcomeObject.setText(jobReport.getOutcomeObjectId());
} else {
hasOutcome = false;
}
// outcomeObject.setTitle(jobReport.getSourceObjectOriginalName());
outcomeObject.setHref(HistoryUtils.createHistoryHashLink(
HistoryUtils.getHistoryUuidResolver(jobReport.getOutcomeObjectClass(), jobReport.getOutcomeObjectId())));
outcomeObjectLabel.setText(messages.jobReportOutcome(jobReport.getOutcomeObjectClass()));
outcomeObjectState.setHTML(HtmlSnippetUtils.getAIPStateHTML(jobReport.getOutcomeObjectState()));
}
outcomeObject.setVisible(hasOutcome);
outcomeObjectState.setVisible(hasOutcome);
outcomeObjectLabel.setVisible(hasOutcome);
dateCreated.setText(Humanize.formatDateTime(jobReport.getDateCreated()));
dateUpdated.setText(Humanize.formatDateTime(jobReport.getDateUpdated()));
duration.setText(Humanize.durationInDHMS(jobReport.getDateCreated(), jobReport.getDateUpdated(), DHMSFormat.LONG));
status.setHTML(HtmlSnippetUtils.getPluginStateHTML(jobReport.getPluginState()));
progress.setText(messages.showJobReportProgress(jobReport.getCompletionPercentage(), jobReport.getStepsCompleted(),
jobReport.getTotalSteps()));
ListSelectionUtils.bindLayout(jobReport, searchPrevious, searchNext, keyboardFocus, true, false, false);
//If it is an ingestion, creates a panel to render the type of Ingestion
if (jobReport.getIngestType() != null) {
ingestType.setText(jobReport.getIngestType().equals("NEW") ? messages.newIngestion() : messages.ingestionUpdate());
} else {
ingestTypePanel.setVisible(false);
}
for (Report reportItem : jobReport.getReports()) {
FlowPanel panel = new FlowPanel();
panel.setStyleName("panel");
panel.addStyleName("panel-counter");
reportItems.add(panel);
FlowPanel panelHeading = new FlowPanel();
panelHeading.setStyleName("panel-heading");
Label panelTitle = new Label(reportItem.getTitle());
HTML pluginMandatoryHTML = new HTML(HtmlSnippetUtils.getPluginMandatoryHTML(reportItem.getPluginIsMandatory()));
pluginMandatoryHTML.addStyleName("small");
panelTitle.setStyleName("panel-title");
panelHeading.add(panelTitle);
panelHeading.add(pluginMandatoryHTML);
panel.add(panelHeading);
FlowPanel panelBody = new FlowPanel();
panelBody.addStyleName("panel-body");
panel.add(panelBody);
Label attributeLabel = new Label(messages.reportAgent());
attributeLabel.setStyleName("label");
panelBody.add(attributeLabel);
String text;
if (StringUtils.isNotBlank(reportItem.getPluginVersion())) {
text = messages.pluginLabelWithVersion(reportItem.getPlugin(), reportItem.getPluginVersion());
} else {
text = messages.pluginLabel(reportItem.getPlugin());
}
Label attributeValue = new Label(text);
attributeValue.setStyleName("value");
panelBody.add(attributeValue);
attributeLabel = new Label(messages.reportStartDatetime());
attributeLabel.setStyleName("label");
panelBody.add(attributeLabel);
attributeValue = new Label(Humanize.formatDateTime(reportItem.getDateCreated()));
attributeValue.setStyleName("value");
panelBody.add(attributeValue);
attributeLabel = new Label(messages.reportEndDatetime());
attributeLabel.setStyleName("label");
panelBody.add(attributeLabel);
attributeValue = new Label(Humanize.formatDateTime(reportItem.getDateUpdated()));
attributeValue.setStyleName("value");
panelBody.add(attributeValue);
attributeLabel = new Label(messages.reportOutcome());
attributeLabel.setStyleName("label");
panelBody.add(attributeLabel);
HTML outcomeHTML = new HTML(HtmlSnippetUtils.getPluginStateHTML(reportItem.getPluginState()));
panelBody.add(outcomeHTML);
if (reportItem.getPluginDetails() != null && !"".equals(reportItem.getPluginDetails())) {
attributeLabel = new Label(messages.reportOutcomeDetails());
attributeLabel.setStyleName("label");
panelBody.add(attributeLabel);
if (reportItem.isHtmlPluginDetails()) {
attributeValue = new HTML(SafeHtmlUtils.fromTrustedString(reportItem.getPluginDetails()));
} else {
attributeValue = new Label(reportItem.getPluginDetails());
}
attributeValue.addStyleName("code-pre");
panelBody.add(attributeValue);
}
}
Element firstElement = this.getElement().getFirstChildElement();
if ("input".equalsIgnoreCase(firstElement.getTagName())) {
firstElement.removeFromParent();
}
}
@Override
protected void onLoad() {
super.onLoad();
JavascriptUtils.stickSidebar();
}
@UiHandler("buttonBack")
void buttonCancelHandler(ClickEvent e) {
cancel();
}
private void cancel() {
HistoryUtils.newHistory(ShowJob.RESOLVER, jobReport.getJobId());
}
}