Search in sources :

Example 71 with WebMessage

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

the class WebMessageControllerAdvice method beforeBodyWrite.

@Override
public WebMessageResponse beforeBodyWrite(WebMessageResponse body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
    WebMessage message = (WebMessage) body;
    String location = message.getLocation();
    if (location != null) {
        response.getHeaders().addIfAbsent(ContextUtils.HEADER_LOCATION, contextService.getApiPath() + location);
    }
    if (isPlainResponse(request, message)) {
        return ((WebMessage) body).getResponse();
    }
    HttpStatus httpStatus = HttpStatus.resolve(message.getHttpStatusCode());
    if (httpStatus != null) {
        response.setStatusCode(httpStatus);
        if (httpStatus.is4xxClientError() || httpStatus.is5xxServerError()) {
            response.getHeaders().addIfAbsent("Cache-Control", CacheControl.noCache().cachePrivate().getHeaderValue());
        }
    }
    return body;
}
Also used : HttpStatus(org.springframework.http.HttpStatus) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage)

Example 72 with WebMessage

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

the class TrackedEntityInstanceController method updateTrackedEntityInstanceJson.

@PutMapping(value = "/{id}", consumes = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage updateTrackedEntityInstanceJson(@PathVariable String id, @RequestParam(required = false) String program, ImportOptions importOptions, HttpServletRequest request) throws IOException {
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstanceJson(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 73 with WebMessage

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

the class MetadataImportExportController method postJsonMetadata.

@PostMapping(value = "", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage postJsonMetadata(HttpServletRequest request) throws IOException {
    MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
    final Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> objects = renderService.fromMetadata(StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream()), RenderFormat.JSON);
    params.setObjects(objects);
    if (params.hasJobId()) {
        return startAsyncMetadata(params);
    }
    ImportReport importReport = metadataImportService.importMetadata(params);
    return importReport(importReport).withPlainResponseBefore(DhisApiVersion.V38);
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) CsvImportClass(org.hisp.dhis.dxf2.csv.CsvImportClass) List(java.util.List) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 74 with WebMessage

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

the class MetadataImportExportController method bulkSharing.

@ResponseBody
@PatchMapping(value = "sharing", consumes = "application/json-patch+json", produces = APPLICATION_JSON_VALUE)
public WebMessage bulkSharing(@RequestParam(required = false, defaultValue = "false") boolean atomic, HttpServletRequest request) throws IOException {
    final BulkJsonPatches bulkJsonPatches = jsonMapper.readValue(request.getInputStream(), BulkJsonPatches.class);
    BulkPatchParameters patchParams = BulkPatchParameters.builder().validators(BulkPatchValidatorFactory.SHARING).build();
    List<IdentifiableObject> patchedObjects = bulkPatchManager.applyPatches(bulkJsonPatches, patchParams);
    if (patchedObjects.isEmpty() || (atomic && !patchParams.hasErrorReports())) {
        ImportReport importReport = new ImportReport();
        importReport.addTypeReports(patchParams.getTypeReports());
        importReport.setStatus(Status.ERROR);
        return importReport(importReport);
    }
    Map<String, List<String>> parameterValuesMap = contextService.getParameterValuesMap();
    MetadataImportParams importParams = metadataImportService.getParamsFromMap(parameterValuesMap);
    importParams.setUser(currentUserService.getCurrentUser()).setImportStrategy(ImportStrategy.UPDATE).setAtomicMode(atomic ? AtomicMode.ALL : AtomicMode.NONE).addObjects(patchedObjects);
    ImportReport importReport = metadataImportService.importMetadata(importParams);
    if (patchParams.hasErrorReports()) {
        importReport.addTypeReports(patchParams.getTypeReports());
        importReport.setStatus(importReport.getStatus() == Status.OK ? Status.WARNING : importReport.getStatus());
    }
    return importReport(importReport);
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) BulkPatchParameters(org.hisp.dhis.jsonpatch.BulkPatchParameters) BulkJsonPatches(org.hisp.dhis.jsonpatch.BulkJsonPatches) List(java.util.List) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) PatchMapping(org.springframework.web.bind.annotation.PatchMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 75 with WebMessage

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

the class MetadataWorkflowController method acceptProposal.

@PostMapping(value = { "/{uid}/", "/{uid}" }, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage acceptProposal(@PathVariable("uid") String uid) throws NotFoundException {
    MetadataProposal proposal = checkProposalExists(uid);
    ImportReport report = service.accept(proposal);
    if (report.getStatus() != Status.OK) {
        return importReport(report);
    }
    if (proposal.getType() == MetadataProposalType.ADD) {
        String objUid = report.getFirstObjectReport().getUid();
        Schema schema = schemaService.getSchema(proposal.getTarget().getType());
        return created(schema.getSingular() + " created").setLocation(schema.getRelativeApiEndpoint() + "/" + objUid);
    }
    return ok();
}
Also used : MetadataProposal(org.hisp.dhis.metadata.MetadataProposal) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Schema(org.hisp.dhis.schema.Schema) 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