Skip to content

Commit

Permalink
fix: Map created date of notes as a timestamp [DHIS2-17864] (#19654)
Browse files Browse the repository at this point in the history
  • Loading branch information
enricocolasante authored Jan 14, 2025
1 parent ea05d49 commit 0bb73a5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,8 @@ public List<EventRow> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<TrackedEntityComment> expected, List<TrackedEntityComment> actual) {
assertContainsOnly(expected, actual);
Map<String, TrackedEntityComment> expectedNotes =
expected.stream()
.collect(Collectors.toMap(TrackedEntityComment::getUid, Function.identity()));
Map<String, TrackedEntityComment> actualNotes =
actual.stream()
.collect(Collectors.toMap(TrackedEntityComment::getUid, Function.identity()));
List<Executable> 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 {

Expand Down

0 comments on commit 0bb73a5

Please sign in to comment.