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] #19236

Merged
merged 1 commit into from
Nov 20, 2024
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 @@ -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.test.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,16 @@
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.common.Pager;
import org.hisp.dhis.common.SlimPager;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.note.Note;
import org.hisp.dhis.tracker.imports.report.ImportReport;
import org.hisp.dhis.tracker.imports.report.Status;
import org.hisp.dhis.tracker.imports.report.ValidationReport;
Expand Down Expand Up @@ -309,6 +315,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 @@ -33,6 +33,7 @@
import static org.hisp.dhis.test.utils.Assertions.assertIsEmpty;
import static org.hisp.dhis.tracker.Assertions.assertHasTimeStamp;
import static org.hisp.dhis.tracker.Assertions.assertNoErrors;
import static org.hisp.dhis.tracker.Assertions.assertNotes;
import static org.hisp.dhis.util.DateUtils.parseDate;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -45,7 +46,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 All @@ -59,7 +59,6 @@
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.feedback.BadRequestException;
import org.hisp.dhis.feedback.ForbiddenException;
import org.hisp.dhis.note.Note;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.EnrollmentStatus;
import org.hisp.dhis.program.Event;
Expand Down Expand Up @@ -929,47 +928,6 @@ void shouldReturnEventsWhenParamEndDueDateLaterThanEventsDueDate()
assertContainsOnly(List.of("D9PbzJY8bJM", "pTzf9KYMk72"), events);
}

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()));
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"),
() ->
assertEquals(
expectedNote.getLastUpdated(),
actualNote.getLastUpdated(),
"lastUpdated"));
})
.toList();
assertAll("note assertions", assertions);
}

private DataElement dataElement(UID uid) {
return dataElementService.getDataElement(uid.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static org.hisp.dhis.test.utils.Assertions.assertContains;
import static org.hisp.dhis.test.utils.Assertions.assertContainsOnly;
import static org.hisp.dhis.test.utils.Assertions.assertIsEmpty;
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 @@ -1311,7 +1312,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