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)
  • Loading branch information
enricocolasante committed Dec 30, 2024
1 parent 5079086 commit 695768b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,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 @@ -54,14 +54,20 @@
import org.hisp.dhis.common.SlimPager;
import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams;
import org.hisp.dhis.dxf2.events.enrollment.EnrollmentService;
import org.hisp.dhis.dxf2.events.event.Event;
import org.hisp.dhis.dxf2.events.event.EventQueryParams;
import org.hisp.dhis.dxf2.events.event.EventService;
import org.hisp.dhis.dxf2.events.event.Events;
import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance;
import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService;
import org.hisp.dhis.feedback.BadRequestException;
import org.hisp.dhis.feedback.ForbiddenException;
import org.hisp.dhis.feedback.NotFoundException;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramInstance;
import org.hisp.dhis.program.ProgramInstanceQueryParams;
import org.hisp.dhis.program.ProgramStageInstance;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams;
Expand All @@ -80,6 +86,8 @@ class OrderAndPaginationExporterTest extends TrackerTest {

@Autowired private EventService eventService;

@Autowired private EnrollmentService enrollmentService;

@Autowired private TrackedEntityInstanceService trackedEntityService;

@Autowired private TrackerImportService trackerImportService;
Expand Down Expand Up @@ -133,6 +141,27 @@ void setUp() {
injectAdminUser();
}

@Test
void shouldOrderEventsByStatusAndByDefaultOrder() throws ForbiddenException, BadRequestException {
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 695768b

Please sign in to comment.