From c78b77abeeda06f1dca77815ab1190547f2539ab Mon Sep 17 00:00:00 2001 From: lincmba Date: Tue, 6 Aug 2024 01:23:30 +0300 Subject: [PATCH] Bug Fix Handle null adminlevels in post filtering location hierarchy --- exec/pom.xml | 4 ++-- plugins/pom.xml | 2 +- .../plugins/LocationHierarchyEndpointHelper.java | 3 +++ .../LocationHierarchyEndpointHelperTest.java | 15 +++++++++++++++ pom.xml | 2 +- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/exec/pom.xml b/exec/pom.xml index 803c4ad..c4293e4 100755 --- a/exec/pom.xml +++ b/exec/pom.xml @@ -4,7 +4,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.4 + 2.0.5 exec @@ -70,7 +70,7 @@ org.smartregister plugins - 2.0.4 + 2.0.5 diff --git a/plugins/pom.xml b/plugins/pom.xml index 328bcab..e17ccd6 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -4,7 +4,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.4 + 2.0.5 plugins diff --git a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/LocationHierarchyEndpointHelper.java b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/LocationHierarchyEndpointHelper.java index a931c8a..24c1f9f 100644 --- a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/LocationHierarchyEndpointHelper.java +++ b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/LocationHierarchyEndpointHelper.java @@ -411,6 +411,9 @@ public List generateAdminLevels( public List filterLocationsByAdminLevels( List locations, List postFetchAdminLevels) { + if (postFetchAdminLevels == null) { + return locations; + } List allLocations = new ArrayList<>(); for (Location location : locations) { for (CodeableConcept codeableConcept : location.getType()) { diff --git a/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/LocationHierarchyEndpointHelperTest.java b/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/LocationHierarchyEndpointHelperTest.java index 184d8d0..62a14c5 100644 --- a/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/LocationHierarchyEndpointHelperTest.java +++ b/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/LocationHierarchyEndpointHelperTest.java @@ -299,6 +299,21 @@ public void testFilterLocationsByAdminLevelsBasic() { Assert.assertEquals("3", filteredLocations.get(1).getId()); } + @Test + public void testFilterLocationsByAdminLevelsWithNullAdminLevelsDoesNotFilter() { + List locations = createLocationList(5, true); + + List filteredLocations = + locationHierarchyEndpointHelper.filterLocationsByAdminLevels(locations, null); + + Assert.assertEquals(5, filteredLocations.size()); + Assert.assertEquals("0", filteredLocations.get(0).getId()); + Assert.assertEquals("1", filteredLocations.get(1).getId()); + Assert.assertEquals("2", filteredLocations.get(2).getId()); + Assert.assertEquals("3", filteredLocations.get(3).getId()); + Assert.assertEquals("4", filteredLocations.get(4).getId()); + } + private Bundle getLocationBundle() { Bundle bundleLocation = new Bundle(); bundleLocation.setId("Location/1234"); diff --git a/pom.xml b/pom.xml index c2a3ac3..871b1cd 100755 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.4 + 2.0.5 pom