114 lines
6.4 KiB
Java
114 lines
6.4 KiB
Java
package eu.dnetlib.repo.manager.service.controllers;
|
|
|
|
import eu.dnetlib.api.functionality.ValidatorService;
|
|
import eu.dnetlib.api.functionality.ValidatorServiceException;
|
|
import eu.dnetlib.domain.functionality.validator.StoredJob;
|
|
import eu.dnetlib.repo.manager.shared.Constants;
|
|
import eu.dnetlib.repo.manager.shared.JobsOfUser;
|
|
import gr.uoa.di.driver.util.ServiceLocator;
|
|
import io.swagger.annotations.ApiParam;
|
|
import org.apache.log4j.Logger;
|
|
import org.json.JSONException;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
@Component
|
|
public class MonitorApiImpl implements MonitorApi {
|
|
|
|
@Resource(name = "validatorServiceLocator")
|
|
private ServiceLocator<ValidatorService> validatorServiceLocator;
|
|
|
|
private ValidatorService getValidationService() {
|
|
return this.validatorServiceLocator.getService();
|
|
}
|
|
|
|
public ServiceLocator<ValidatorService> getValidatorServiceLocator() {
|
|
return validatorServiceLocator;
|
|
}
|
|
|
|
public void setValidatorServiceLocator(ServiceLocator<ValidatorService> validatorServiceLocator) {
|
|
this.validatorServiceLocator = validatorServiceLocator;
|
|
}
|
|
|
|
|
|
private static final Logger LOGGER = Logger
|
|
.getLogger(MonitorApiImpl.class);
|
|
|
|
@Override
|
|
public JobsOfUser getJobsOfUser(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
|
|
@RequestParam(value = "jobType", required = false)
|
|
@ApiParam(value = "Equals to filter job type on validation history page") String jobType,
|
|
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
|
|
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
|
|
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
|
|
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
|
|
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = false) String validationStatus,
|
|
@RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException {
|
|
|
|
LOGGER.debug("Getting jobs of user : " + user);
|
|
LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);
|
|
JobsOfUser retJobs = new JobsOfUser();
|
|
LOGGER.debug("Size of jobs list -> " + getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset),
|
|
Integer.parseInt(limit), dateFrom, dateTo, validationStatus).size());
|
|
retJobs.setJobs(getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset),
|
|
Integer.parseInt(limit), dateFrom, dateTo, validationStatus));
|
|
if (Boolean.parseBoolean(includeJobsTotal)) {
|
|
retJobs.setTotalJobs(this.getJobsTotalNumberOfUser(user, jobType, null));
|
|
retJobs.setTotalJobsSuccessful(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_SUCCESSFUL));
|
|
retJobs.setTotalJobsFailed(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_FAILED));
|
|
retJobs.setTotalJobsOngoing(this.getJobsTotalNumberOfUser(user, jobType,Constants.VALIDATION_JOB_STATUS_ONGOING));
|
|
}
|
|
|
|
//TODO fix status with new validator version
|
|
for(StoredJob job :retJobs.getJobs()){
|
|
if (job.getContentJobStatus().equals("ongoing") || job.getUsageJobStatus().equals("ongoing")) {
|
|
job.setValidationStatus("ongoing");
|
|
} else if ((job.getValidationType().equals("CU") && job.getContentJobStatus().equals("finished") && job.getUsageJobStatus().equals("finished") && job.getContentJobScore() > 50 && job.getUsageJobScore() > 50)
|
|
|| (job.getValidationType().equals("C") && job.getContentJobStatus().equals("finished") && job.getUsageJobStatus().equals("none") && job.getContentJobScore() > 50)
|
|
|| (job.getValidationType().equals("U") && job.getContentJobStatus().equals("none") && job.getUsageJobStatus().equals("finished") && job.getUsageJobScore() > 50)) {
|
|
job.setValidationStatus("successful");
|
|
} else if ((job.getValidationType().equals("CU") && job.getContentJobStatus().equals("finished") && job.getUsageJobStatus().equals("finished") && (job.getContentJobScore() <= 50 || job.getUsageJobScore() <= 50))
|
|
|| (job.getValidationType().equals("C") && job.getContentJobStatus().equals("finished") && job.getUsageJobStatus().equals("none") && job.getContentJobScore() <= 50)
|
|
|| (job.getValidationType().equals("U") && job.getContentJobStatus().equals("none") && job.getUsageJobStatus().equals("finished") && job.getUsageJobScore() <= 50) ) {
|
|
job.setValidationStatus("failed");
|
|
}
|
|
|
|
}
|
|
|
|
return retJobs;
|
|
|
|
}
|
|
|
|
private int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidatorServiceException {
|
|
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
|
|
}
|
|
|
|
@Override
|
|
public int getJobsOfUserPerValidationStatus(String user,
|
|
String jobType,
|
|
String validationStatus) throws JSONException {
|
|
LOGGER.debug("Getting job with validation status : " + validationStatus);
|
|
try {
|
|
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
|
|
} catch (ValidatorServiceException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public StoredJob getJobSummary(String jobId,
|
|
String groupBy) throws JSONException {
|
|
LOGGER.debug("Getting job summary with id : " + jobId);
|
|
try {
|
|
return getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
|
|
} catch (ValidatorServiceException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
}
|