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