Skip to content

Commit

Permalink
fix: Map created date of notes as a timestamp [DHIS2-17864]
Browse files Browse the repository at this point in the history
  • Loading branch information
enricocolasante committed Jan 14, 2025
1 parent 8c5f02e commit c46afea
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,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 @@ -36,9 +37,14 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
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.report.TrackerErrorCode;
import org.hisp.dhis.tracker.report.TrackerImportReport;
Expand Down Expand Up @@ -201,6 +207,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);
}

/**
* assertTrackedEntityDataValueAudit asserts a TrackedEntityDataValueAudit obtained from the db
* and compares it with the expected value, auditType and dataElement.
Expand Down

0 comments on commit c46afea

Please sign in to comment.