Skip to content

Commit

Permalink
feat: Add data element name as a fallback when sorting [DHIS2-18871]
Browse files Browse the repository at this point in the history
  • Loading branch information
muilpp committed Jan 20, 2025
1 parent 5510546 commit 320dde8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public class HibernateEventChangeLogStore {
private static final String COLUMN_CHANGELOG_DATA_ELEMENT = "d.uid";
private static final String COLUMN_CHANGELOG_FIELD = "ecl.eventField";
private static final String ORDER_CHANGE_EXPRESSION =
"CONCAT(COALESCE(d.formName, ''), COALESCE(" + COLUMN_CHANGELOG_FIELD + ", ''))";
"CONCAT(COALESCE(d.formName, ''), COALESCE(d.name, ''), COALESCE("
+ COLUMN_CHANGELOG_FIELD
+ ", ''))";
private static final String DEFAULT_ORDER =
COLUMN_CHANGELOG_CREATED + " " + SortDirection.DESC.getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,31 @@ void shouldSortChangeLogsWhenOrderingByChangeDescAndChangesOnlyToEventFields()
() -> assertFieldCreate("geometry", "(-11.419700, 8.103900)", changeLogs.get(4)));
}

@Test
void shouldSortChangeLogsByNameWhenOrderingByChangeAndDataElementDoesNotHaveFormName()
throws ForbiddenException, NotFoundException {
EventChangeLogOperationParams params =
EventChangeLogOperationParams.builder().orderBy("change", SortDirection.DESC).build();
Event event = getEvent("pTzf9KYMk72");

updateDataValues(event, "DATAEL00001", "value00002", "value00003");

List<EventChangeLog> changeLogs =
eventChangeLogService
.getEventChangeLog(UID.of("pTzf9KYMk72"), params, defaultPageParams)
.getItems();

assertNumberOfChanges(7, changeLogs);
assertAll(
() -> assertDataElementCreate("DATAEL00005", "option1", changeLogs.get(0)),
() -> assertDataElementCreate("DATAEL00006", "88", changeLogs.get(1)),
() -> assertDataElementUpdate("DATAEL00001", "value00002", "value00003", changeLogs.get(2)),
() -> assertDataElementUpdate("DATAEL00001", "value00001", "value00002", changeLogs.get(3)),
() -> assertDataElementCreate("DATAEL00001", "value00001", changeLogs.get(4)),
() -> assertFieldCreate("scheduledAt", "2019-01-28 12:32:38.100", changeLogs.get(5)),
() -> assertFieldCreate("occurredAt", "2019-01-25 12:10:38.100", changeLogs.get(6)));
}

@Test
void shouldFilterChangeLogsWhenFilteringByUser() throws ForbiddenException, NotFoundException {
EventChangeLogOperationParams params =
Expand Down

0 comments on commit 320dde8

Please sign in to comment.