Search in sources :

Example 1 with ImportEventsTask

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);
    }
}
Also used : ImportEventsTask(org.hisp.dhis.dxf2.events.event.ImportEventsTask) TaskId(org.hisp.dhis.scheduling.TaskId) Events(org.hisp.dhis.dxf2.events.event.Events) InputStream(java.io.InputStream) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ImportEventsTask

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);
}
Also used : ImportEventsTask(org.hisp.dhis.dxf2.events.event.ImportEventsTask) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 3 with ImportEventsTask

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;
}
Also used : ImportEventsTask(org.hisp.dhis.dxf2.events.event.ImportEventsTask) TaskId(org.hisp.dhis.scheduling.TaskId) ImportEventTask(org.hisp.dhis.dxf2.events.event.ImportEventTask) Events(org.hisp.dhis.dxf2.events.event.Events) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Event(org.hisp.dhis.dxf2.events.event.Event) FileInputStream(java.io.FileInputStream) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions)

Aggregations

ImportEventsTask (org.hisp.dhis.dxf2.events.event.ImportEventsTask)3 InputStream (java.io.InputStream)2 Events (org.hisp.dhis.dxf2.events.event.Events)2 TaskId (org.hisp.dhis.scheduling.TaskId)2 FileInputStream (java.io.FileInputStream)1 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)1 Event (org.hisp.dhis.dxf2.events.event.Event)1 ImportEventTask (org.hisp.dhis.dxf2.events.event.ImportEventTask)1 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)1 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1