use of org.hisp.dhis.importexport.ImportStrategy.UPDATE in project dhis2-core by dhis2.
the class EventManager method updateEvents.
public ImportSummaries updateEvents(final List<Event> events, final WorkContext workContext) {
final ImportSummaries importSummaries = new ImportSummaries();
// pre-process events
executorsByPhase.get(EventProcessorPhase.UPDATE_PRE).execute(workContext, events);
if (ImportStrategyUtils.isUpdate(workContext.getImportOptions().getImportStrategy())) {
importSummaries.addImportSummaries(run(workContext, events, checkersRunOnUpdate));
}
// collect the UIDs of events that did not pass validation
final List<String> eventValidationFailedUids = importSummaries.getImportSummaries().stream().filter(i -> i.isStatus(ERROR)).map(ImportSummary::getReference).collect(toList());
if (eventValidationFailedUids.size() == events.size()) {
return importSummaries;
}
if (!workContext.getImportOptions().isDryRun()) {
try {
eventPersistenceService.update(workContext, eventValidationFailedUids.isEmpty() ? events : events.stream().filter(e -> !eventValidationFailedUids.contains(e.getEvent())).collect(toList()));
} catch (Exception e) {
handleFailure(workContext, importSummaries, events, IMPORT_ERROR_STRING, UPDATE);
}
final List<String> eventPersistenceFailedUids = importSummaries.getImportSummaries().stream().filter(i -> i.isStatus(ERROR)).map(ImportSummary::getReference).collect(toList());
// Post processing only the events that passed validation and were
// persisted
// correctly.
List<Event> savedEvents = events.stream().filter(e -> !eventPersistenceFailedUids.contains(e.getEvent())).collect(toList());
executorsByPhase.get(EventProcessorPhase.UPDATE_POST).execute(workContext, savedEvents);
incrementSummaryTotals(events, importSummaries, UPDATE);
}
return importSummaries;
}
Aggregations