Skip to content

Commit

Permalink
feat: Add atClient dates order capabilities for events [DHIS2-15900] (#…
Browse files Browse the repository at this point in the history
…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]
  • Loading branch information
enricocolasante authored Nov 27, 2023
1 parent 8a2fd86 commit d5a79f2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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<String> 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<String> 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<String> events = getEvents(params);

assertEquals(List.of("D9PbzJY8bJM", "pTzf9KYMk72"), events);
}

@Test
void testExportEvents() throws ForbiddenException, BadRequestException {
EventOperationParams params =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,38 +292,37 @@ 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");

eventDataValue.setDataElement(de.getUid());
eventDataValue.setCreatedByUserInfo(UserInfoSnapshot.from(user));
eventDataValue.setLastUpdatedByUserInfo(UserInfoSnapshot.from(user));
Set<EventDataValue> 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
Expand Down

0 comments on commit d5a79f2

Please sign in to comment.