Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Map created date of notes as a timestamp [DHIS2-17864](2.41) #19653

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ public List<org.hisp.dhis.dxf2.deprecated.tracker.event.Event> 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) {
Expand All @@ -501,7 +502,7 @@ public List<org.hisp.dhis.dxf2.deprecated.tracker.event.Event> 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"));
Expand Down Expand Up @@ -712,7 +713,8 @@ public List<EventRow> 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);
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("notetext"));
note.setStoredBy(rs.getString("creator"));
note.setStoredDate(DateUtils.toIso8601NoTz(rs.getDate("created")));
note.setStoredDate(DateUtils.toIso8601NoTz(rs.getTimestamp("created")));

return note;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
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,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;
Expand Down Expand Up @@ -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<Note> expected, List<Note> actual) {
assertContainsOnly(expected, actual);
Map<String, Note> expectedNotes =
expected.stream().collect(Collectors.toMap(Note::getUid, Function.identity()));
Map<String, Note> actualNotes =
actual.stream().collect(Collectors.toMap(Note::getUid, Function.identity()));
List<Executable> 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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1053,9 +1052,11 @@ void shouldReturnEventsWhenParamEndDueDateLaterThanEventsDueDate()
private static void assertNotes(List<Note> expected, List<Note> actual) {
assertContainsOnly(expected, actual);
Map<String, Note> expectedNotes =
expected.stream().collect(Collectors.toMap(Note::getUid, Function.identity()));
expected.stream()
.collect(Collectors.toMap(Note::getUid, java.util.function.Function.identity()));
Map<String, Note> actualNotes =
actual.stream().collect(Collectors.toMap(Note::getUid, Function.identity()));
actual.stream()
.collect(Collectors.toMap(Note::getUid, java.util.function.Function.identity()));
List<Executable> assertions =
expectedNotes.entrySet().stream()
.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1351,7 +1352,7 @@ void shouldReturnTrackedEntityWithEventsAndNotesGivenTheyShouldBeIncluded()
.findFirst();
Set<Event> 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
Expand Down
Loading