diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/event/JdbcEventStore.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/event/JdbcEventStore.java index a70dd86f2ea9..d12112080c8e 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/event/JdbcEventStore.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/event/JdbcEventStore.java @@ -486,7 +486,8 @@ public List getEvents( Note note = new Note(); note.setNote(resultSet.getString("psinote_uid")); note.setValue(resultSet.getString("psinote_value")); - note.setStoredDate(DateUtils.toIso8601NoTz(resultSet.getDate("psinote_storeddate"))); + note.setStoredDate( + DateUtils.toIso8601NoTz(resultSet.getTimestamp("psinote_storeddate"))); note.setStoredBy(resultSet.getString("psinote_storedby")); if (resultSet.getObject("usernote_id") != null) { @@ -501,7 +502,7 @@ public List getEvents( resultSet.getString("userinfo_surname"))); } - note.setLastUpdated(resultSet.getDate("psinote_lastupdated")); + note.setLastUpdated(resultSet.getTimestamp("psinote_lastupdated")); event.getNotes().add(note); notes.add(resultSet.getString("psinote_id")); @@ -712,7 +713,8 @@ public List getEventRows(EventSearchParams params) { Note note = new Note(); note.setNote(resultSet.getString("psinote_uid")); note.setValue(resultSet.getString("psinote_value")); - note.setStoredDate(DateUtils.toIso8601NoTz(resultSet.getDate("psinote_storeddate"))); + note.setStoredDate( + DateUtils.toIso8601NoTz(resultSet.getTimestamp("psinote_storeddate"))); note.setStoredBy(resultSet.getString("psinote_storedby")); eventRow.getNotes().add(note); diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/store/mapper/NoteRowCallbackHandler.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/store/mapper/NoteRowCallbackHandler.java index f190a620ed89..32bebe7d7350 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/store/mapper/NoteRowCallbackHandler.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/deprecated/tracker/trackedentity/store/mapper/NoteRowCallbackHandler.java @@ -52,7 +52,7 @@ private Note getNote(ResultSet rs) throws SQLException { note.setNote(rs.getString("uid")); note.setValue(rs.getString("notetext")); note.setStoredBy(rs.getString("creator")); - note.setStoredDate(DateUtils.toIso8601NoTz(rs.getDate("created"))); + note.setStoredDate(DateUtils.toIso8601NoTz(rs.getTimestamp("created"))); return note; } diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/NoteRowCallbackHandler.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/NoteRowCallbackHandler.java index 43971c8aa358..0526b7105945 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/NoteRowCallbackHandler.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/trackedentity/aggregates/mapper/NoteRowCallbackHandler.java @@ -50,7 +50,7 @@ private Note getNote(ResultSet rs) throws SQLException { note.setUid(rs.getString("uid")); note.setNoteText(rs.getString("notetext")); note.setCreator(rs.getString("creator")); - note.setCreated(rs.getDate("created")); + note.setCreated(rs.getTimestamp("created")); return note; } } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/Assertions.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/Assertions.java index f23cb90197ce..9cb17a7be343 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/Assertions.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/Assertions.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.tracker; +import static org.hisp.dhis.utils.Assertions.assertContainsOnly; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -38,12 +39,17 @@ import java.util.Arrays; import java.util.Collections; import java.util.Date; +import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.function.Function; import java.util.function.Supplier; +import java.util.stream.Collectors; import org.hisp.dhis.changelog.ChangeLogType; import org.hisp.dhis.common.Pager; import org.hisp.dhis.common.SlimPager; import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.note.Note; import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueChangeLog; import org.hisp.dhis.tracker.imports.report.ImportReport; import org.hisp.dhis.tracker.imports.report.Status; @@ -312,6 +318,42 @@ public static void assertHasTimeStamp(Date date) { String.format("Supported format is %s but found %s", DATE_WITH_TIMESTAMP_PATTERN, date)); } + public static void assertNotes(List expected, List actual) { + assertContainsOnly(expected, actual); + Map expectedNotes = + expected.stream().collect(Collectors.toMap(Note::getUid, Function.identity())); + Map actualNotes = + actual.stream().collect(Collectors.toMap(Note::getUid, Function.identity())); + List assertions = + expectedNotes.entrySet().stream() + .map( + entry -> + (Executable) + () -> { + Note expectedNote = entry.getValue(); + Note actualNote = actualNotes.get(entry.getKey()); + assertAll( + "note assertions " + expectedNote.getUid(), + () -> + assertEquals( + expectedNote.getNoteText(), + actualNote.getNoteText(), + "noteText"), + () -> + assertEquals( + expectedNote.getCreator(), + actualNote.getCreator(), + "creator"), + () -> + assertEquals( + expectedNote.getCreated(), + actualNote.getCreated(), + "created")); + }) + .toList(); + assertAll("note assertions", assertions); + } + private static boolean hasTimeStamp(Date date) { try { diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java index 4b9c74b937b1..0acfa9318757 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java @@ -48,7 +48,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Function; import java.util.stream.Collectors; import org.hisp.dhis.category.CategoryOption; import org.hisp.dhis.common.BaseIdentifiableObject; @@ -1053,9 +1052,11 @@ void shouldReturnEventsWhenParamEndDueDateLaterThanEventsDueDate() private static void assertNotes(List expected, List actual) { assertContainsOnly(expected, actual); Map expectedNotes = - expected.stream().collect(Collectors.toMap(Note::getUid, Function.identity())); + expected.stream() + .collect(Collectors.toMap(Note::getUid, java.util.function.Function.identity())); Map actualNotes = - actual.stream().collect(Collectors.toMap(Note::getUid, Function.identity())); + actual.stream() + .collect(Collectors.toMap(Note::getUid, java.util.function.Function.identity())); List assertions = expectedNotes.entrySet().stream() .map( diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityServiceTest.java index b6e88fb14672..e589f64622d8 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityServiceTest.java @@ -33,6 +33,7 @@ import static org.hisp.dhis.common.OrganisationUnitSelectionMode.CHILDREN; import static org.hisp.dhis.common.OrganisationUnitSelectionMode.DESCENDANTS; import static org.hisp.dhis.common.OrganisationUnitSelectionMode.SELECTED; +import static org.hisp.dhis.tracker.Assertions.assertNotes; import static org.hisp.dhis.tracker.TrackerTestUtils.oneHourAfter; import static org.hisp.dhis.tracker.TrackerTestUtils.oneHourBefore; import static org.hisp.dhis.tracker.TrackerTestUtils.twoHoursAfter; @@ -1351,7 +1352,7 @@ void shouldReturnTrackedEntityWithEventsAndNotesGivenTheyShouldBeIncluded() .findFirst(); Set events = enrollmentA.get().getEvents(); assertContainsOnly(Set.of(eventA), events); - assertContainsOnly(Set.of(note), events.stream().findFirst().get().getNotes()); + assertNotes(eventA.getNotes(), events.stream().findFirst().get().getNotes()); } @Test