1
|
package eu.dnetlib.repo.manager.utils;
|
2
|
|
3
|
import eu.dnetlib.domain.functionality.validator.JobResultEntry;
|
4
|
import eu.dnetlib.domain.functionality.validator.StoredJob;
|
5
|
import org.eurocris.openaire.cris.validator.model.Job;
|
6
|
import org.eurocris.openaire.cris.validator.model.RuleResults;
|
7
|
|
8
|
import java.text.DateFormat;
|
9
|
import java.text.SimpleDateFormat;
|
10
|
import java.util.ArrayList;
|
11
|
import java.util.Date;
|
12
|
import java.util.List;
|
13
|
|
14
|
public class CrisValidatorUtils {
|
15
|
|
16
|
private static final DateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
17
|
private static final DateFormat DURATION_FORMATTER = new SimpleDateFormat("HH 'hours' mm 'min' ss 'sec'");
|
18
|
|
19
|
public static StoredJob convertJobToStoredJob(Job job) {
|
20
|
StoredJob sj = new StoredJob();
|
21
|
sj.setId(job.getId().hashCode());
|
22
|
sj.setValidationStatus(job.getStatus());
|
23
|
if (job.getDateFinished() != null) {
|
24
|
sj.setEnded(DATE_FORMATTER.format(job.getDateFinished()));
|
25
|
sj.setDuration(DURATION_FORMATTER.format(new Date(job.getDateFinished().getTime() - job.getDateStarted().getTime())));
|
26
|
} else {
|
27
|
sj.setEnded("-");
|
28
|
sj.setDuration("-");
|
29
|
}
|
30
|
sj.setStarted(DATE_FORMATTER.format(job.getDateStarted()));
|
31
|
|
32
|
sj.setUserEmail(job.getUser());
|
33
|
sj.setCris(true);
|
34
|
sj.setBaseUrl(job.getUrl());
|
35
|
sj.setValidationType("CU");
|
36
|
sj.setJobType("CRIS Validation");
|
37
|
sj.setGuidelinesShortName("For CRIS Managers 1.1");
|
38
|
sj.setValidationSet("-");
|
39
|
|
40
|
// Set status
|
41
|
sj.setValidationStatus(job.getStatus());
|
42
|
sj.setUsageJobStatus(job.getUsageJobStatus());
|
43
|
sj.setContentJobStatus(job.getContentJobStatus());
|
44
|
|
45
|
// Set scores
|
46
|
// sj.setFilteredScores(); // TODO what is this?
|
47
|
sj.setContentJobScore(job.getContentScore());
|
48
|
sj.setUsageJobScore(job.getUsageScore());
|
49
|
|
50
|
sj.setResultEntries(CrisValidatorUtils.crisResultsToJobEntries(job));
|
51
|
sj.setRecordsTested(job.getRecordsTested());
|
52
|
|
53
|
return sj;
|
54
|
}
|
55
|
|
56
|
public static List<JobResultEntry> crisResultsToJobEntries(Job crisJob) {
|
57
|
List<JobResultEntry> jobResultEntries = new ArrayList<>();
|
58
|
for (RuleResults ruleResults : crisJob.getRuleResults()) {
|
59
|
JobResultEntry jobResultEntry = new JobResultEntry();
|
60
|
jobResultEntry.setName(ruleResults.getRule().getName());
|
61
|
jobResultEntry.setRuleId(ruleResults.getRule().getId());
|
62
|
jobResultEntry.setDescription(ruleResults.getRule().getDescription());
|
63
|
jobResultEntry.setMandatory(true);
|
64
|
jobResultEntry.setWeight(Math.round(ruleResults.getRule().getWeight()));
|
65
|
jobResultEntry.setType(ruleResults.getRule().getType());
|
66
|
jobResultEntry.setHasErrors(false);
|
67
|
if (ruleResults.getCount() == 0) {
|
68
|
jobResultEntry.setSuccesses("-");
|
69
|
} else {
|
70
|
jobResultEntry.setSuccesses(ruleResults.getCount() - ruleResults.getFailed() + "/" + ruleResults.getCount());
|
71
|
}
|
72
|
if (ruleResults.getErrorMessages() != null && !ruleResults.getErrorMessages().isEmpty()) {
|
73
|
jobResultEntry.setErrors(ruleResults.getErrorMessages());
|
74
|
jobResultEntry.setHasErrors(true);
|
75
|
}
|
76
|
jobResultEntries.add(jobResultEntry);
|
77
|
}
|
78
|
return jobResultEntries;
|
79
|
}
|
80
|
|
81
|
private CrisValidatorUtils() {
|
82
|
}
|
83
|
}
|