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