Search in sources :

Example 1 with MonitoringJobParameters

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;
    }
}
Also used : Objects(java.util.Objects) Period(org.hisp.dhis.period.Period) ValidationAnalysisParams(org.hisp.dhis.validation.ValidationAnalysisParams) Date(java.util.Date) MonitoringJobParameters(org.hisp.dhis.scheduling.parameters.MonitoringJobParameters) ValidationRule(org.hisp.dhis.validation.ValidationRule) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with MonitoringJobParameters

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);
}
Also used : JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) MonitoringJobParameters(org.hisp.dhis.scheduling.parameters.MonitoringJobParameters) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

MonitoringJobParameters (org.hisp.dhis.scheduling.parameters.MonitoringJobParameters)2 Date (java.util.Date)1 Objects (java.util.Objects)1 Period (org.hisp.dhis.period.Period)1 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)1 ValidationAnalysisParams (org.hisp.dhis.validation.ValidationAnalysisParams)1 ValidationRule (org.hisp.dhis.validation.ValidationRule)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1