use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class NotesConverterService method to.
@Override
public Note to(TrackedEntityComment trackedEntityComment) {
Note note = new Note();
note.setNote(trackedEntityComment.getUid());
note.setValue(trackedEntityComment.getCommentText());
note.setStoredAt(DateUtils.instantFromDate(trackedEntityComment.getCreated()));
note.setStoredBy(trackedEntityComment.getCreator());
return note;
}
use of org.hisp.dhis.tracker.domain.Note 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.domain.Note in project dhis2-core by dhis2.
the class EnrollmentNoteValidationHookTest method testNotesAreValidWhenUidDoesNotExist.
@Test
void testNotesAreValidWhenUidDoesNotExist() {
// Given
final List<Note> notes = rnd.objects(Note.class, 5).collect(Collectors.toList());
TrackerBundle trackerBundle = mock(TrackerBundle.class);
TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
when(ctx.getBundle()).thenReturn(trackerBundle);
when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
enrollment.setNotes(notes);
// When
this.hook.validateEnrollment(reporter, enrollment);
// Then
assertFalse(reporter.hasErrors());
assertThat(enrollment.getNotes(), hasSize(5));
}
use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class NotesConverterServiceTest method verifyConvertCommentsToNotes.
@Test
void verifyConvertCommentsToNotes() {
List<Note> notes = rnd.objects(Note.class, 10).collect(Collectors.toList());
final List<TrackedEntityComment> comments = notesConverterService.from(preheat, notes);
assertThat(comments, hasSize(10));
for (Note note : notes) {
assertNoteValues(comments.stream().filter(c -> c.getUid().equals(note.getNote())).findFirst().get(), note);
}
}
use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class ValidationUtils method validateNotes.
protected static List<Note> validateNotes(ValidationErrorReporter reporter, TrackerDto dto, List<Note> notesToCheck) {
TrackerImportValidationContext context = reporter.getValidationContext();
final List<Note> notes = new ArrayList<>();
for (Note note : notesToCheck) {
if (// Ignore notes with no text
isNotEmpty(note.getValue())) {
// warning, ignore the note and continue
if (isNotEmpty(note.getNote()) && context.getNote(note.getNote()).isPresent()) {
TrackerWarningReport warning = TrackerWarningReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).warningCode(TrackerErrorCode.E1119).addArg(note.getNote()).build(reporter.getValidationContext().getBundle());
reporter.addWarning(warning);
} else {
notes.add(note);
}
}
}
return notes;
}
Aggregations