use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class PreCheckUidValidationHookTest method verifyEnrollmentWithNoteWithInvalidUidFails.
@Test
void verifyEnrollmentWithNoteWithInvalidUidFails() {
// given
Note note = Note.builder().note(INVALID_UID).build();
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).notes(Lists.newArrayList(note)).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEnrollment(reporter, enrollment);
// then
hasTrackerError(reporter, E1048, ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class PreCheckUidValidationHookTest method verifyEnrollmentValidationSuccess.
@Test
void verifyEnrollmentValidationSuccess() {
// given
Note note = Note.builder().note(CodeGenerator.generateUid()).build();
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).notes(Lists.newArrayList(note)).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEnrollment(reporter, enrollment);
// then
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class TrackerBundleParamsConverter method convert.
/**
* Iterates over the collections of a dataBundle. If any objects in those
* collections have objects nested within them, they are extracted. For each
* object we process, we make sure all references are valid as well.
*
* @param dataBundle containing collections to check and update.
* @return a dataBundle with a flattened data structure, and valid uid
* references.
*/
@Override
public TrackerBundleParams convert(TrackerBundleParams dataBundle) {
Map<String, TrackedEntity> trackedEntityMap = new HashMap<>();
Map<String, Enrollment> enrollmentHashMap = new HashMap<>();
Map<String, Event> eventHashMap = new HashMap<>();
Map<String, Relationship> relationshipHashMap = new HashMap<>();
// Extract all enrollments and relationships, and set parent reference.
for (TrackedEntity te : dataBundle.getTrackedEntities()) {
updateTrackedEntityReferences(te);
trackedEntityMap.put(te.getTrackedEntity(), te);
extractEnrollments(te).forEach(enrollment -> enrollmentHashMap.put(enrollment.getEnrollment(), enrollment));
extractRelationships(te).forEach(relationship -> relationshipHashMap.put(relationship.getRelationship(), relationship));
}
// Set UID for all enrollments and notes
dataBundle.getEnrollments().stream().peek(enrollment -> updateEnrollmentReferences(enrollment, enrollment.getTrackedEntity())).forEach(enrollment -> enrollmentHashMap.put(enrollment.getEnrollment(), enrollment));
// Extract all events and relationships, and set parent references
for (Enrollment enrollment : enrollmentHashMap.values()) {
extractEvents(enrollment).forEach(event -> eventHashMap.put(event.getEvent(), event));
extractRelationships(enrollment).forEach(relationship -> relationshipHashMap.put(relationship.getRelationship(), relationship));
enrollment.setNotes(enrollment.getNotes().stream().filter(note -> !StringUtils.isEmpty(note.getValue())).peek(this::updateNoteReferences).collect(Collectors.toList()));
}
// Set UID for all events and notes
dataBundle.getEvents().stream().peek(event -> updateEventReferences(event, event.getEnrollment())).forEach(event -> eventHashMap.put(event.getEvent(), event));
// Extract all relationships
for (Event event : eventHashMap.values()) {
extractRelationships(event).forEach(relationship -> relationshipHashMap.put(relationship.getRelationship(), relationship));
event.setNotes(event.getNotes().stream().filter(note -> !StringUtils.isEmpty(note.getValue())).peek(this::updateNoteReferences).collect(Collectors.toList()));
}
// Set UID for all relationships
dataBundle.getRelationships().stream().peek(this::updateRelationshipReferences).forEach(relationship -> relationshipHashMap.put(relationship.getRelationship(), relationship));
return TrackerBundleParams.builder().trackedEntities(new ArrayList<>(trackedEntityMap.values())).enrollments(new ArrayList<>(enrollmentHashMap.values())).events(new ArrayList<>(eventHashMap.values())).relationships(new ArrayList<>(relationshipHashMap.values())).build();
}
Aggregations