use of org.hisp.dhis.scheduling.parameters.MonitoringJobParameters in project dhis2-core by dhis2.
the class MonitoringJob method execute.
@Override
@Transactional
public void execute(JobConfiguration jobConfiguration, JobProgress progress) {
notifier.clear(jobConfiguration).notify(jobConfiguration, "Monitoring data");
MonitoringJobParameters monitoringJobParameters = (MonitoringJobParameters) jobConfiguration.getJobParameters();
try {
List<Period> periods;
Collection<ValidationRule> validationRules;
List<String> groupUIDs = monitoringJobParameters.getValidationRuleGroups();
if (groupUIDs.isEmpty()) {
validationRules = validationRuleService.getValidationRulesWithNotificationTemplates();
} else {
validationRules = groupUIDs.stream().map(validationRuleService::getValidationRuleGroup).filter(Objects::nonNull).map(ValidationRuleGroup::getMembers).filter(Objects::nonNull).reduce(Sets.newHashSet(), SetUtils::union);
}
if (monitoringJobParameters.getRelativeStart() != 0 && monitoringJobParameters.getRelativeEnd() != 0) {
Date startDate = DateUtils.getDateAfterAddition(new Date(), monitoringJobParameters.getRelativeStart());
Date endDate = DateUtils.getDateAfterAddition(new Date(), monitoringJobParameters.getRelativeEnd());
periods = periodService.getPeriodsBetweenDates(startDate, endDate);
periods = ListUtils.union(periods, periodService.getIntersectionPeriods(periods));
} else {
periods = validationRules.stream().map(ValidationRule::getPeriodType).distinct().map((vr) -> Arrays.asList(vr.createPeriod(), vr.getPreviousPeriod(vr.createPeriod()))).reduce(Lists.newArrayList(), ListUtils::union);
}
ValidationAnalysisParams parameters = validationService.newParamsBuilder(validationRules, null, periods).withIncludeOrgUnitDescendants(true).withMaxResults(ValidationService.MAX_SCHEDULED_ALERTS).withSendNotifications(monitoringJobParameters.isSendNotifications()).withPersistResults(monitoringJobParameters.isPersistResults()).build();
validationService.validationAnalysis(parameters);
notifier.notify(jobConfiguration, INFO, "Monitoring process done", true);
} catch (RuntimeException ex) {
notifier.notify(jobConfiguration, ERROR, "Process failed: " + ex.getMessage(), true);
messageService.sendSystemErrorNotification("Monitoring process failed", ex);
throw ex;
}
}
use of org.hisp.dhis.scheduling.parameters.MonitoringJobParameters in project dhis2-core by dhis2.
the class ResourceTableController method monitoring.
@RequestMapping(value = "/monitoring", method = { RequestMethod.PUT, RequestMethod.POST })
@PreAuthorize("hasRole('ALL') or hasRole('F_PERFORM_MAINTENANCE')")
@ResponseBody
public WebMessage monitoring() {
JobConfiguration monitoringJob = new JobConfiguration("inMemoryMonitoringJob", JobType.MONITORING, "", new MonitoringJobParameters(), true, true);
schedulingManager.executeNow(monitoringJob);
return jobConfigurationReport(monitoringJob);
}
Aggregations