Search in sources :

Example 1 with PredictionTask

use of org.hisp.dhis.predictor.PredictionTask in project dhis2-core by dhis2.

the class PredictionController method runPredictors.

@RequestMapping(method = { RequestMethod.POST, RequestMethod.PUT })
@PreAuthorize("hasRole('ALL') or hasRole('F_PREDICTOR_RUN')")
@ResponseBody
public WebMessage runPredictors(@RequestParam Date startDate, @RequestParam Date endDate, @RequestParam(value = "predictor", required = false) List<String> predictors, @RequestParam(value = "predictorGroup", required = false) List<String> predictorGroups, @RequestParam(defaultValue = "false", required = false) boolean async, HttpServletRequest request) {
    if (async) {
        JobConfiguration jobId = new JobConfiguration("inMemoryPrediction", PREDICTOR, currentUserService.getCurrentUser().getUid(), true);
        taskExecutor.executeTask(new PredictionTask(startDate, endDate, predictors, predictorGroups, predictionService, jobId));
        return jobConfigurationReport(jobId).setLocation("/system/tasks/" + PREDICTOR);
    }
    PredictionSummary predictionSummary = predictionService.predictTask(startDate, endDate, predictors, predictorGroups, null);
    return new WebMessage(Status.OK, HttpStatus.OK).setResponse(predictionSummary).withPlainResponseBefore(DhisApiVersion.V38);
}
Also used : PredictionTask(org.hisp.dhis.predictor.PredictionTask) PredictionSummary(org.hisp.dhis.predictor.PredictionSummary) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)1 PredictionSummary (org.hisp.dhis.predictor.PredictionSummary)1 PredictionTask (org.hisp.dhis.predictor.PredictionTask)1 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1