Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add data element name as a fallback when sorting [DHIS2-18871] #19729

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could have an assertion just to check the order like mapping the changelogs to the order field (if possible) or to the UID and make a comment to show what is the value of the name.
Something like:
expected = List.of("with-option-set", "test-dataleement6", "test-dataelement1", "test-dataelement1", "test-dataelement1", "scheduledAt", "occurredAt")

This way would be easy to understand why the assertion makes sense.

() -> 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
Loading