1 |
54525
|
panagiotis
|
package eu.dnetlib.repo.manager.service;
|
2 |
49236
|
panagiotis
|
|
3 |
|
|
import eu.dnetlib.api.functionality.ValidatorService;
|
4 |
|
|
import eu.dnetlib.api.functionality.ValidatorServiceException;
|
5 |
|
|
import eu.dnetlib.domain.functionality.validator.StoredJob;
|
6 |
50680
|
panagiotis
|
import eu.dnetlib.repo.manager.shared.Constants;
|
7 |
49763
|
panagiotis
|
import eu.dnetlib.repo.manager.shared.JobsOfUser;
|
8 |
49236
|
panagiotis
|
import gr.uoa.di.driver.util.ServiceLocator;
|
9 |
49410
|
panagiotis
|
import org.apache.log4j.Logger;
|
10 |
49362
|
panagiotis
|
import org.json.JSONException;
|
11 |
54525
|
panagiotis
|
import org.springframework.stereotype.Service;
|
12 |
50631
|
panagiotis
|
|
13 |
49410
|
panagiotis
|
import javax.annotation.Resource;
|
14 |
49236
|
panagiotis
|
|
15 |
54525
|
panagiotis
|
@Service("monitorService")
|
16 |
54690
|
panagiotis
|
public class MonitorServiceImpl implements MonitorService {
|
17 |
49236
|
panagiotis
|
|
18 |
49410
|
panagiotis
|
@Resource(name = "validatorServiceLocator")
|
19 |
49236
|
panagiotis
|
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 |
49410
|
panagiotis
|
|
34 |
|
|
private static final Logger LOGGER = Logger
|
35 |
54690
|
panagiotis
|
.getLogger(MonitorServiceImpl.class);
|
36 |
49410
|
panagiotis
|
|
37 |
49236
|
panagiotis
|
@Override
|
38 |
54525
|
panagiotis
|
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 |
49236
|
panagiotis
|
|
47 |
49813
|
panagiotis
|
LOGGER.debug("Getting jobs of user : " + user);
|
48 |
50570
|
panagiotis
|
LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);
|
49 |
49431
|
panagiotis
|
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 |
49236
|
panagiotis
|
}
|
58 |
51330
|
panagiotis
|
|
59 |
|
|
//TODO fix status with new validator version
|
60 |
51525
|
panagiotis
|
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 |
51330
|
panagiotis
|
}
|
75 |
|
|
}
|
76 |
|
|
|
77 |
51525
|
panagiotis
|
|
78 |
49431
|
panagiotis
|
return retJobs;
|
79 |
49236
|
panagiotis
|
|
80 |
|
|
}
|
81 |
|
|
|
82 |
49431
|
panagiotis
|
private int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidatorServiceException {
|
83 |
|
|
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
|
84 |
|
|
}
|
85 |
|
|
|
86 |
49236
|
panagiotis
|
@Override
|
87 |
49410
|
panagiotis
|
public int getJobsOfUserPerValidationStatus(String user,
|
88 |
|
|
String jobType,
|
89 |
|
|
String validationStatus) throws JSONException {
|
90 |
49813
|
panagiotis
|
LOGGER.debug("Getting job with validation status : " + validationStatus);
|
91 |
49236
|
panagiotis
|
try {
|
92 |
|
|
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
|
93 |
|
|
} catch (ValidatorServiceException e) {
|
94 |
|
|
e.printStackTrace();
|
95 |
|
|
}
|
96 |
|
|
return 0;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
@Override
|
100 |
49410
|
panagiotis
|
public StoredJob getJobSummary(String jobId,
|
101 |
|
|
String groupBy) throws JSONException {
|
102 |
49813
|
panagiotis
|
LOGGER.debug("Getting job summary with id : " + jobId);
|
103 |
49236
|
panagiotis
|
try {
|
104 |
|
|
return getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
|
105 |
|
|
} catch (ValidatorServiceException e) {
|
106 |
|
|
e.printStackTrace();
|
107 |
|
|
}
|
108 |
|
|
return null;
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
}
|