From d5a79f26165df30ecd1a8323c2dc21601646a945 Mon Sep 17 00:00:00 2001 From: Enrico Colasante Date: Mon, 27 Nov 2023 08:25:28 +0000 Subject: [PATCH] feat: Add atClient dates order capabilities for events [DHIS2-15900] (#15733) * feat: Add atClient dates order capabilities for events [DHIS2-15900] * feat: Add atClient dates order capabilities for events [DHIS2-15900] * feat: Add atClient dates order capabilities for events [DHIS2-15900] --- .../export/event/EventExporterTest.java | 57 +++++++++++++++++++ .../tracker/event_and_enrollment.json | 4 ++ .../event/EventsExportControllerTest.java | 41 +++++++------ 3 files changed, 81 insertions(+), 21 deletions(-) diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java index e99448529462..5599ed85695b 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/EventExporterTest.java @@ -76,6 +76,7 @@ import org.hisp.dhis.tracker.imports.TrackerImportService; import org.hisp.dhis.user.User; import org.hisp.dhis.util.DateUtils; +import org.hisp.dhis.webapi.controller.event.mapper.SortDirection; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.function.Executable; @@ -179,6 +180,62 @@ void shouldReturnEventsWithNotes() throws ForbiddenException, BadRequestExceptio () -> assertNote(importUser, "comment value", notes.get(1))); } + @Test + void shouldOrderEventsByCreatedAtClientInAscOrder() + throws ForbiddenException, BadRequestException { + EventOperationParams params = + operationParamsBuilder + .programStageUid(programStage.getUid()) + .orderBy("createdAtClient", SortDirection.ASC) + .build(); + + List events = getEvents(params); + + assertEquals(List.of("D9PbzJY8bJM", "pTzf9KYMk72"), events); + } + + @Test + void shouldOrderEventsByCreatedAtClientInDescOrder() + throws ForbiddenException, BadRequestException { + EventOperationParams params = + operationParamsBuilder + .programStageUid(programStage.getUid()) + .orderBy("createdAtClient", SortDirection.DESC) + .build(); + + List events = getEvents(params); + + assertEquals(List.of("pTzf9KYMk72", "D9PbzJY8bJM"), events); + } + + @Test + void shouldOrderEventsByUpdatedAtClientInAscOrder() + throws ForbiddenException, BadRequestException { + EventOperationParams params = + operationParamsBuilder + .programStageUid(programStage.getUid()) + .orderBy("lastUpdatedAtClient", SortDirection.ASC) + .build(); + + List events = getEvents(params); + + assertEquals(List.of("pTzf9KYMk72", "D9PbzJY8bJM"), events); + } + + @Test + void shouldOrderEventsByUpdatedAtClientInDescOrder() + throws ForbiddenException, BadRequestException { + EventOperationParams params = + operationParamsBuilder + .programStageUid(programStage.getUid()) + .orderBy("lastUpdatedAtClient", SortDirection.DESC) + .build(); + + List events = getEvents(params); + + assertEquals(List.of("D9PbzJY8bJM", "pTzf9KYMk72"), events); + } + @Test void testExportEvents() throws ForbiddenException, BadRequestException { EventOperationParams params = diff --git a/dhis-2/dhis-test-integration/src/test/resources/tracker/event_and_enrollment.json b/dhis-2/dhis-test-integration/src/test/resources/tracker/event_and_enrollment.json index 7b60887b277b..b8a96613c302 100644 --- a/dhis-2/dhis-test-integration/src/test/resources/tracker/event_and_enrollment.json +++ b/dhis-2/dhis-test-integration/src/test/resources/tracker/event_and_enrollment.json @@ -508,6 +508,8 @@ "relationships": [], "occurredAt": "2019-01-25T12:10:38.100", "scheduledAt": "2019-01-28T12:32:38.100", + "createdAtClient": "2020-01-25T12:10:38.100", + "updatedAtClient": "2020-01-26T12:10:38.100", "storedBy": "admin", "followUp": true, "deleted": false, @@ -586,6 +588,8 @@ "relationships": [], "occurredAt": "2020-01-28T00:00:00.000", "scheduledAt": "2019-01-28T12:10:38.100", + "createdAtClient": "2019-01-25T12:10:38.100", + "updatedAtClient": "2021-01-26T12:10:38.100", "storedBy": "admin", "followUp": true, "deleted": false, diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportControllerTest.java index a0c9d9f1a14b..602ccbb64260 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportControllerTest.java @@ -292,10 +292,10 @@ void getEventByIdContainsCreatedByAndUpdateByAndAssignedUserInDataValues() { TrackedEntity te = trackedEntity(); Enrollment enrollment = enrollment(te); - Event programStageInstance = event(enrollment); - programStageInstance.setCreatedByUserInfo(UserInfoSnapshot.from(user)); - programStageInstance.setLastUpdatedByUserInfo(UserInfoSnapshot.from(user)); - programStageInstance.setAssignedUser(user); + Event event = event(enrollment); + event.setCreatedByUserInfo(UserInfoSnapshot.from(user)); + event.setLastUpdatedByUserInfo(UserInfoSnapshot.from(user)); + event.setAssignedUser(user); EventDataValue eventDataValue = new EventDataValue(); eventDataValue.setValue("6"); @@ -303,27 +303,26 @@ void getEventByIdContainsCreatedByAndUpdateByAndAssignedUserInDataValues() { eventDataValue.setCreatedByUserInfo(UserInfoSnapshot.from(user)); eventDataValue.setLastUpdatedByUserInfo(UserInfoSnapshot.from(user)); Set eventDataValues = Set.of(eventDataValue); - programStageInstance.setEventDataValues(eventDataValues); - manager.save(programStageInstance); - - JsonObject event = - GET("/tracker/events/{id}", programStageInstance.getUid()).content(HttpStatus.OK); - - assertTrue(event.isObject()); - assertFalse(event.isEmpty()); - assertEquals(programStageInstance.getUid(), event.getString("event").string()); - assertEquals(enrollment.getUid(), event.getString("enrollment").string()); - assertEquals(orgUnit.getUid(), event.getString("orgUnit").string()); - assertEquals(user.getUsername(), event.getString("createdBy.username").string()); - assertEquals(user.getUsername(), event.getString("updatedBy.username").string()); - assertEquals(user.getDisplayName(), event.getString("assignedUser.displayName").string()); - assertFalse(event.getArray("dataValues").isEmpty()); + event.setEventDataValues(eventDataValues); + manager.save(event); + + JsonObject jsonEvent = GET("/tracker/events/{id}", event.getUid()).content(HttpStatus.OK); + + assertTrue(jsonEvent.isObject()); + assertFalse(jsonEvent.isEmpty()); + assertEquals(event.getUid(), jsonEvent.getString("event").string()); + assertEquals(enrollment.getUid(), jsonEvent.getString("enrollment").string()); + assertEquals(orgUnit.getUid(), jsonEvent.getString("orgUnit").string()); + assertEquals(user.getUsername(), jsonEvent.getString("createdBy.username").string()); + assertEquals(user.getUsername(), jsonEvent.getString("updatedBy.username").string()); + assertEquals(user.getDisplayName(), jsonEvent.getString("assignedUser.displayName").string()); + assertFalse(jsonEvent.getArray("dataValues").isEmpty()); assertEquals( user.getUsername(), - event.getArray("dataValues").getObject(0).getString("createdBy.username").string()); + jsonEvent.getArray("dataValues").getObject(0).getString("createdBy.username").string()); assertEquals( user.getUsername(), - event.getArray("dataValues").getObject(0).getString("updatedBy.username").string()); + jsonEvent.getArray("dataValues").getObject(0).getString("updatedBy.username").string()); } @Test