use of org.hisp.dhis.importexport.ImportStrategy.DELETE in project dhis2-core by dhis2.
the class EventManager method deleteEvents.
public ImportSummaries deleteEvents(final List<Event> events, final WorkContext workContext) {
final ImportSummaries importSummaries = new ImportSummaries();
// pre-process events
executorsByPhase.get(EventProcessorPhase.DELETE_PRE).execute(workContext, events);
if (ImportStrategyUtils.isDelete(workContext.getImportOptions().getImportStrategy())) {
importSummaries.addImportSummaries(run(workContext, events, checkersRunOnDelete));
}
// 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.delete(workContext, eventValidationFailedUids.isEmpty() ? events : events.stream().filter(e -> !eventValidationFailedUids.contains(e.getEvent())).collect(toList()));
} catch (Exception e) {
handleFailure(workContext, importSummaries, events, IMPORT_ERROR_STRING, DELETE);
}
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.
executorsByPhase.get(EventProcessorPhase.DELETE_POST).execute(workContext, events.stream().filter(e -> !eventPersistenceFailedUids.contains(e.getEvent())).collect(toList()));
incrementSummaryTotals(events, importSummaries, DELETE);
}
return importSummaries;
}
Aggregations