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) @ApiParam(value = "Equals to filter job type on validation history page") String jobType,
|
42
|
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
|
43
|
@RequestParam(value = "limit", required = false, defaultValue = "10") @ApiParam(value = "Null value") String limit,
|
44
|
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
|
45
|
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
|
46
|
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus,
|
47
|
@RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException {
|
48
|
|
49
|
LOGGER.debug("Getting jobs of user : " + user);
|
50
|
LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);
|
51
|
JobsOfUser retJobs = new JobsOfUser();
|
52
|
LOGGER.debug("Size fo jobs list -> " + getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset),
|
53
|
Integer.parseInt(limit), dateFrom, dateTo, validationStatus));
|
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
|
return retJobs;
|
63
|
|
64
|
}
|
65
|
|
66
|
private int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidatorServiceException {
|
67
|
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
|
68
|
}
|
69
|
|
70
|
@Override
|
71
|
public int getJobsOfUserPerValidationStatus(String user,
|
72
|
String jobType,
|
73
|
String validationStatus) throws JSONException {
|
74
|
LOGGER.debug("Getting job with validation status : " + validationStatus);
|
75
|
try {
|
76
|
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
|
77
|
} catch (ValidatorServiceException e) {
|
78
|
e.printStackTrace();
|
79
|
}
|
80
|
return 0;
|
81
|
}
|
82
|
|
83
|
@Override
|
84
|
public StoredJob getJobSummary(String jobId,
|
85
|
String groupBy) throws JSONException {
|
86
|
LOGGER.debug("Getting job summary with id : " + jobId);
|
87
|
try {
|
88
|
return getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
|
89
|
} catch (ValidatorServiceException e) {
|
90
|
e.printStackTrace();
|
91
|
}
|
92
|
return null;
|
93
|
}
|
94
|
|
95
|
}
|