From 857b68b0a23662612bec72e9ab81c60dacd01290 Mon Sep 17 00:00:00 2001 From: teleivo Date: Sat, 23 Nov 2024 20:15:06 +0100 Subject: [PATCH] fix: dataElementIdScheme should not filter events [DHIS2-14968] (#19267) --- .../tracker/export/event/JdbcEventStore.java | 1 - .../org/hisp/dhis/test/utils/Assertions.java | 11 +++++++++++ .../export/IdSchemeExportControllerTest.java | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/JdbcEventStore.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/JdbcEventStore.java index 5f936331d2b..8712da90c83 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/JdbcEventStore.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/JdbcEventStore.java @@ -650,7 +650,6 @@ lateral jsonb_each( ) as eventdatavalue(dataelement_uid, value) on true left join dataelement de on de.uid = eventdatavalue.dataelement_uid -where eventdatavalue.dataelement_uid is not null """); } diff --git a/dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/test/utils/Assertions.java b/dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/test/utils/Assertions.java index 2a25cb922a8..869fe537d80 100644 --- a/dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/test/utils/Assertions.java +++ b/dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/test/utils/Assertions.java @@ -128,6 +128,17 @@ public static void assertIsEmpty(Collection actual) { assertTrue(actual.isEmpty(), actual.toString()); } + /** + * Asserts that the given collection is not null and empty. + * + * @param actual the collection. + * @param message fails with this message + */ + public static void assertIsEmpty(Collection actual, String message) { + assertNotNull(actual, message); + assertTrue(actual.isEmpty(), message); + } + /** * Asserts that the given collection is not null and not empty. * diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/IdSchemeExportControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/IdSchemeExportControllerTest.java index 16f9076a330..34b73b00454 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/IdSchemeExportControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/IdSchemeExportControllerTest.java @@ -29,6 +29,7 @@ import static org.hisp.dhis.test.utils.Assertions.assertContains; import static org.hisp.dhis.test.utils.Assertions.assertContainsOnly; +import static org.hisp.dhis.test.utils.Assertions.assertIsEmpty; import static org.hisp.dhis.test.utils.Assertions.assertNotEmpty; import static org.hisp.dhis.test.webapi.Assertions.assertWebMessage; import static org.junit.jupiter.api.Assertions.assertAll; @@ -75,6 +76,7 @@ import org.hisp.dhis.webapi.controller.tracker.JsonEvent; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.function.Executable; import org.junit.jupiter.params.ParameterizedTest; @@ -149,6 +151,7 @@ void setUpUser() { @MethodSource(value = "shouldExportMetadataUsingGivenIdSchemeProvider") void shouldExportMetadataUsingGivenIdScheme(TrackerIdSchemeParam idSchemeParam) { Event event = get(Event.class, "QRYjLTiJTrA"); + assertNotEmpty(event.getEventDataValues(), "test expects an event with data values"); // maps JSON fields to idScheme request parameters Map idSchemeRequestParams = @@ -266,6 +269,19 @@ void shouldExportMetadataUsingGivenIdScheme(TrackerIdSchemeParam idSchemeParam) assertMetadataIdScheme(metadata, actual, idSchemeParam, "event"); } + @Test + void shouldExportEventUsingNonUIDDataElementIdSchemeEvenIfItHasNoDataValues() { + Event event = get(Event.class, "jxgFyJEMUPf"); + assertIsEmpty(event.getEventDataValues(), "test expects an event with no data values"); + + JsonEvent actual = + GET("/tracker/events/{id}?fields=event,dataValues&dataElementIdScheme=NAME", event.getUid()) + .content(HttpStatus.OK) + .as(JsonEvent.class); + + assertEquals("jxgFyJEMUPf", actual.getEvent()); + } + @ParameterizedTest @ValueSource(strings = {"/{id}?", "?events={id}&paging=true&", "?events={id}&paging=false&"}) void shouldReportMetadataWhichDoesNotHaveAnIdentifierForGivenIdScheme(String urlPortion) {