use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class TrackedEntityInstanceController method updateTrackedEntityInstanceXml.
// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_XML_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_INSTANCE_ADD')")
public void updateTrackedEntityInstanceXml(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
ImportSummary importSummary = trackedEntityInstanceService.updateTrackedEntityInstanceXml(id, inputStream, importOptions);
importSummary.setImportOptions(importOptions);
webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class EnrollmentController method updateEnrollmentJson.
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')")
public void updateEnrollmentJson(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
ImportSummary importSummary = enrollmentService.updateEnrollmentJson(id, inputStream, importOptions);
importSummary.setImportOptions(importOptions);
webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class EnrollmentController method updateEnrollmentXml.
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_XML_VALUE, produces = MediaType.APPLICATION_XML_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_PROGRAM_ENROLLMENT')")
public void updateEnrollmentXml(@PathVariable String id, ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
ImportSummary importSummary = enrollmentService.updateEnrollmentXml(id, inputStream, importOptions);
importSummary.setImportOptions(importOptions);
webMessageService.send(WebMessageUtils.importSummary(importSummary), response, request);
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class EventController method postCsvEvents.
@RequestMapping(method = RequestMethod.POST, consumes = { "application/csv", "text/csv" })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void postCsvEvents(@RequestParam(required = false, defaultValue = "false") boolean skipFirst, HttpServletResponse response, HttpServletRequest request, ImportOptions importOptions) throws IOException {
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
Events events = csvEventService.readEvents(inputStream, skipFirst);
if (!importOptions.isAsync()) {
ImportSummaries importSummaries = eventService.addEvents(events.getEvents(), importOptions, null);
importSummaries.setImportOptions(importOptions);
webMessageService.send(WebMessageUtils.importSummaries(importSummaries), response, request);
} else {
TaskId taskId = new TaskId(TaskCategory.EVENT_IMPORT, currentUserService.getCurrentUser());
scheduler.executeTask(new ImportEventsTask(events.getEvents(), eventService, importOptions, taskId));
response.setHeader("Location", ContextUtils.getRootPath(request) + "/system/tasks/" + TaskCategory.EVENT_IMPORT);
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
}
use of org.hisp.dhis.dxf2.common.ImportOptions in project dhis2-core by dhis2.
the class TrackedEntityInstanceController method postTrackedEntityInstanceJson.
// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@RequestMapping(value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_INSTANCE_ADD')")
public void postTrackedEntityInstanceJson(@RequestParam(defaultValue = "CREATE_AND_UPDATE") ImportStrategy strategy, ImportOptions importOptions, HttpServletRequest request, HttpServletResponse response) throws IOException {
importOptions.setStrategy(strategy);
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
ImportSummaries importSummaries = trackedEntityInstanceService.addTrackedEntityInstanceJson(inputStream, importOptions);
importSummaries.setImportOptions(importOptions);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
importSummaries.getImportSummaries().stream().filter(importSummary -> !importOptions.isDryRun() && !importSummary.getStatus().equals(ImportStatus.ERROR) && !importOptions.getImportStrategy().isDelete()).forEach(importSummary -> importSummary.setHref(ContextUtils.getRootPath(request) + TrackedEntityInstanceSchemaDescriptor.API_ENDPOINT + "/" + importSummary.getReference()));
if (importSummaries.getImportSummaries().size() == 1) {
ImportSummary importSummary = importSummaries.getImportSummaries().get(0);
importSummary.setImportOptions(importOptions);
if (!importSummary.getStatus().equals(ImportStatus.ERROR)) {
response.setHeader("Location", getResourcePath(request, importSummary));
}
}
response.setStatus(HttpServletResponse.SC_CREATED);
webMessageService.send(WebMessageUtils.importSummaries(importSummaries), response, request);
}
Aggregations