Search in sources :

Example 21 with WebMessage

use of org.hisp.dhis.dxf2.webmessage.WebMessage 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)

Example 22 with WebMessage

use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.

the class DataValueSetController method postAdxDataValueSet.

@PostMapping(consumes = CONTENT_TYPE_XML_ADX)
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
@ResponseBody
public WebMessage postAdxDataValueSet(ImportOptions importOptions, HttpServletRequest request) throws IOException {
    if (importOptions.isAsync()) {
        return startAsyncImport(importOptions, ImportDataValueTask.FORMAT_ADX, request);
    }
    ImportSummary summary = adxDataService.saveDataValueSet(request.getInputStream(), importOptions, null);
    summary.setImportOptions(importOptions);
    return importSummary(summary).withPlainResponseBefore(V38);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 23 with WebMessage

use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.

the class DataValueSetController method postCsvDataValueSet.

@PostMapping(consumes = "application/csv")
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
@ResponseBody
public WebMessage postCsvDataValueSet(ImportOptions importOptions, HttpServletRequest request) throws IOException {
    if (importOptions.isAsync()) {
        return startAsyncImport(importOptions, ImportDataValueTask.FORMAT_CSV, request);
    }
    ImportSummary summary = dataValueSetService.importDataValueSetCsv(request.getInputStream(), importOptions);
    summary.setImportOptions(importOptions);
    return importSummary(summary).withPlainResponseBefore(V38);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 24 with WebMessage

use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.

the class ProgramRuleController method validateCondition.

@PostMapping(value = "/condition/description", produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage validateCondition(@RequestBody String condition, @RequestParam String programId) {
    I18n i18n = i18nManager.getI18n();
    RuleValidationResult result = programRuleEngineService.getDescription(condition, programId);
    if (result.isValid()) {
        return new DescriptiveWebMessage(Status.OK, HttpStatus.OK).setDescription(result.getDescription()).setMessage(i18n.getString(ProgramIndicator.VALID));
    }
    String description = null;
    if (result.getErrorMessage() != null) {
        description = result.getErrorMessage();
    } else if (result.getException() != null) {
        description = result.getException().getMessage();
    }
    return new DescriptiveWebMessage(Status.ERROR, HttpStatus.OK).setDescription(description).setMessage(i18n.getString(ProgramIndicator.EXPRESSION_NOT_VALID));
}
Also used : DescriptiveWebMessage(org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage) RuleValidationResult(org.hisp.dhis.rules.models.RuleValidationResult) I18n(org.hisp.dhis.i18n.I18n) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 25 with WebMessage

use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.

the class RelationshipController method postRelationshipXml.

@PostMapping(value = "", consumes = APPLICATION_XML_VALUE, produces = APPLICATION_XML_VALUE)
@ResponseBody
public WebMessage postRelationshipXml(@RequestParam(defaultValue = "CREATE_AND_UPDATE") ImportStrategy strategy, ImportOptions importOptions, HttpServletRequest request) throws IOException {
    importOptions.setStrategy(strategy);
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummaries importSummaries = relationshipService.addRelationshipsXml(inputStream, importOptions);
    importSummaries.getImportSummaries().stream().filter(filterImportSummary(importOptions)).forEach(setImportSummaryHref(request));
    return importSummaries(importSummaries);
}
Also used : InputStream(java.io.InputStream) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ResponseBody (org.springframework.web.bind.annotation.ResponseBody)49 PostMapping (org.springframework.web.bind.annotation.PostMapping)29 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)28 InputStream (java.io.InputStream)24 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)20 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)17 PutMapping (org.springframework.web.bind.annotation.PutMapping)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)10 User (org.hisp.dhis.user.User)10 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)10 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)9 List (java.util.List)8 Event (org.hisp.dhis.dxf2.events.event.Event)8 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)7 IOException (java.io.IOException)6 FileResourceWebMessageResponse (org.hisp.dhis.dxf2.webmessage.responses.FileResourceWebMessageResponse)6