Skip to content

Commit

Permalink
fix: Always add default order as last order param in tracker exporter…
Browse files Browse the repository at this point in the history
…s [DHIS2-17671] (#19551) (#19571)
  • Loading branch information
enricocolasante authored Dec 30, 2024
1 parent 79db883 commit 827aa78
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1990,7 +1990,7 @@ private String getOrderQuery(EventQueryParams params) {
}

if (!orderFields.isEmpty()) {
return "order by " + StringUtils.join(orderFields, ',') + " ";
return "order by " + StringUtils.join(orderFields, ',') + ", psi_id desc ";
} else {
return "order by psi_lastupdated desc ";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,27 @@ void setUp() {
injectAdminUser();
}

@Test
void shouldOrderEventsByStatusAndByDefaultOrder() {
List<String> expected =
Stream.of(
get(ProgramStageInstance.class, "ck7DzdxqLqA"),
get(ProgramStageInstance.class, "kWjSezkXHVp"),
get(ProgramStageInstance.class, "OTmjvJDn0Fu"))
.sorted(Comparator.comparing(ProgramStageInstance::getId).reversed()) // reversed = desc
.map(ProgramStageInstance::getUid)
.collect(Collectors.toList());

EventQueryParams params = new EventQueryParams();
params.setOrgUnit(get(OrganisationUnit.class, "DiszpKrYNg8"));
params.setEvents(Set.of("ck7DzdxqLqA", "kWjSezkXHVp", "OTmjvJDn0Fu"));
params.addOrders(List.of(new OrderParam("status", SortDirection.DESC)));

List<String> actual = getEvents(params);

assertEquals(expected, actual);
}

@Test
void shouldReturnPaginatedEventsWithNotesGivenNonDefaultPageSize() {
EventQueryParams params = new EventQueryParams();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,22 @@
"to": {
"event": "pTzf9KYMk72"
}
},
{
"relationship": "fHn74P5T3r1",
"relationshipType": {
"idScheme": "UID",
"identifier": "TV9oB9LT3sh"
},
"createdAtClient": "2018-11-01T13:24:37.118",
"bidirectional": false,
"deleted": false,
"from": {
"trackedEntity": "dUE514NMOlo"
},
"to": {
"event": "D9PbzJY8bJM"
}
}
],
"username": "system-process"
Expand Down

0 comments on commit 827aa78

Please sign in to comment.