1
|
package eu.dnetlib.repo.manager.client.browsehistory;
|
2
|
|
3
|
import com.google.gwt.core.client.GWT;
|
4
|
import com.google.gwt.dom.client.Document;
|
5
|
import com.google.gwt.event.dom.client.ClickEvent;
|
6
|
import com.google.gwt.event.dom.client.ClickHandler;
|
7
|
import com.google.gwt.query.client.Function;
|
8
|
import com.google.gwt.user.client.Event;
|
9
|
import com.google.gwt.user.client.Window;
|
10
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
11
|
import com.google.gwt.user.client.ui.Anchor;
|
12
|
import com.google.gwt.user.client.ui.FlowPanel;
|
13
|
import com.google.gwt.user.client.ui.HTML;
|
14
|
import eu.dnetlib.domain.data.Repository;
|
15
|
import eu.dnetlib.domain.functionality.validator.JobResultEntry;
|
16
|
import eu.dnetlib.domain.functionality.validator.StoredJob;
|
17
|
import eu.dnetlib.gwt.client.help.HelpService;
|
18
|
import eu.dnetlib.gwt.client.help.HelpServiceAsync;
|
19
|
import eu.dnetlib.repo.manager.client.AbstractRepositoryManagerWidget;
|
20
|
import eu.dnetlib.repo.manager.client.HelpCallback;
|
21
|
import eu.dnetlib.repo.manager.client.RepositoryManagerWidget;
|
22
|
import eu.dnetlib.repo.manager.client.services.ValidationService;
|
23
|
import eu.dnetlib.repo.manager.client.services.ValidationServiceAsync;
|
24
|
import org.apache.lucene.document.Field;
|
25
|
import org.gwtbootstrap3.client.ui.*;
|
26
|
import org.gwtbootstrap3.client.ui.constants.AlertType;
|
27
|
import org.gwtbootstrap3.client.ui.constants.ButtonType;
|
28
|
import org.gwtbootstrap3.client.ui.constants.ModalBackdrop;
|
29
|
import org.gwtbootstrap3.client.ui.html.UnorderedList;
|
30
|
|
31
|
import java.util.ArrayList;
|
32
|
import java.util.List;
|
33
|
|
34
|
import static com.google.gwt.query.client.GQuery.$;
|
35
|
|
36
|
/**
|
37
|
* Created by stefania on 4/4/16.
|
38
|
*/
|
39
|
public class ViewJobDetailsWidget extends AbstractRepositoryManagerWidget implements RepositoryManagerWidget {
|
40
|
|
41
|
private String parentToken = "";
|
42
|
private String restToken = "";
|
43
|
|
44
|
private HTML title = new HTML();
|
45
|
private FlowPanel viewJobDetailsBoxContent = new FlowPanel();
|
46
|
|
47
|
private Alert errorAlert = new Alert();
|
48
|
|
49
|
private FlowPanel helpPanel = new FlowPanel();
|
50
|
|
51
|
private StoredJob storedJob;
|
52
|
|
53
|
private List<JobResultEntry> contentResults = new ArrayList<>();
|
54
|
private List<JobResultEntry> usageResults = new ArrayList<>();
|
55
|
|
56
|
private ValidationServiceAsync validationService = GWT.create(ValidationService.class);
|
57
|
private static HelpServiceAsync helpService = GWT.create(HelpService.class);
|
58
|
|
59
|
public ViewJobDetailsWidget() {
|
60
|
|
61
|
super();
|
62
|
|
63
|
|
64
|
title.addStyleName("uk-margin-medium-bottom");
|
65
|
contentPanel.add(title);
|
66
|
// HTML title = new HTML("<h1 class=\"uk-article-title\">Validation results for</h1>");
|
67
|
// title.addStyleName("uk-margin-medium-bottom");
|
68
|
// contentPanel.add(title);
|
69
|
|
70
|
contentPanel.add(viewJobDetailsBoxContent);
|
71
|
|
72
|
errorAlert.setType(AlertType.DANGER);
|
73
|
errorAlert.setDismissable(false);
|
74
|
errorAlert.setVisible(false);
|
75
|
viewJobDetailsBoxContent.add(errorAlert);
|
76
|
}
|
77
|
|
78
|
@Override
|
79
|
public void clear() {
|
80
|
viewJobDetailsBoxContent.clear();
|
81
|
errorAlert.setVisible(false);
|
82
|
gridPanel.remove(helpPanel);
|
83
|
storedJob = null;
|
84
|
}
|
85
|
|
86
|
@Override
|
87
|
public void reload() {
|
88
|
|
89
|
Document.get().getElementById("headerNoTransparent").removeClassName("tm-header-transparent");
|
90
|
|
91
|
viewJobDetailsBoxContent.add(errorAlert);
|
92
|
|
93
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\" style=\"text-align: center; padding-top: 170px; " +
|
94
|
"color: rgb(47, 64, 80); font-weight: bold;\">Retrieving job details...</div>" +
|
95
|
"<div class=\"whiteFilm\"></div>");
|
96
|
viewJobDetailsBoxContent.addStyleName("loading-big");
|
97
|
viewJobDetailsBoxContent.add(loadingWheel);
|
98
|
|
99
|
helpService.getHelpById(parentToken + "_viewJobDetails", new HelpCallback(helpPanel, gridPanel));
|
100
|
|
101
|
validationService.getJobSummary(Integer.parseInt(restToken), "all", new AsyncCallback<StoredJob>() {
|
102
|
|
103
|
@Override
|
104
|
public void onFailure(Throwable caught) {
|
105
|
|
106
|
viewJobDetailsBoxContent.removeStyleName("loading-big");
|
107
|
viewJobDetailsBoxContent.remove(loadingWheel);
|
108
|
|
109
|
errorAlert.setText("System error retrieving job details");
|
110
|
errorAlert.setVisible(true);
|
111
|
}
|
112
|
|
113
|
@Override
|
114
|
public void onSuccess(StoredJob storedJob) {
|
115
|
|
116
|
ViewJobDetailsWidget.this.storedJob = storedJob;
|
117
|
|
118
|
// title.setHTML("<h1 class=\"uk-article-title\">Validation results for " + storedJob.getOfficialName() + "</h1>");
|
119
|
title.setHTML("<h1 class=\"uk-article-title\">Validation results for</h1>");
|
120
|
|
121
|
viewJobDetailsBoxContent.removeStyleName("loading-big");
|
122
|
viewJobDetailsBoxContent.remove(loadingWheel);
|
123
|
|
124
|
viewJobDetailsBoxContent.add(createGeneralInfoItem());
|
125
|
viewJobDetailsBoxContent.add(createInfoTags());
|
126
|
viewJobDetailsBoxContent.add(createUsageAndContentInfo());
|
127
|
|
128
|
addHandlers();
|
129
|
}
|
130
|
});
|
131
|
}
|
132
|
|
133
|
@Override
|
134
|
public void setToken(String parentToken, String rest) {
|
135
|
this.parentToken = parentToken;
|
136
|
this.restToken = rest;
|
137
|
}
|
138
|
|
139
|
@Override
|
140
|
public void afterAdditionToRootPanel() {
|
141
|
|
142
|
}
|
143
|
|
144
|
private FlowPanel createGeneralInfoItem() {
|
145
|
|
146
|
FlowPanel generalInfoItem = new FlowPanel();
|
147
|
|
148
|
String content = "<h4 class=\"uk-h4 uk-text-primary uk-scrollspy-inview uk-animation-slide-top-medium\"" +
|
149
|
"uk-scrollspy-class=\"\"><span>" + storedJob.getBaseUrl() + "</span></h4>" +
|
150
|
"<div class=\"uk-margin-small\">by " + storedJob.getUserEmail() + "</div>";
|
151
|
|
152
|
|
153
|
generalInfoItem.add(new HTML(content));
|
154
|
return generalInfoItem;
|
155
|
}
|
156
|
|
157
|
private FlowPanel createInfoTags() {
|
158
|
|
159
|
FlowPanel generalInfoTags = new FlowPanel();
|
160
|
|
161
|
String content = "<hr class=\"uk-scrollspy-inview uk-animation-slide-bottom-small\" uk-scrollspy-class=\"\">" +
|
162
|
"<div>" +
|
163
|
"<span class=\"\">" + storedJob.getJobType() + "</span> | " +
|
164
|
"<span class=\"\">" + storedJob.getGuidelinesShortName() + "</span> | " +
|
165
|
"<span class=\"\">Validation set: " + storedJob.getValidationSet() + "</span>" +
|
166
|
"</div>" +
|
167
|
"<div>" +
|
168
|
"<span class=\"\">Started: " + storedJob.getStarted() + "</span>, " +
|
169
|
"<span class=\"\">Ended: " + storedJob.getEnded() + "</span>, " +
|
170
|
"<span class=\"\">Duration: " + storedJob.getDuration() + "</span>" +
|
171
|
"</div>" +
|
172
|
"<div style=\"font-size: 120%\">" +
|
173
|
"<span class=\"\">Records tested: " + storedJob.getRecordsTested() + "</span>" +
|
174
|
"</div>" +
|
175
|
"<div>" +
|
176
|
"<span class=\"label label-primary uk-margin-right\">Score for content: " + storedJob.getContentJobScore() + "</span>" +
|
177
|
"<span class=\"label label-primary\">Score for usage: " + storedJob.getUsageJobScore() + "</span>" +
|
178
|
"</div>" +
|
179
|
"<hr class=\"uk-scrollspy-inview uk-animation-slide-bottom-small\" uk-scrollspy-class=\"\">";
|
180
|
|
181
|
generalInfoTags.add(new HTML(content));
|
182
|
return generalInfoTags;
|
183
|
}
|
184
|
|
185
|
private FlowPanel createUsageAndContentInfo() {
|
186
|
|
187
|
FlowPanel usageAndContentTabs = new FlowPanel();
|
188
|
|
189
|
UnorderedList tabTitles = new UnorderedList();
|
190
|
tabTitles.addStyleName("uk-margin el-nav uk-tab");
|
191
|
|
192
|
final ListItem contentTab = new ListItem();
|
193
|
final ListItem usageTab = new ListItem();
|
194
|
|
195
|
final ListItem contentTabContent = new ListItem();
|
196
|
final ListItem usageTabContent = new ListItem();
|
197
|
|
198
|
contentTab.addStyleName("uk-active");
|
199
|
Anchor contentTablLink = new Anchor("for Content");
|
200
|
contentTablLink.addClickHandler(new ClickHandler() {
|
201
|
@Override
|
202
|
public void onClick(ClickEvent event) {
|
203
|
contentTab.addStyleName("uk-active");
|
204
|
usageTab.removeStyleName("uk-active");
|
205
|
contentTabContent.addStyleName("uk-active");
|
206
|
usageTabContent.removeStyleName("uk-active");
|
207
|
}
|
208
|
});
|
209
|
contentTab.add(contentTablLink);
|
210
|
tabTitles.add(contentTab);
|
211
|
|
212
|
Anchor usageTabLink = new Anchor("for Usage");
|
213
|
usageTabLink.addClickHandler(new ClickHandler() {
|
214
|
@Override
|
215
|
public void onClick(ClickEvent event) {
|
216
|
usageTab.addStyleName("uk-active");
|
217
|
contentTab.removeStyleName("uk-active");
|
218
|
usageTabContent.addStyleName("uk-active");
|
219
|
contentTabContent.removeStyleName("uk-active");
|
220
|
}
|
221
|
});
|
222
|
usageTab.add(usageTabLink);
|
223
|
tabTitles.add(usageTab);
|
224
|
|
225
|
usageAndContentTabs.add(tabTitles);
|
226
|
|
227
|
UnorderedList tabContent = new UnorderedList();
|
228
|
tabContent.addStyleName("uk-switcher");
|
229
|
|
230
|
contentTabContent.addStyleName("el-item uk-active");
|
231
|
tabContent.add(contentTabContent);
|
232
|
|
233
|
usageTabContent.addStyleName("el-item");
|
234
|
tabContent.add(usageTabContent);
|
235
|
|
236
|
usageAndContentTabs.add(tabContent);
|
237
|
|
238
|
if(storedJob.getResultEntries()!=null) {
|
239
|
for (JobResultEntry jobResultEntry : storedJob.getResultEntries()) {
|
240
|
if (jobResultEntry.getType().equals("content"))
|
241
|
contentResults.add(jobResultEntry);
|
242
|
else
|
243
|
usageResults.add(jobResultEntry);
|
244
|
}
|
245
|
}
|
246
|
|
247
|
contentTabContent.add(rulesTable(contentResults));
|
248
|
usageTabContent.add(rulesTable(usageResults));
|
249
|
|
250
|
return usageAndContentTabs;
|
251
|
}
|
252
|
|
253
|
private FlowPanel rulesTable(List<JobResultEntry> jobResults) {
|
254
|
|
255
|
FlowPanel contentRules = new FlowPanel();
|
256
|
contentRules.addStyleName("uk-grid-margin uk-grid uk-grid-stack");
|
257
|
|
258
|
FlowPanel colPanel = new FlowPanel();
|
259
|
colPanel.addStyleName("uk-width-1-1@m uk-first-column");
|
260
|
contentRules.add(colPanel);
|
261
|
|
262
|
FlowPanel divPanel = new FlowPanel();
|
263
|
divPanel.addStyleName("uk-overflow-auto uk-scrollspy-inview uk-animation-slide-top-medium");
|
264
|
colPanel.add(divPanel);
|
265
|
|
266
|
String content = "<table class=\"uk-table uk-table-striped uk-table-middle rules-table\">" +
|
267
|
"<thead><tr><th>Rule Name</th><th class=\"uk-text-nowrap\">Rule Description</th>" +
|
268
|
"<th class=\"uk-text-nowrap\">Rule Weight</th><th class=\"uk-text-nowrap\"># of records</th>" +
|
269
|
"<th class=\"uk-text-nowrap\">Status</th></tr></thead>";
|
270
|
|
271
|
content += "<tbody>";
|
272
|
|
273
|
if(jobResults==null || jobResults.size()==0) {
|
274
|
|
275
|
content += "<tr class=\"el-item\">" +
|
276
|
"<td colspan=\"10\"><div class=\"alert alert-warning\">No result entries found</div></td>" +
|
277
|
"</tr>";
|
278
|
|
279
|
} else {
|
280
|
|
281
|
for (int i=0; i<jobResults.size(); i++) {
|
282
|
|
283
|
content += "<tr class=\"el-item\">" +
|
284
|
"<td class=\"uk-table-shrink\">" +
|
285
|
"<div class=\"el-title\">" + jobResults.get(i).getName() + "</div>" +
|
286
|
"</td>" +
|
287
|
"<td class=\"uk-table-shrink\">\n" +
|
288
|
"<div class=\"el-title\">" + jobResults.get(i).getDescription() + "</div>" +
|
289
|
"</td>" +
|
290
|
"<td class=\"uk-table-shrink\">\n" +
|
291
|
"<div class=\"el-title\">" + jobResults.get(i).getWeight() + "</div>" +
|
292
|
"</td>" +
|
293
|
"<td class=\"uk-table-shrink\">\n" +
|
294
|
"<div class=\"el-title\">" + jobResults.get(i).getSuccesses() + "</div>" +
|
295
|
"</td>" +
|
296
|
"<td class=\"uk-table-shrink\">\n";
|
297
|
|
298
|
if (jobResults.get(i).isHasErrors() && jobResults.get(i).isMandatory()) {
|
299
|
|
300
|
content += "<span uk-icon=\"icon: close\" style=\"color: #cd242b\"></span>" +
|
301
|
"<a href=\"javascript:;\" class=\"errorlink viewErrors uk-display-block\" id=\"" + jobResults.get(i).getType() + "#" + i + "\"><span>View Errors</span></a>";
|
302
|
// content += "<img src=\"img/icon_colours-x.jpg\" alt=\"Error\" class=\"el-image uk-preserve-width\" width=\"20\">" +
|
303
|
// "<a href=\"javascript:;\" class=\"errorlink viewErrors uk-display-block\" id=\"" + jobResults.get(i).getType() + "#" + i + "\"><span>View Errors</span></a>";
|
304
|
|
305
|
} else if (jobResults.get(i).isHasErrors() && !jobResults.get(i).isMandatory()) {
|
306
|
|
307
|
content += "<span uk-icon=\"icon: warning\" style=\"color: #e9d60d\"></span>" +
|
308
|
"<a href=\"javascript:;\" class=\"warninglink viewErrors uk-display-block\" id=\"" + jobResults.get(i).getType() + "#" + i + "\"><span>View Warnings</span></a>";
|
309
|
// content += "<img src=\"img/icon_colours-warning.jpg\" alt=\"Warning\" class=\"el-image uk-preserve-width\" width=\"20\">" +
|
310
|
// "<a href=\"javascript:;\" class=\"warninglink viewErrors uk-display-block\" id=\"" + jobResults.get(i).getType() + "#" + i + "\"><span>View Warnings</span></a>";
|
311
|
|
312
|
} else
|
313
|
content += "<span uk-icon=\"icon: check\" style=\"color: #4b991f\"></span>" ;
|
314
|
// content += "<img src=\"img/icon_colours-check.jpg\" alt=\"Success\" class=\"el-image uk-preserve-width\" width=\"20\">";
|
315
|
|
316
|
content += "</td>" +
|
317
|
"</tr>";
|
318
|
}
|
319
|
}
|
320
|
|
321
|
content += "</tbody></table>";
|
322
|
|
323
|
HTML contentRulesListHTML = new HTML();
|
324
|
contentRulesListHTML.setHTML(content);
|
325
|
|
326
|
divPanel.add(contentRulesListHTML);
|
327
|
|
328
|
return contentRules;
|
329
|
}
|
330
|
|
331
|
private void addHandlers() {
|
332
|
|
333
|
$(".viewErrors").click(new Function() {
|
334
|
|
335
|
public boolean f(Event e) {
|
336
|
|
337
|
String[] idParts = $(e).get(0).getId().split("#");
|
338
|
String jobType = idParts[0];
|
339
|
String index = idParts[1];
|
340
|
|
341
|
JobResultEntry jobResultEntry;
|
342
|
|
343
|
if(jobType.equals("content")) {
|
344
|
jobResultEntry = contentResults.get(Integer.parseInt(index));
|
345
|
} else {
|
346
|
jobResultEntry = usageResults.get(Integer.parseInt(index));
|
347
|
}
|
348
|
|
349
|
openErrorModal(jobResultEntry);
|
350
|
|
351
|
return true;
|
352
|
}
|
353
|
});
|
354
|
}
|
355
|
|
356
|
private void openErrorModal(JobResultEntry jobResultEntry) {
|
357
|
|
358
|
final Modal errorsModal = new Modal();
|
359
|
errorsModal.setDataBackdrop(ModalBackdrop.STATIC);
|
360
|
|
361
|
FlowPanel modalContent = new FlowPanel();
|
362
|
|
363
|
String content = "<h2 class=\"uk-modal-title\">Rule: " + jobResultEntry.getName() + "</h2>" +
|
364
|
"<p>See the list of errors found for this specific rule</p>";
|
365
|
|
366
|
for(String error : jobResultEntry.getErrors()) {
|
367
|
content += "<a class=\"uk-display-block\" target=\"_blank\" href=\"" + storedJob.getBaseUrl() +
|
368
|
"?verb=GetRecord&metadataPrefix=oai_dc&identifier=" + error + "\">" + error + "</a>";
|
369
|
}
|
370
|
|
371
|
HTML contentHTML = new HTML(content);
|
372
|
modalContent.add(contentHTML);
|
373
|
|
374
|
FlowPanel actionButtons = new FlowPanel();
|
375
|
actionButtons.addStyleName("uk-text-right");
|
376
|
modalContent.add(actionButtons);
|
377
|
|
378
|
Button no = new Button("Ok");
|
379
|
no.setType(ButtonType.DEFAULT);
|
380
|
no.addClickHandler(new ClickHandler() {
|
381
|
@Override
|
382
|
public void onClick(ClickEvent event) {
|
383
|
errorsModal.hide();
|
384
|
errorsModal.removeFromParent();
|
385
|
}
|
386
|
});
|
387
|
actionButtons.add(no);
|
388
|
|
389
|
ModalBody modalBody = new ModalBody();
|
390
|
modalBody.add(modalContent);
|
391
|
errorsModal.add(modalBody);
|
392
|
errorsModal.getElement().getChild(0).getChild(0).getChild(0).removeFromParent();
|
393
|
|
394
|
errorsModal.show();
|
395
|
}
|
396
|
}
|