2019-02-16 11:04:41 +01:00
|
|
|
package eu.dnetlib.repo.manager.service;
|
|
|
|
|
|
|
|
import eu.dnetlib.api.functionality.ValidatorService;
|
|
|
|
import eu.dnetlib.api.functionality.ValidatorServiceException;
|
|
|
|
import eu.dnetlib.domain.functionality.validator.StoredJob;
|
2019-11-28 12:25:56 +01:00
|
|
|
import eu.dnetlib.repo.manager.domain.Constants;
|
|
|
|
import eu.dnetlib.repo.manager.domain.JobsOfUser;
|
2020-03-18 23:39:25 +01:00
|
|
|
import eu.dnetlib.repo.manager.utils.CrisValidatorUtils;
|
2019-02-16 11:04:41 +01:00
|
|
|
import gr.uoa.di.driver.util.ServiceLocator;
|
2023-01-11 17:50:31 +01:00
|
|
|
import org.slf4j.Logger;
|
2019-11-20 14:03:40 +01:00
|
|
|
import org.eurocris.openaire.cris.validator.model.Job;
|
|
|
|
import org.eurocris.openaire.cris.validator.service.MapJobDao;
|
2019-02-16 11:04:41 +01:00
|
|
|
import org.json.JSONException;
|
2023-01-11 17:50:31 +01:00
|
|
|
import org.slf4j.LoggerFactory;
|
2019-11-20 14:03:40 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2019-02-16 11:04:41 +01:00
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
2019-11-20 14:03:40 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
@Service("monitorService")
|
|
|
|
public class MonitorServiceImpl implements MonitorService {
|
|
|
|
|
2023-01-11 17:50:31 +01:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(MonitorServiceImpl.class);
|
2022-12-14 15:33:12 +01:00
|
|
|
|
2019-11-20 14:03:40 +01:00
|
|
|
@Autowired
|
|
|
|
private MapJobDao crisJobs;
|
|
|
|
|
2019-02-16 11:04:41 +01:00
|
|
|
@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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public JobsOfUser getJobsOfUser(String user,
|
|
|
|
String jobType,
|
|
|
|
String offset,
|
|
|
|
String limit,
|
|
|
|
String dateFrom,
|
|
|
|
String dateTo,
|
|
|
|
String validationStatus,
|
|
|
|
String includeJobsTotal) throws JSONException, ValidatorServiceException {
|
|
|
|
|
2020-03-18 23:39:25 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
int crisOffset = 0;
|
|
|
|
int limitWithCris = 0;
|
|
|
|
if (offset.equals("0")) {
|
|
|
|
limitWithCris = crisJobs.getJobs(user, validationStatus).size();
|
|
|
|
} else {
|
|
|
|
crisOffset = crisJobs.getJobs(user, validationStatus).size();
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = String.valueOf(Math.max(Integer.parseInt(offset) - crisOffset, 0));
|
|
|
|
limit = String.valueOf(Math.max(Integer.parseInt(limit) - limitWithCris, 0));
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-02-16 11:04:41 +01:00
|
|
|
JobsOfUser retJobs = new JobsOfUser();
|
|
|
|
retJobs.setJobs(getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset),
|
|
|
|
Integer.parseInt(limit), dateFrom, dateTo, validationStatus));
|
2019-11-20 14:03:40 +01:00
|
|
|
|
2019-02-16 11:04:41 +01:00
|
|
|
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));
|
2020-03-18 23:39:25 +01:00
|
|
|
retJobs.setTotalJobsOngoing(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_ONGOING));
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO fix status with new validator version
|
2020-03-18 23:39:25 +01:00
|
|
|
if (retJobs.getJobs() != null) {
|
|
|
|
for (StoredJob job : retJobs.getJobs()) {
|
2019-02-16 11:04:41 +01:00
|
|
|
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)
|
2020-03-18 23:39:25 +01:00
|
|
|
|| (job.getValidationType().equals("U") && job.getContentJobStatus().equals("none") && job.getUsageJobStatus().equals("finished") && job.getUsageJobScore() <= 50)) {
|
2019-02-16 11:04:41 +01:00
|
|
|
job.setValidationStatus("failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2020-03-18 23:39:25 +01:00
|
|
|
|
|
|
|
|
2019-11-20 14:03:40 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
2020-03-18 23:39:25 +01:00
|
|
|
if (crisOffset == 0) {
|
|
|
|
List<StoredJob> jobs = new ArrayList<>();
|
2019-11-20 14:03:40 +01:00
|
|
|
|
2020-03-18 23:39:25 +01:00
|
|
|
List<Job> cj = crisJobs.getJobs(user, validationStatus);
|
|
|
|
for (Job job : cj) {
|
|
|
|
StoredJob sj = CrisValidatorUtils.convertJobToStoredJob(job);
|
2019-11-20 14:03:40 +01:00
|
|
|
jobs.add(sj);
|
2020-03-18 23:39:25 +01:00
|
|
|
|
|
|
|
// // filter out entries based on 'validationStatus'
|
|
|
|
// if ("all".equals(validationStatus)) {
|
|
|
|
// jobs.add(sj);
|
|
|
|
// } else {
|
|
|
|
// if (sj.getValidationStatus().equals(validationStatus)) {
|
|
|
|
// jobs.add(sj);
|
|
|
|
// }
|
|
|
|
// }
|
2019-11-20 14:03:40 +01:00
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2020-03-18 23:39:25 +01:00
|
|
|
// add to CRIS Jan jobs all other jobs
|
|
|
|
if (retJobs.getJobs() != null) {
|
|
|
|
jobs.addAll(retJobs.getJobs());
|
|
|
|
}
|
|
|
|
// set all jobs back to retJobs
|
|
|
|
retJobs.setJobs(jobs);
|
2019-11-20 14:03:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// fix number of jobs
|
|
|
|
if (Boolean.parseBoolean(includeJobsTotal)) {
|
|
|
|
retJobs.setTotalJobs(retJobs.getTotalJobs() + crisJobs.getJobs(user).size());
|
|
|
|
retJobs.setTotalJobsSuccessful(retJobs.getTotalJobsSuccessful() + crisJobs.getJobs(user, Job.Status.SUCCESSFUL.getKey()).size());
|
|
|
|
retJobs.setTotalJobsFailed(retJobs.getTotalJobsFailed() + crisJobs.getJobs(user, Job.Status.FAILED.getKey()).size());
|
|
|
|
retJobs.setTotalJobsOngoing(retJobs.getTotalJobsOngoing() + crisJobs.getJobs(user, Job.Status.ONGOING.getKey()).size());
|
|
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
return retJobs;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidatorServiceException {
|
2020-03-18 23:39:25 +01:00
|
|
|
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getJobsOfUserPerValidationStatus(String user,
|
|
|
|
String jobType,
|
|
|
|
String validationStatus) throws JSONException {
|
2022-12-14 15:33:12 +01:00
|
|
|
logger.debug("Getting job with validation status : " + validationStatus);
|
2020-03-18 23:39:25 +01:00
|
|
|
|
|
|
|
if (jobType.equalsIgnoreCase("cris")) {
|
|
|
|
return crisJobs.getJobs(user, validationStatus).size();
|
|
|
|
}
|
|
|
|
|
2019-02-16 11:04:41 +01:00
|
|
|
try {
|
|
|
|
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
|
|
|
|
} catch (ValidatorServiceException e) {
|
2023-01-11 17:50:31 +01:00
|
|
|
logger.error(e.getMessage(), e);
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StoredJob getJobSummary(String jobId,
|
|
|
|
String groupBy) throws JSONException {
|
2022-12-14 15:33:12 +01:00
|
|
|
logger.debug("Getting job summary with id : " + jobId);
|
2019-11-20 14:03:40 +01:00
|
|
|
StoredJob job = null;
|
2019-02-16 11:04:41 +01:00
|
|
|
try {
|
2019-11-20 14:03:40 +01:00
|
|
|
job = getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
|
2019-02-16 11:04:41 +01:00
|
|
|
} catch (ValidatorServiceException e) {
|
2023-01-11 17:50:31 +01:00
|
|
|
logger.error(e.getMessage(), e);
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
2019-11-20 14:03:40 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
if (job == null) {
|
|
|
|
// not a good way to do it but Job id field is string
|
|
|
|
List<Job> cJobs = crisJobs.getAll().stream().filter(j -> j.getId().hashCode() == Integer.parseInt(jobId)).collect(Collectors.toList());
|
|
|
|
if (!cJobs.isEmpty()) {
|
2020-03-18 23:39:25 +01:00
|
|
|
job = CrisValidatorUtils.convertJobToStoredJob(cJobs.get(0));
|
2019-11-20 14:03:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
return job;
|
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|