use of org.hisp.dhis.dxf2.events.importer.context.EventDataValueAggregator in project dhis2-core by dhis2.
the class FilteringOutUndeclaredDataElementsProcessorTest method testNotLinkedDataElementsAreRemovedFromEvent.
@Test
void testNotLinkedDataElementsAreRemovedFromEvent() {
Event event = new Event();
event.setProgramStage(PROGRAMSTAGE);
HashSet<DataValue> dataValues = Sets.newHashSet(new DataValue(DATA_ELEMENT_1, "whatever"), new DataValue(DATA_ELEMENT_2, "another value"));
event.setDataValues(dataValues);
WorkContext ctx = WorkContext.builder().importOptions(ImportOptions.getDefaultImportOptions()).programsMap(getProgramMap()).eventDataValueMap(new EventDataValueAggregator().aggregateDataValues(ImmutableList.of(event), Collections.emptyMap(), ImportOptions.getDefaultImportOptions())).build();
preProcessor.process(event, ctx);
Set<String> allowedDataValues = ctx.getProgramStage(ctx.getImportOptions().getIdSchemes().getProgramStageIdScheme(), PROGRAMSTAGE).getDataElements().stream().map(BaseIdentifiableObject::getUid).collect(Collectors.toSet());
Set<String> filteredEventDataValues = ctx.getEventDataValueMap().values().stream().flatMap(Collection::stream).map(EventDataValue::getDataElement).collect(Collectors.toSet());
assertTrue(allowedDataValues.containsAll(filteredEventDataValues));
}
use of org.hisp.dhis.dxf2.events.importer.context.EventDataValueAggregator in project dhis2-core by dhis2.
the class FilteredDataValueCheckTest method testNotLinkedDataElementsAreReported.
@Test
void testNotLinkedDataElementsAreReported() {
Event event = new Event();
event.setProgramStage(PROGRAMSTAGE);
HashSet<DataValue> dataValues = Sets.newHashSet(new DataValue(DATA_ELEMENT_1, "whatever"), new DataValue(DATA_ELEMENT_2, "another value"));
event.setDataValues(dataValues);
WorkContext ctx = WorkContext.builder().importOptions(ImportOptions.getDefaultImportOptions()).programsMap(getProgramMap()).eventDataValueMap(new EventDataValueAggregator().aggregateDataValues(ImmutableList.of(event), Collections.emptyMap(), ImportOptions.getDefaultImportOptions())).build();
ImportSummary importSummary = dataValueCheck.check(new ImmutableEvent(event), ctx);
assertEquals(ImportStatus.WARNING, importSummary.getStatus());
}
use of org.hisp.dhis.dxf2.events.importer.context.EventDataValueAggregator in project dhis2-core by dhis2.
the class WorkContextLoader method load.
@Transactional(readOnly = true)
public WorkContext load(ImportOptions importOptions, List<Event> events) {
sessionFactory.getCurrentSession().flush();
ImportOptions localImportOptions = importOptions;
// API allows a null Import Options
if (localImportOptions == null) {
localImportOptions = ImportOptions.getDefaultImportOptions();
}
initializeUser(localImportOptions);
// Make sure all events have the 'uid' field populated
events = uidGen.assignUidToEvents(events);
final Map<String, ProgramStageInstance> programStageInstanceMap = programStageInstanceSupplier.get(localImportOptions, events);
final Map<String, Pair<TrackedEntityInstance, Boolean>> teiMap = trackedEntityInstanceSupplier.get(localImportOptions, events);
final Map<String, OrganisationUnit> orgUniMap = organisationUnitSupplier.get(localImportOptions, events);
return WorkContext.builder().importOptions(localImportOptions).programsMap(programSupplier.get(localImportOptions, events)).programStageInstanceMap(programStageInstanceMap).organisationUnitMap(orgUniMap).trackedEntityInstanceMap(teiMap).programInstanceMap(programInstanceSupplier.get(localImportOptions, teiMap, events)).categoryOptionComboMap(categoryOptionComboSupplier.get(localImportOptions, events)).dataElementMap(dataElementSupplier.get(localImportOptions, events)).notesMap(noteSupplier.get(localImportOptions, events)).assignedUserMap(assignedUserSupplier.get(localImportOptions, events)).eventDataValueMap(new EventDataValueAggregator().aggregateDataValues(events, programStageInstanceMap, localImportOptions)).programWithOrgUnitsMap(programOrgUnitSupplier.get(localImportOptions, events, orgUniMap)).serviceDelegator(serviceDelegatorSupplier.get()).build();
}
Aggregations