use of org.hisp.dhis.scheduling.TaskId 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;
}
use of org.hisp.dhis.scheduling.TaskId in project dhis2-core by dhis2.
the class GetImportReportAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
TaskId taskId = new TaskId(category, currentUserService.getCurrentUser());
importReport = (ImportReport) notifier.getTaskSummary(taskId);
return SUCCESS;
}
use of org.hisp.dhis.scheduling.TaskId in project dhis2-core by dhis2.
the class GetImportEventSummariesAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
TaskId taskId = new TaskId(TaskCategory.EVENT_IMPORT, currentUserService.getCurrentUser());
importSummaries = (ImportSummaries) notifier.getTaskSummary(taskId);
return SUCCESS;
}
use of org.hisp.dhis.scheduling.TaskId in project dhis2-core by dhis2.
the class EventController method postXmlEvent.
// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.POST, consumes = "application/xml")
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')")
public void postXmlEvent(@RequestParam(defaultValue = "CREATE") ImportStrategy strategy, HttpServletResponse response, HttpServletRequest request, ImportOptions importOptions) throws Exception {
importOptions.setImportStrategy(strategy);
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
importOptions.setIdSchemes(getIdSchemesFromParameters(importOptions.getIdSchemes(), contextService.getParameterValuesMap()));
if (!importOptions.isAsync()) {
ImportSummaries importSummaries = eventService.addEventsXml(inputStream, importOptions);
importSummaries.setImportOptions(importOptions);
importSummaries.getImportSummaries().stream().filter(importSummary -> !importOptions.isDryRun() && !importSummary.getStatus().equals(ImportStatus.ERROR) && !importOptions.getImportStrategy().isDelete()).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()) {
if (!importSummary.getStatus().equals(ImportStatus.ERROR)) {
response.setHeader("Location", ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + importSummary.getReference());
}
}
}
webMessageService.send(WebMessageUtils.importSummaries(importSummaries), response, request);
} else {
TaskId taskId = new TaskId(TaskCategory.EVENT_IMPORT, currentUserService.getCurrentUser());
List<Event> events = eventService.getEventsXml(inputStream);
scheduler.executeTask(new ImportEventTask(events, 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.scheduling.TaskId in project dhis2-core by dhis2.
the class SystemController method getTaskSummaryJson.
@RequestMapping(value = "/taskSummaries/{category}", method = RequestMethod.GET, produces = { "*/*", "application/json" })
public void getTaskSummaryJson(HttpServletResponse response, @PathVariable("category") String category) throws IOException {
if (category != null) {
TaskCategory taskCategory = TaskCategory.valueOf(category.toUpperCase());
TaskId taskId = new TaskId(taskCategory, currentUserService.getCurrentUser());
Object summary = notifier.getTaskSummary(taskId);
if (//TODO improve this
summary != null && summary.getClass().isAssignableFrom(ImportSummary.class)) {
ImportSummary importSummary = (ImportSummary) summary;
renderService.toJson(response.getOutputStream(), importSummary);
return;
} else {
renderService.toJson(response.getOutputStream(), summary);
return;
}
}
renderService.toJson(response.getOutputStream(), new ImportSummary());
}
Aggregations