84 lines
3.4 KiB
Java
84 lines
3.4 KiB
Java
package eu.dnetlib.repo.manager.utils;
|
|
|
|
import eu.dnetlib.domain.functionality.validator.JobResultEntry;
|
|
import eu.dnetlib.domain.functionality.validator.StoredJob;
|
|
import org.eurocris.openaire.cris.validator.model.Job;
|
|
import org.eurocris.openaire.cris.validator.model.RuleResults;
|
|
|
|
import java.text.DateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
public class CrisValidatorUtils {
|
|
|
|
private static final DateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
private static final DateFormat DURATION_FORMATTER = new SimpleDateFormat("HH 'hours' mm 'min' ss 'sec'");
|
|
|
|
public static StoredJob convertJobToStoredJob(Job job) {
|
|
StoredJob sj = new StoredJob();
|
|
sj.setId(job.getId().hashCode());
|
|
sj.setValidationStatus(job.getStatus());
|
|
if (job.getDateFinished() != null) {
|
|
sj.setEnded(DATE_FORMATTER.format(job.getDateFinished()));
|
|
sj.setDuration(DURATION_FORMATTER.format(new Date(job.getDateFinished().getTime() - job.getDateStarted().getTime())));
|
|
} else {
|
|
sj.setEnded("-");
|
|
sj.setDuration("-");
|
|
}
|
|
sj.setStarted(DATE_FORMATTER.format(job.getDateStarted()));
|
|
|
|
sj.setUserEmail(job.getUser());
|
|
sj.setCris(true);
|
|
sj.setBaseUrl(job.getUrl());
|
|
sj.setValidationType("CU");
|
|
sj.setJobType("CRIS Validation");
|
|
sj.setGuidelinesShortName("For CRIS Managers 1.1");
|
|
sj.setValidationSet("-");
|
|
|
|
// Set status
|
|
sj.setValidationStatus(job.getStatus());
|
|
sj.setUsageJobStatus(job.getUsageJobStatus());
|
|
sj.setContentJobStatus(job.getContentJobStatus());
|
|
|
|
// Set scores
|
|
// sj.setFilteredScores(); // TODO what is this?
|
|
sj.setContentJobScore(job.getContentScore());
|
|
sj.setUsageJobScore(job.getUsageScore());
|
|
|
|
sj.setResultEntries(CrisValidatorUtils.crisResultsToJobEntries(job));
|
|
sj.setRecordsTested(job.getRecordsTested());
|
|
|
|
return sj;
|
|
}
|
|
|
|
public static List<JobResultEntry> crisResultsToJobEntries(Job crisJob) {
|
|
List<JobResultEntry> jobResultEntries = new ArrayList<>();
|
|
for (RuleResults ruleResults : crisJob.getRuleResults()) {
|
|
JobResultEntry jobResultEntry = new JobResultEntry();
|
|
jobResultEntry.setName(ruleResults.getRule().getName());
|
|
jobResultEntry.setRuleId(ruleResults.getRule().getId());
|
|
jobResultEntry.setDescription(ruleResults.getRule().getDescription());
|
|
jobResultEntry.setMandatory(true);
|
|
jobResultEntry.setWeight(Math.round(ruleResults.getRule().getWeight()));
|
|
jobResultEntry.setType(ruleResults.getRule().getType());
|
|
jobResultEntry.setHasErrors(false);
|
|
if (ruleResults.getCount() == 0) {
|
|
jobResultEntry.setSuccesses("-");
|
|
} else {
|
|
jobResultEntry.setSuccesses(ruleResults.getCount() - ruleResults.getFailed() + "/" + ruleResults.getCount());
|
|
}
|
|
if (ruleResults.getErrorMessages() != null && !ruleResults.getErrorMessages().isEmpty()) {
|
|
jobResultEntry.setErrors(ruleResults.getErrorMessages());
|
|
jobResultEntry.setHasErrors(true);
|
|
}
|
|
jobResultEntries.add(jobResultEntry);
|
|
}
|
|
return jobResultEntries;
|
|
}
|
|
|
|
private CrisValidatorUtils() {
|
|
}
|
|
}
|