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