1
|
package eu.dnetlib.repo.manager.service.controllers;
|
2
|
|
3
|
import eu.dnetlib.api.functionality.ValidatorService;
|
4
|
import eu.dnetlib.api.functionality.ValidatorServiceException;
|
5
|
import eu.dnetlib.domain.functionality.validator.StoredJob;
|
6
|
import eu.dnetlib.repo.manager.shared.Constants;
|
7
|
import eu.dnetlib.repo.manager.shared.JobsOfUser;
|
8
|
import gr.uoa.di.driver.util.ServiceLocator;
|
9
|
import io.swagger.annotations.ApiParam;
|
10
|
import org.apache.log4j.Logger;
|
11
|
import org.json.JSONException;
|
12
|
import org.springframework.stereotype.Component;
|
13
|
import org.springframework.web.bind.annotation.RequestParam;
|
14
|
|
15
|
import javax.annotation.Resource;
|
16
|
|
17
|
@Component
|
18
|
public class MonitorApiImpl implements MonitorApi {
|
19
|
|
20
|
@Resource(name = "validatorServiceLocator")
|
21
|
private ServiceLocator<ValidatorService> validatorServiceLocator;
|
22
|
|
23
|
private ValidatorService getValidationService() {
|
24
|
return this.validatorServiceLocator.getService();
|
25
|
}
|
26
|
|
27
|
public ServiceLocator<ValidatorService> getValidatorServiceLocator() {
|
28
|
return validatorServiceLocator;
|
29
|
}
|
30
|
|
31
|
public void setValidatorServiceLocator(ServiceLocator<ValidatorService> validatorServiceLocator) {
|
32
|
this.validatorServiceLocator = validatorServiceLocator;
|
33
|
}
|
34
|
|
35
|
|
36
|
private static final Logger LOGGER = Logger
|
37
|
.getLogger(MonitorApiImpl.class);
|
38
|
|
39
|
@Override
|
40
|
public JobsOfUser getJobsOfUser(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
|
41
|
@RequestParam(value = "jobType", required = false)
|
42
|
@ApiParam(value = "Equals to filter job type on validation history page") String jobType,
|
43
|
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
|
44
|
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
|
45
|
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
|
46
|
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
|
47
|
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = false) String validationStatus,
|
48
|
@RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException {
|
49
|
|
50
|
LOGGER.debug("Getting jobs of user : " + user);
|
51
|
LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);
|
52
|
JobsOfUser retJobs = new JobsOfUser();
|
53
|
retJobs.setJobs(getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset),
|
54
|
Integer.parseInt(limit), dateFrom, dateTo, validationStatus));
|
55
|
if (Boolean.parseBoolean(includeJobsTotal)) {
|
56
|
retJobs.setTotalJobs(this.getJobsTotalNumberOfUser(user, jobType, null));
|
57
|
retJobs.setTotalJobsSuccessful(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_SUCCESSFUL));
|
58
|
retJobs.setTotalJobsFailed(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_FAILED));
|
59
|
retJobs.setTotalJobsOngoing(this.getJobsTotalNumberOfUser(user, jobType,Constants.VALIDATION_JOB_STATUS_ONGOING));
|
60
|
}
|
61
|
|
62
|
//TODO fix status with new validator version
|
63
|
if(retJobs.getJobs() != null){
|
64
|
for(StoredJob job :retJobs.getJobs()){
|
65
|
if (job.getContentJobStatus().equals("ongoing") || job.getUsageJobStatus().equals("ongoing")) {
|
66
|
job.setValidationStatus("ongoing");
|
67
|
} else if ((job.getValidationType().equals("CU") && job.getContentJobStatus().equals("finished") && job.getUsageJobStatus().equals("finished") && job.getContentJobScore() > 50 && job.getUsageJobScore() > 50)
|
68
|
|| (job.getValidationType().equals("C") && job.getContentJobStatus().equals("finished") && job.getUsageJobStatus().equals("none") && job.getContentJobScore() > 50)
|
69
|
|| (job.getValidationType().equals("U") && job.getContentJobStatus().equals("none") && job.getUsageJobStatus().equals("finished") && job.getUsageJobScore() > 50)) {
|
70
|
job.setValidationStatus("successful");
|
71
|
} else if ((job.getValidationType().equals("CU") && job.getContentJobStatus().equals("finished") && job.getUsageJobStatus().equals("finished") && (job.getContentJobScore() <= 50 || job.getUsageJobScore() <= 50))
|
72
|
|| (job.getValidationType().equals("C") && job.getContentJobStatus().equals("finished") && job.getUsageJobStatus().equals("none") && job.getContentJobScore() <= 50)
|
73
|
|| (job.getValidationType().equals("U") && job.getContentJobStatus().equals("none") && job.getUsageJobStatus().equals("finished") && job.getUsageJobScore() <= 50) ) {
|
74
|
job.setValidationStatus("failed");
|
75
|
}
|
76
|
|
77
|
}
|
78
|
}
|
79
|
|
80
|
|
81
|
return retJobs;
|
82
|
|
83
|
}
|
84
|
|
85
|
private int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidatorServiceException {
|
86
|
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
|
87
|
}
|
88
|
|
89
|
@Override
|
90
|
public int getJobsOfUserPerValidationStatus(String user,
|
91
|
String jobType,
|
92
|
String validationStatus) throws JSONException {
|
93
|
LOGGER.debug("Getting job with validation status : " + validationStatus);
|
94
|
try {
|
95
|
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
|
96
|
} catch (ValidatorServiceException e) {
|
97
|
e.printStackTrace();
|
98
|
}
|
99
|
return 0;
|
100
|
}
|
101
|
|
102
|
@Override
|
103
|
public StoredJob getJobSummary(String jobId,
|
104
|
String groupBy) throws JSONException {
|
105
|
LOGGER.debug("Getting job summary with id : " + jobId);
|
106
|
try {
|
107
|
return getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
|
108
|
} catch (ValidatorServiceException e) {
|
109
|
e.printStackTrace();
|
110
|
}
|
111
|
return null;
|
112
|
}
|
113
|
|
114
|
}
|