use of org.hisp.dhis.dxf2.events.event.ImportEventsTask 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.events.event.ImportEventsTask in project dhis2-core by dhis2.
the class EventController method startAsyncImport.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
* Starts an asynchronous import task.
*
* @param importOptions the ImportOptions.
* @param events the events to import.
*/
private WebMessage startAsyncImport(ImportOptions importOptions, List<Event> events) {
JobConfiguration jobId = new JobConfiguration("inMemoryEventImport", EVENT_IMPORT, currentUserService.getCurrentUser().getUid(), true);
taskExecutor.executeTask(new ImportEventsTask(events, eventService, importOptions, jobId));
return jobConfigurationReport(jobId).setLocation("/system/tasks/" + EVENT_IMPORT);
}
use of org.hisp.dhis.dxf2.events.event.ImportEventsTask in project dhis2-core by dhis2.
the class ImportEventAction method execute.
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
TaskId taskId = new TaskId(TaskCategory.EVENT_IMPORT, currentUserService.getCurrentUser());
notifier.clear(taskId);
InputStream in = new FileInputStream(upload);
in = StreamUtils.wrapAndCheckCompressionFormat(in);
ImportOptions importOptions = new ImportOptions().setDryRun(dryRun).setOrgUnitIdScheme(orgUnitIdScheme.toString()).setEventIdScheme(eventIdScheme.toString()).setFilename(uploadFileName);
if (FORMAT_CSV.equals(payloadFormat)) {
Events events = csvEventService.readEvents(in, skipFirst);
scheduler.executeTask(new ImportEventsTask(events.getEvents(), eventService, importOptions, taskId));
} else {
List<Event> events;
if (FORMAT_JSON.equals(payloadFormat)) {
events = eventService.getEventsJson(in);
} else {
events = eventService.getEventsXml(in);
}
scheduler.executeTask(new ImportEventTask(events, eventService, importOptions, taskId));
}
return SUCCESS;
}
Aggregations