diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java index d8f17b4daf70..5b08f2a8d252 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java @@ -771,7 +771,13 @@ private void collectScanTargets(Map, List> targets) { } objects.forEach( - o -> list.addAll(ReflectionUtils.invokeMethod(o, property.getGetterMethod()))); + o -> { + Collection propertyValue = + ReflectionUtils.invokeMethod(o, property.getGetterMethod()); + if (!org.apache.commons.collections4.CollectionUtils.isEmpty(propertyValue)) { + list.addAll(propertyValue); + } + }); targets.put(property.getItemKlass(), list); } else { List list = new ArrayList<>(); @@ -781,7 +787,12 @@ private void collectScanTargets(Map, List> targets) { } objects.forEach( - o -> list.add(ReflectionUtils.invokeMethod(o, property.getGetterMethod()))); + o -> { + Object item = ReflectionUtils.invokeMethod(o, property.getGetterMethod()); + if (item != null) { + list.add(item); + } + }); targets.put(property.getKlass(), list); } } diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/EventVisualizationControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/EventVisualizationControllerTest.java index 28a56d78deb5..48afdc0f4ffb 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/EventVisualizationControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/EventVisualizationControllerTest.java @@ -34,6 +34,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hisp.dhis.web.HttpStatus.BAD_REQUEST; import static org.hisp.dhis.web.HttpStatus.CREATED; +import static org.hisp.dhis.web.HttpStatus.OK; import static org.hisp.dhis.web.WebClientUtils.assertStatus; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -110,6 +111,27 @@ void testPostForSingleEventDate() { assertThat(nodeMap.get("filters").toString(), not(containsString(eventDateDimension))); } + @Test + void testDelete() { + // Given + String eventDateDimension = "eventDate"; + String eventDate = "2021-07-21_2021-08-01"; + String dimensionBody = + "{'dimension': '" + eventDateDimension + "', 'items': [{'id': '" + eventDate + "'}]}"; + String body = + "{'name': 'Name Test', 'type': 'STACKED_COLUMN','eventRepetitions':null, 'program': {'id':'" + + mockProgram.getUid() + + "'}, 'columns': [" + + dimensionBody + + "]}"; + + // When + String uid = assertStatus(CREATED, POST("/eventVisualizations/", body)); + + // Then + DELETE("/eventVisualizations/" + uid).content(OK); + } + @Test @SuppressWarnings("unchecked") void testPostForMultiEventDates() {