Search in sources :

Example 6 with TrackedEntityComment

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;
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Date(java.util.Date)

Example 7 with TrackedEntityComment

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());
    });
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Date(java.util.Date) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test)

Example 8 with TrackedEntityComment

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));
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) BeanRandomizer(org.hisp.dhis.random.BeanRandomizer) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) E1119(org.hisp.dhis.tracker.report.TrackerErrorCode.E1119) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Note(org.hisp.dhis.tracker.domain.Note) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ENROLLMENT(org.hisp.dhis.tracker.TrackerType.ENROLLMENT) Mockito.when(org.mockito.Mockito.when) ValidationMode(org.hisp.dhis.tracker.ValidationMode) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Collections(java.util.Collections) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Mockito.mock(org.mockito.Mockito.mock) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Note(org.hisp.dhis.tracker.domain.Note) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 9 with TrackedEntityComment

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);
    }
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) CoreMatchers.is(org.hamcrest.CoreMatchers.is) BeforeEach(org.junit.jupiter.api.BeforeEach) BeanRandomizer(org.hisp.dhis.random.BeanRandomizer) Collectors(java.util.stream.Collectors) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Test(org.junit.jupiter.api.Test) List(java.util.List) TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Note(org.hisp.dhis.tracker.domain.Note) Matchers.hasSize(org.hamcrest.Matchers.hasSize) User(org.hisp.dhis.user.User) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) DateUtils(org.hisp.dhis.util.DateUtils) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest) Note(org.hisp.dhis.tracker.domain.Note) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 10 with TrackedEntityComment

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));
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Note(org.hisp.dhis.tracker.domain.Note) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

TrackedEntityComment (org.hisp.dhis.trackedentitycomment.TrackedEntityComment)20 Test (org.junit.jupiter.api.Test)11 Note (org.hisp.dhis.tracker.domain.Note)9 Date (java.util.Date)8 List (java.util.List)6 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)5 Collectors (java.util.stream.Collectors)4 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)4 Matchers.hasSize (org.hamcrest.Matchers.hasSize)4 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)4 BeanRandomizer (org.hisp.dhis.random.BeanRandomizer)4 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)4 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)4 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)4 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Note (org.hisp.dhis.dxf2.events.event.Note)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2