Search in sources :

Example 31 with WebMessage

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

the class MetadataImportExportController method postGmlMetadata.

@PostMapping(value = "/gml", consumes = APPLICATION_XML_VALUE)
@ResponseBody
public WebMessage postGmlMetadata(HttpServletRequest request) throws IOException {
    MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
    if (params.hasJobId()) {
        return startAsyncGml(params, request);
    }
    ImportReport importReport = gmlImportService.importGml(request.getInputStream(), params);
    return importReport(importReport).withPlainResponseBefore(DhisApiVersion.V38);
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 32 with WebMessage

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

the class TrackedEntityInstanceController method updateTrackedEntityInstanceXml.

// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
@PutMapping(value = "/{id}", consumes = APPLICATION_XML_VALUE)
@ResponseBody
public WebMessage updateTrackedEntityInstanceXml(@PathVariable String id, @RequestParam(required = false) String program, ImportOptions importOptions, HttpServletRequest request) throws IOException {
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstanceXml(id, program, inputStream, importOptions);
    importSummary.setImportOptions(importOptions);
    return importSummary(importSummary);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 33 with WebMessage

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

the class TrackedEntityInstanceController method postTrackedEntityInstance.

private WebMessage postTrackedEntityInstance(ImportStrategy strategy, ImportOptions importOptions, HttpServletRequest request, String mediaType) throws IOException, BadRequestException {
    importOptions.setStrategy(strategy);
    importOptions.setSkipLastUpdated(true);
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    // For in memory Jobs
    JobConfiguration jobId = new JobConfiguration("inMemoryEventImport", TEI_IMPORT, currentUserService.getCurrentUser().getUid(), true);
    TrackerEntityInstanceRequest trackerEntityInstanceRequest = TrackerEntityInstanceRequest.builder().inputStream(inputStream).importOptions(importOptions).mediaType(mediaType).jobConfiguration(jobId).build();
    ImportSummaries importSummaries = trackedEntityInstanceStrategyHandler.mergeOrDeleteTrackedEntityInstances(trackerEntityInstanceRequest);
    if (!importOptions.isAsync()) {
        ImportSummary singleSummary = finalizeTrackedEntityInstancePostRequest(importOptions, request, importSummaries);
        return importSummaries(importSummaries).setLocation(singleSummary == null ? null : "/api/" + "trackedEntityInstances" + "/" + singleSummary.getReference());
    }
    return jobConfigurationReport(jobId).setLocation("/system/tasks/" + TEI_IMPORT);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackerEntityInstanceRequest(org.hisp.dhis.webapi.strategy.old.tracker.imports.request.TrackerEntityInstanceRequest) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 34 with WebMessage

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

the class ProgramRuleActionController method getDataExpressionDescription.

@PostMapping(value = "/data/expression/description", produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage getDataExpressionDescription(@RequestBody String condition, @RequestParam String programId) {
    I18n i18n = i18nManager.getI18n();
    RuleValidationResult result = programRuleEngineService.getDataExpressionDescription(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.CONFLICT).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 35 with WebMessage

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

the class SystemSoftwareUpdateNotifyController method checkSystemUpdate.

@GetMapping(SystemSoftwareUpdateNotifyController.RESOURCE_PATH)
@ResponseBody
public WebMessage checkSystemUpdate(@RequestParam(value = "forceVersion", required = false) String forceVersion) throws Exception {
    Semver currentVersion = SystemUpdateService.getCurrentVersion();
    if (forceVersion != null) {
        currentVersion = new Semver(forceVersion);
    }
    Map<Semver, Map<String, String>> newerVersions = SystemUpdateService.getLatestNewerThan(currentVersion);
    systemUpdateService.sendMessageForEachVersion(newerVersions);
    WebMessage ok = WebMessageUtils.ok();
    ok.setResponse(new SoftwareUpdateResponse(newerVersions));
    return ok;
}
Also used : Semver(com.vdurmont.semver4j.Semver) Map(java.util.Map) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) GetMapping(org.springframework.web.bind.annotation.GetMapping) 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