From 0bb73a5beec70726001d44f9aab230707c7d0880 Mon Sep 17 00:00:00 2001 From: Enrico Colasante Date: Tue, 14 Jan 2025 15:57:06 -0300 Subject: [PATCH] fix: Map created date of notes as a timestamp [DHIS2-17864] (#19654) --- .../dxf2/events/event/JdbcEventStore.java | 3 +- .../store/mapper/NoteRowCallbackHandler.java | 2 +- .../org/hisp/dhis/tracker/Assertions.java | 43 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java index 7eaa6561a9fc..2c0bcf4522bf 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java @@ -734,7 +734,8 @@ public List getEventRows(EventQueryParams params) { Note note = new Note(); note.setNote(resultSet.getString("psinote_uid")); note.setValue(resultSet.getString("psinote_value")); - note.setStoredDate(DateUtils.getIso8601NoTz(resultSet.getDate("psinote_storeddate"))); + note.setStoredDate( + DateUtils.getIso8601NoTz(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/events/trackedentity/store/mapper/NoteRowCallbackHandler.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/store/mapper/NoteRowCallbackHandler.java index fc0644880711..0b9bb17c8c6e 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/store/mapper/NoteRowCallbackHandler.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/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("commenttext")); note.setStoredBy(rs.getString("creator")); - note.setStoredDate(DateUtils.getIso8601NoTz(rs.getDate("created"))); + note.setStoredDate(DateUtils.getIso8601NoTz(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 1c857014f5d7..d3beafc13706 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,11 +39,14 @@ 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.common.AuditType; import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.trackedentitycomment.TrackedEntityComment; import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit; import org.hisp.dhis.tracker.job.TrackerSideEffectDataBundle; import org.hisp.dhis.tracker.report.ImportReport; @@ -347,6 +351,45 @@ public static void assertHasTimeStamp(String 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(TrackedEntityComment::getUid, Function.identity())); + Map actualNotes = + actual.stream() + .collect(Collectors.toMap(TrackedEntityComment::getUid, Function.identity())); + List assertions = + expectedNotes.entrySet().stream() + .map( + entry -> + (Executable) + () -> { + TrackedEntityComment expectedNote = entry.getValue(); + TrackedEntityComment actualNote = actualNotes.get(entry.getKey()); + assertAll( + "note assertions " + expectedNote.getUid(), + () -> + assertEquals( + expectedNote.getCommentText(), + actualNote.getCommentText(), + "noteText"), + () -> + assertEquals( + expectedNote.getCreator(), + actualNote.getCreator(), + "creator"), + () -> + assertEquals( + expectedNote.getCreated(), + actualNote.getCreated(), + "created")); + }) + .collect(Collectors.toList()); + assertAll("note assertions", assertions); + } + private static boolean hasTimeStamp(Date date) { try {