use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.
the class EnrollmentController method startAsyncImport.
// -------------------------------------------------------------------------
// HELPERS
// -------------------------------------------------------------------------
/**
* Starts an asynchronous enrollment task.
*
* @param importOptions the ImportOptions.
* @param enrollments the enrollments to import.
*/
private WebMessage startAsyncImport(ImportOptions importOptions, List<Enrollment> enrollments) {
JobConfiguration jobId = new JobConfiguration("inMemoryEventImport", ENROLLMENT_IMPORT, currentUserService.getCurrentUser().getUid(), true);
taskExecutor.executeTask(new ImportEnrollmentsTask(enrollments, enrollmentService, importOptions, jobId));
return jobConfigurationReport(jobId).setLocation("/system/tasks/" + ENROLLMENT_IMPORT);
}
use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.
the class EnrollmentController method postEnrollmentXml.
@PostMapping(value = "", consumes = APPLICATION_XML_VALUE, produces = APPLICATION_XML_VALUE)
@ResponseBody
public WebMessage postEnrollmentXml(@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.addEnrollmentsXml(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.getEnrollmentsXml(inputStream));
}
use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.
the class DataValueController method saveFileDataValue.
@PreAuthorize("hasRole('ALL') or hasRole('F_DATAVALUE_ADD')")
@PostMapping(FILE_PATH)
@ResponseBody
public WebMessage saveFileDataValue(@RequestParam String de, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String ds, @RequestParam(required = false) String comment, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) boolean force, @RequestParam MultipartFile file, @CurrentUser User currentUser) throws WebMessageException, IOException {
FileResource fileResource = fileResourceUtils.saveFileResource(file, FileResourceDomain.DATA_VALUE);
saveDataValueInternal(de, co, cc, cp, pe, ou, ds, fileResource.getUid(), comment, followUp, force, currentUser);
WebMessage webMessage = new WebMessage(Status.OK, HttpStatus.ACCEPTED);
webMessage.setResponse(new FileResourceWebMessageResponse(fileResource));
return webMessage;
}
use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.
the class EventController method postEvent.
@SneakyThrows
private WebMessage postEvent(ImportStrategy strategy, HttpServletRequest request, ImportOptions importOptions, BiFunction<InputStream, ImportOptions, ImportSummaries> eventAdder, Function<InputStream, List<Event>> eventConverter) {
importOptions.setImportStrategy(strategy);
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
importOptions.setIdSchemes(getIdSchemesFromParameters(importOptions.getIdSchemes(), contextService.getParameterValuesMap()));
if (!importOptions.isAsync()) {
ImportSummaries importSummaries = eventAdder.apply(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 (!importOptions.isDryRun() && !importSummary.getStatus().equals(ImportStatus.ERROR)) {
return importSummaries(importSummaries).setLocation(RESOURCE_PATH + "/" + importSummary.getReference());
}
}
return importSummaries(importSummaries);
}
return startAsyncImport(importOptions, eventConverter.apply(inputStream));
}
use of org.hisp.dhis.dxf2.webmessage.WebMessage in project dhis2-core by dhis2.
the class EventController method putJsonEvent.
@PutMapping(value = "/{uid}", consumes = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage putJsonEvent(HttpServletRequest request, @PathVariable("uid") String uid, ImportOptions importOptions) throws IOException {
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
Event updatedEvent = renderService.fromJson(inputStream, Event.class);
updatedEvent.setEvent(uid);
return updateEvent(updatedEvent, false, importOptions);
}
Aggregations