use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class TrackedEntityInstanceCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
Program program = ctx.getProgramsMap().get(event.getProgram());
final Optional<TrackedEntityInstance> trackedEntityInstance = ctx.getTrackedEntityInstance(event.getUid());
if (program.isRegistration() && !trackedEntityInstance.isPresent()) {
return new ImportSummary(ImportStatus.ERROR, "Event.trackedEntityInstance does not point to a valid tracked entity instance: " + event.getTrackedEntityInstance()).setReference(event.getEvent()).incrementIgnored();
}
return success();
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class EventBaseCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
ImportSummary importSummary = new ImportSummary();
List<String> errors = validate(event, ctx);
if (!errors.isEmpty()) {
importSummary.setStatus(ERROR);
importSummary.setReference(event.getEvent());
errors.forEach(error -> importSummary.addConflict("Event", error));
importSummary.incrementIgnored();
}
return importSummary;
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class FilteredDataValueCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
final Set<String> eventDataValuesUids = Optional.ofNullable(event).map(ImmutableEvent::getDataValues).orElse(Collections.emptySet()).stream().map(DataValue::getDataElement).collect(Collectors.toSet());
final ImportSummary importSummary = new ImportSummary();
if (!eventDataValuesUids.isEmpty() && Objects.nonNull(event) && StringUtils.isNotBlank(event.getProgramStage())) {
Set<String> filteredEventDataValuesUids = getFilteredDataValues(event.getDataValues(), getDataElementUidsFromProgramStage(event.getProgramStage(), ctx)).stream().map(DataValue::getDataElement).collect(Collectors.toSet());
Set<String> ignoredDataValues = eventDataValuesUids.stream().filter(uid -> !filteredEventDataValuesUids.contains(uid)).collect(Collectors.toSet());
if (!ignoredDataValues.isEmpty()) {
importSummary.setStatus(ImportStatus.WARNING);
importSummary.setReference(event.getUid());
importSummary.setDescription("Data Values " + ignoredDataValues.stream().collect(Collectors.joining(",", "[", "]")) + " ignored because " + "not defined in program stage " + event.getProgramStage());
importSummary.incrementImported();
}
}
return importSummary;
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ProgramOrgUnitCheckTest method failWhenProgramHasNoOrgUnitMatchingEventOrgUnit.
@Test
void failWhenProgramHasNoOrgUnitMatchingEventOrgUnit() {
// assign a UID to the event's org unit
event.setOrgUnit(CodeGenerator.generateUid());
// Prepare data
Program program = createProgram('P');
program.setId(1);
OrganisationUnit ou = new OrganisationUnit();
ou.setId(1);
ou.setUid(event.getOrgUnit());
when(workContext.getOrganisationUnitMap()).thenReturn(ImmutableMap.of(event.getUid(), ou));
when(workContext.getProgramWithOrgUnitsMap()).thenReturn(new HashMap<>());
ProgramInstance pi = new ProgramInstance();
pi.setProgram(program);
Map<String, ProgramInstance> programInstanceMap = new HashMap<>();
programInstanceMap.put(event.getUid(), pi);
when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
// method under test
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(summary, event, "Program is not assigned to this Organisation Unit: " + event.getOrgUnit());
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class DataValueCheckTest method verifyValidationFailOnMissingDataElement.
@Test
void verifyValidationFailOnMissingDataElement() {
event.setProgramStage("prgstg1");
DataElement de1 = addToDataElementMap(createDataElement('A'));
programStageA.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
programStageA.setProgramStageDataElements(Sets.newHashSet(createProgramStageDataElement(programStageA, de1, 1, true)));
addToDataValueMap(event.getUid(), createEventDataValue(de1.getUid(), "1"), createEventDataValue("iDontExist", "2"));
DataValue dv1 = createDataValue(de1.getUid(), "1");
DataValue dv2 = createDataValue("iDontExist", "2");
event.setDataValues(Sets.newHashSet(dv1, dv2));
final ImportSummary summary = rule.check(new ImmutableEvent(event), this.workContext);
assertHasError(summary, event, null);
assertHasConflict(summary, "iDontExist is not a valid data element", "dataElement");
}
Aggregations