From 320dde8edc0ee1df208d383770bdbb30d2645d50 Mon Sep 17 00:00:00 2001 From: Marc Date: Mon, 20 Jan 2025 20:16:18 +0100 Subject: [PATCH] feat: Add data element name as a fallback when sorting [DHIS2-18871] --- .../event/HibernateEventChangeLogStore.java | 4 ++- .../OrderAndFilterEventChangeLogTest.java | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/HibernateEventChangeLogStore.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/HibernateEventChangeLogStore.java index 53766ba3884..98aebbf7a0f 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/HibernateEventChangeLogStore.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/HibernateEventChangeLogStore.java @@ -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(); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/OrderAndFilterEventChangeLogTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/OrderAndFilterEventChangeLogTest.java index c01879abbcb..1e2aa12cc8f 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/OrderAndFilterEventChangeLogTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/tracker/export/event/OrderAndFilterEventChangeLogTest.java @@ -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 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 =