use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class AssignValueImplementer method isTheSameValue.
private boolean isTheSameValue(EnrollmentActionRule actionRule, TrackerPreheat preheat) {
TrackedEntityAttribute attribute = preheat.get(TrackedEntityAttribute.class, actionRule.getField());
String value = actionRule.getValue();
Optional<Attribute> optionalAttribute = actionRule.getAttributes().stream().filter(at -> at.getAttribute().equals(actionRule.getField())).findAny();
if (optionalAttribute.isPresent()) {
return areEquals(value, optionalAttribute.get().getValue(), attribute.getValueType());
}
return false;
}
use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class EnrollmentImportValidationTest method testPreheatOwnershipForSubsequentEnrollment.
@Test
void testPreheatOwnershipForSubsequentEnrollment() throws IOException {
TrackerImportParams params = createBundleFromJson("tracker/validations/enrollments_te_enrollments-data.json");
params.setImportStrategy(TrackerImportStrategy.CREATE);
TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
TrackerImportParams secondParams = createBundleFromJson("tracker/validations/enrollments_te_enrollments-data.json");
TrackerPreheat preheat = trackerPreheatService.preheat(secondParams);
secondParams.getEnrollments().forEach(e -> {
assertEquals(e.getOrgUnit(), preheat.getProgramOwner().get(e.getTrackedEntity()).get(e.getProgram()).getOrganisationUnit().getUid());
});
}
use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class EnrollmentNoteValidationHookTest method testNoteWithExistingUidWarnings.
@Test
void testNoteWithExistingUidWarnings() {
// Given
final Note note = rnd.nextObject(Note.class);
TrackerBundle trackerBundle = mock(TrackerBundle.class);
TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
TrackerPreheat preheat = mock(TrackerPreheat.class);
when(ctx.getBundle()).thenReturn(trackerBundle);
when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
when(trackerBundle.getPreheat()).thenReturn(preheat);
when(ctx.getNote(note.getNote())).thenReturn(Optional.of(new TrackedEntityComment()));
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
enrollment.setNotes(Collections.singletonList(note));
// When
this.hook.validateEnrollment(reporter, enrollment);
// Then
assertTrue(reporter.hasWarnings());
assertTrue(reporter.hasWarningReport(warn -> E1119.equals(warn.getWarningCode()) && ENROLLMENT.equals(warn.getTrackerType()) && enrollment.getUid().equals(warn.getUid())));
assertThat(enrollment.getNotes(), hasSize(0));
}
use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class AssignedUserValidationHookTest method testEventWithUserNotPresentInPreheat.
@Test
void testEventWithUserNotPresentInPreheat() {
// given
Event event = new Event();
event.setEvent(CodeGenerator.generateUid());
event.setAssignedUser(USER_ID);
event.setProgramStage(PROGRAM_STAGE);
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
// when
TrackerBundle bundle = TrackerBundle.builder().build();
bundle.setPreheat(new TrackerPreheat());
when(validationContext.getBundle()).thenReturn(bundle);
this.hookToTest.validateEvent(reporter, event);
// then
hasTrackerError(reporter, E1118, TrackerType.EVENT, event.getUid());
}
use of org.hisp.dhis.tracker.preheat.TrackerPreheat in project dhis2-core by dhis2.
the class TrackedEntityAttributeTest method testTrackedAttributePreheater.
@Test
void testTrackedAttributePreheater() throws IOException {
TrackerImportParams trackerImportParams = fromJson("tracker/te_with_tea_data.json");
TrackerPreheat preheat = trackerPreheatService.preheat(trackerImportParams);
assertNotNull(preheat.get(OrganisationUnit.class, "cNEZTkdAvmg"));
assertNotNull(preheat.get(TrackedEntityType.class, "KrYIdvLxkMb"));
assertNotNull(preheat.get(TrackedEntityAttribute.class, "sYn3tkL3XKa"));
assertNotNull(preheat.get(TrackedEntityAttribute.class, "TsfP85GKsU5"));
assertNotNull(preheat.get(TrackedEntityAttribute.class, "sTGqP5JNy6E"));
}
Aggregations