use of org.hisp.dhis.trackedentitycomment.TrackedEntityComment in project dhis2-core by dhis2.
the class NotesConverterService method from.
@Override
public TrackedEntityComment from(TrackerPreheat preheat, Note note) {
TrackedEntityComment comment = new TrackedEntityComment();
comment.setUid(note.getNote());
comment.setAutoFields();
comment.setCommentText(note.getValue());
comment.setLastUpdatedBy(preheat.getUser());
comment.setLastUpdated(new Date());
comment.setCreator(getValidUsername(note.getStoredBy(), preheat.getUser()));
return comment;
}
use of org.hisp.dhis.trackedentitycomment.TrackedEntityComment in project dhis2-core by dhis2.
the class EventImportValidationTest method testValidateAndAddNotesToEvent.
@Test
void testValidateAndAddNotesToEvent() throws IOException {
Date now = new Date();
// When
TrackerImportReport trackerImportReport = createEvent("tracker/validations/events-with-notes-data.json");
// Then
// Fetch the UID of the newly created event
final ProgramStageInstance programStageInstance = getEventFromReport(trackerImportReport);
assertThat(programStageInstance.getComments(), hasSize(3));
// Validate note content
Stream.of("first note", "second note", "third note").forEach(t -> {
TrackedEntityComment comment = getByComment(programStageInstance.getComments(), t);
assertTrue(CodeGenerator.isValidUid(comment.getUid()));
assertTrue(comment.getCreated().getTime() > now.getTime());
assertTrue(comment.getLastUpdated().getTime() > now.getTime());
assertNotNull(comment.getCreator());
assertEquals(ADMIN_USER_UID, comment.getLastUpdatedBy().getUid());
});
}
use of org.hisp.dhis.trackedentitycomment.TrackedEntityComment 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.trackedentitycomment.TrackedEntityComment 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.trackedentitycomment.TrackedEntityComment in project dhis2-core by dhis2.
the class EventNoteValidationHookTest method testNoteWithExistingUidAndNoTextIsIgnored.
@Test
void testNoteWithExistingUidAndNoTextIsIgnored() {
// Given
final Note note = rnd.nextObject(Note.class);
note.setValue(null);
TrackerBundle trackerBundle = mock(TrackerBundle.class);
TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
when(ctx.getBundle()).thenReturn(trackerBundle);
when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
when(ctx.getNote(note.getNote())).thenReturn(Optional.of(new TrackedEntityComment()));
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
event.setNotes(Collections.singletonList(note));
// When
this.hook.validateEvent(reporter, event);
// Then
assertFalse(reporter.hasErrors());
assertThat(event.getNotes(), hasSize(0));
}
Aggregations