Search in sources :

Example 26 with WebMessage

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

the class RelationshipController method updateRelationshipXml.

@PutMapping(path = "/{id}", consumes = APPLICATION_XML_VALUE, produces = APPLICATION_XML_VALUE)
@ResponseBody
public WebMessage updateRelationshipXml(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request) throws IOException {
    Relationship relationship = relationshipService.getRelationshipByUid(id);
    if (relationship == null) {
        return notFound("No relationship with id '" + id + "' was found.");
    }
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummary importSummary = relationshipService.updateRelationshipXml(id, inputStream, importOptions);
    importSummary.setImportOptions(importOptions);
    return importSummary(importSummary).withPlainResponseBefore(DhisApiVersion.V38);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 27 with WebMessage

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

the class RelationshipController method postRelationshipJson.

// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@PostMapping(value = "", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage postRelationshipJson(@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.addRelationshipsJson(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)

Example 28 with WebMessage

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

the class RelationshipController method updateRelationshipJson.

// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
@PutMapping(path = "/{id}", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage updateRelationshipJson(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request) throws IOException {
    Relationship relationship = relationshipService.getRelationshipByUid(id);
    if (relationship == null) {
        return notFound("No relationship with id '" + id + "' was found.");
    }
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    ImportSummary importSummary = relationshipService.updateRelationshipJson(id, inputStream, importOptions);
    importSummary.setImportOptions(importOptions);
    return importSummary(importSummary);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 29 with WebMessage

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

the class MapController method putJsonObject.

// --------------------------------------------------------------------------
// CRUD
// --------------------------------------------------------------------------
@Override
@PutMapping(value = "/{uid}", consumes = APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public WebMessage putJsonObject(@PathVariable String uid, @CurrentUser User currentUser, HttpServletRequest request) throws Exception {
    Map map = mappingService.getMap(uid);
    if (map == null) {
        return notFound("Map does not exist: " + uid);
    }
    MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap());
    Map newMap = deserializeJsonEntity(request);
    newMap.setUid(uid);
    mergeService.merge(new MergeParams<>(newMap, map).setMergeMode(params.getMergeMode()).setSkipSharing(params.isSkipSharing()).setSkipTranslation(params.isSkipTranslation()));
    mappingService.updateMap(map);
    return null;
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) MergeParams(org.hisp.dhis.schema.MergeParams) Map(org.hisp.dhis.mapping.Map) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 30 with WebMessage

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

the class MetadataImportExportController method postCsvMetadata.

@PostMapping(value = "", consumes = "application/csv")
@ResponseBody
public WebMessage postCsvMetadata(HttpServletRequest request) throws IOException {
    MetadataImportParams params = metadataImportService.getParamsFromMap(contextService.getParameterValuesMap());
    String classKey = request.getParameter("classKey");
    if (StringUtils.isEmpty(classKey) || !CsvImportClass.classExists(classKey)) {
        return conflict("Cannot find Csv import class:  " + classKey);
    }
    params.setCsvImportClass(CsvImportClass.valueOf(classKey));
    Metadata metadata = csvImportService.fromCsv(request.getInputStream(), new CsvImportOptions().setImportClass(params.getCsvImportClass()).setFirstRowIsHeader(params.isFirstRowIsHeader()));
    params.addMetadata(schemaService.getMetadataSchemas(), metadata);
    if (params.hasJobId()) {
        return startAsyncMetadata(params);
    }
    ImportReport importReport = metadataImportService.importMetadata(params);
    return importReport(importReport).withPlainResponseBefore(DhisApiVersion.V38);
}
Also used : CsvImportOptions(org.hisp.dhis.dxf2.csv.CsvImportOptions) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Metadata(org.hisp.dhis.dxf2.metadata.Metadata) 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