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);
}
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);
}
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);
}
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;
}
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);
}
Aggregations