use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.
the class EventController method updateEvent.
private WebMessage updateEvent(Event updatedEvent, boolean singleValue, ImportOptions importOptions) {
ImportSummary importSummary = eventService.updateEvent(updatedEvent, singleValue, importOptions, false);
importSummary.setImportOptions(importOptions);
return importSummary(importSummary);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.
the class EnrollmentController method postEnrollmentJson.
// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@PostMapping(value = "", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage postEnrollmentJson(@RequestParam(defaultValue = "CREATE_AND_UPDATE") ImportStrategy strategy, ImportOptions importOptions, HttpServletRequest request) throws IOException {
importOptions.setStrategy(strategy);
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
if (!importOptions.isAsync()) {
ImportSummaries importSummaries = enrollmentService.addEnrollmentsJson(inputStream, importOptions);
importSummaries.setImportOptions(importOptions);
importSummaries.getImportSummaries().stream().filter(importSummary -> !importOptions.isDryRun() && !importSummary.getStatus().equals(ImportStatus.ERROR) && !importOptions.getImportStrategy().isDelete() && (!importOptions.getImportStrategy().isSync() || importSummary.getImportCount().getDeleted() == 0)).forEach(importSummary -> importSummary.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + importSummary.getReference()));
if (importSummaries.getImportSummaries().size() == 1) {
ImportSummary importSummary = importSummaries.getImportSummaries().get(0);
importSummary.setImportOptions(importOptions);
if (!importSummary.getStatus().equals(ImportStatus.ERROR)) {
importSummaries(importSummaries).setHttpStatus(HttpStatus.CREATED).setLocation("/api/" + "enrollments" + "/" + importSummary.getReference());
}
}
return importSummaries(importSummaries).setHttpStatus(HttpStatus.CREATED);
}
return startAsyncImport(importOptions, enrollmentService.getEnrollmentsJson(inputStream));
}
use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.
the class EnrollmentController method updateEnrollmentForNoteJson.
// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
@PostMapping(value = "/{id}/note", consumes = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage updateEnrollmentForNoteJson(@PathVariable String id, HttpServletRequest request) throws IOException {
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
ImportSummary importSummary = enrollmentService.updateEnrollmentForNoteJson(id, inputStream);
return importSummary(importSummary);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.
the class EnrollmentController method updateEnrollmentXml.
@PutMapping(value = "/{id}", consumes = APPLICATION_XML_VALUE, produces = APPLICATION_XML_VALUE)
@ResponseBody
public WebMessage updateEnrollmentXml(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request) throws IOException {
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
ImportSummary importSummary = enrollmentService.updateEnrollmentXml(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 AbstractCrudController method deleteObject.
// --------------------------------------------------------------------------
// DELETE
// --------------------------------------------------------------------------
@DeleteMapping(value = "/{uid}")
@ResponseBody
public WebMessage deleteObject(@PathVariable("uid") String pvUid, @CurrentUser User currentUser, HttpServletRequest request, HttpServletResponse response) throws Exception {
List<T> objects = getEntity(pvUid);
if (objects.isEmpty()) {
return notFound(getEntityClass(), pvUid);
}
if (!aclService.canDelete(currentUser, objects.get(0))) {
throw new DeleteAccessDeniedException("You don't have the proper permissions to delete this object.");
}
preDeleteEntity(objects.get(0));
MetadataImportParams params = new MetadataImportParams().setImportReportMode(ImportReportMode.FULL).setUser(currentUser).setImportStrategy(ImportStrategy.DELETE).addObject(objects.get(0));
ImportReport importReport = importService.importMetadata(params);
postDeleteEntity(pvUid);
return objectReport(importReport);
}
Aggregations