From 7efff8414d67acf1361ab5777164584bd541e480 Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Wed, 14 Aug 2024 21:52:08 +0300 Subject: [PATCH 01/10] Location Hierarchies Processing Optimization --- .../LocationHierarchyEndpointHelper.java | 38 +++++++++++-------- .../PractitionerDetailsEndpointHelper.java | 21 +++++----- 2 files changed, 33 insertions(+), 26 deletions(-) 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 24c1f9fc..e343273f 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 @@ -81,12 +81,12 @@ public List getLocationHierarchies( List locationIds, List preFetchAdminLevels, List postFetchAdminLevels) { - List locationHierarchies = new ArrayList<>(); - for (String locationId : locationIds) { - locationHierarchies.add( - getLocationHierarchy(locationId, preFetchAdminLevels, postFetchAdminLevels)); - } - return locationHierarchies; + return locationIds.parallelStream() + .map( + locationId -> + getLocationHierarchy( + locationId, preFetchAdminLevels, postFetchAdminLevels)) + .collect(Collectors.toList()); } public LocationHierarchy getLocationHierarchyCore( @@ -98,7 +98,7 @@ public LocationHierarchy getLocationHierarchyCore( LocationHierarchyTree locationHierarchyTree = new LocationHierarchyTree(); LocationHierarchy locationHierarchy = new LocationHierarchy(); if (location != null) { - logger.info("Building Location Hierarchy of Location Id : " + locationId); + logger.info("Building Location Hierarchy of Location Id : {}", locationId); locationHierarchyTree.buildTreeFromList( filterLocationsByAdminLevels( @@ -110,7 +110,7 @@ public LocationHierarchy getLocationHierarchyCore( locationHierarchy.setLocationHierarchyTree(locationHierarchyTree); } else { - logger.error("LocationHierarchy with identifier: " + locationId + " not found"); + logger.error("LocationHierarchy with identifier: {} not found", locationId); locationHierarchy.setId(LOCATION_RESOURCE_NOT_FOUND); } return locationHierarchy; @@ -160,19 +160,25 @@ public List getDescendants( Bundle childLocationBundle = query.usingStyle(SearchStyleEnum.POST).returnBundle(Bundle.class).execute(); - List allLocations = new ArrayList<>(); + List allLocations = Collections.synchronizedList(new ArrayList<>()); if (parentLocation != null) { allLocations.add(parentLocation); } if (childLocationBundle != null) { - for (Bundle.BundleEntryComponent childLocation : childLocationBundle.getEntry()) { - Location childLocationEntity = (Location) childLocation.getResource(); - allLocations.add(childLocationEntity); - allLocations.addAll( - getDescendants( - childLocationEntity.getIdElement().getIdPart(), null, adminLevels)); - } + + childLocationBundle.getEntry().parallelStream() + .forEach( + childLocation -> { + Location childLocationEntity = + (Location) childLocation.getResource(); + allLocations.add(childLocationEntity); + allLocations.addAll( + getDescendants( + childLocationEntity.getIdElement().getIdPart(), + null, + adminLevels)); + }); } return allLocations; diff --git a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelper.java b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelper.java index 7b7a00ab..e36397c0 100755 --- a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelper.java +++ b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelper.java @@ -569,18 +569,19 @@ private List mapBundleToOrganizationAffiliation( } public static List getLocationsHierarchy(List locationsIdentifiers) { - List locationHierarchyList = new ArrayList<>(); LocationHierarchyEndpointHelper locationHierarchyEndpointHelper = new LocationHierarchyEndpointHelper(r4FHIRClient); - LocationHierarchy locationHierarchy; - for (String locationsIdentifier : locationsIdentifiers) { - locationHierarchy = - locationHierarchyEndpointHelper.getLocationHierarchy( - locationsIdentifier, null, null); - if (!org.smartregister.utils.Constants.LOCATION_RESOURCE_NOT_FOUND.equals( - locationHierarchy.getId())) locationHierarchyList.add(locationHierarchy); - } - return locationHierarchyList; + + return locationsIdentifiers.parallelStream() + .map( + locationsIdentifier -> + locationHierarchyEndpointHelper.getLocationHierarchy( + locationsIdentifier, null, null)) + .filter( + locationHierarchy -> + !org.smartregister.utils.Constants.LOCATION_RESOURCE_NOT_FOUND + .equals(locationHierarchy.getId())) + .collect(Collectors.toList()); } public static String createSearchTagValues(Map.Entry entry) { From e92c0080f041c37d740f7c29e889041f3d4c1809 Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Thu, 15 Aug 2024 22:41:06 +0300 Subject: [PATCH 02/10] Optimize FHIR Server requests - Remove duplicate parameters --- .../gateway/plugins/PermissionAccessChecker.java | 13 +++++++------ .../plugins/PractitionerDetailsEndpointHelper.java | 10 +++++----- .../PractitionerDetailsEndpointHelperTest.java | 5 +++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PermissionAccessChecker.java b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PermissionAccessChecker.java index 3c1d73b8..16a0b1a2 100755 --- a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PermissionAccessChecker.java +++ b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PermissionAccessChecker.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -287,7 +288,7 @@ private Map> collateSyncStrategyIds( PractitionerDetails practitionerDetails, RequestDetailsReader requestDetailsReader) { Map> resultMap; - List syncStrategyIds; + Set syncStrategyIds; if (StringUtils.isNotBlank(syncStrategy)) { if (Constants.SyncStrategy.CARE_TEAM.equalsIgnoreCase(syncStrategy)) { @@ -301,7 +302,7 @@ private Map> collateSyncStrategyIds( careTeams.stream() .filter(careTeam -> careTeam.getIdElement() != null) .map(careTeam -> careTeam.getIdElement().getIdPart()) - .collect(Collectors.toList()); + .collect(Collectors.toSet()); } else if (Constants.SyncStrategy.ORGANIZATION.equalsIgnoreCase(syncStrategy)) { List organizations = @@ -316,7 +317,7 @@ private Map> collateSyncStrategyIds( organizations.stream() .filter(organization -> organization.getIdElement() != null) .map(organization -> organization.getIdElement().getIdPart()) - .collect(Collectors.toList()); + .collect(Collectors.toSet()); } else if (Constants.SyncStrategy.LOCATION.equalsIgnoreCase(syncStrategy)) { syncStrategyIds = @@ -326,7 +327,7 @@ private Map> collateSyncStrategyIds( practitionerDetails .getFhirPractitionerDetails() .getLocationHierarchyList()) - : new ArrayList<>(); + : new HashSet<>(); } else if (Constants.SyncStrategy.RELATED_ENTITY_LOCATION.equalsIgnoreCase( syncStrategy)) { @@ -355,14 +356,14 @@ private Map> collateSyncStrategyIds( practitionerDetails .getFhirPractitionerDetails() .getLocationHierarchyList()) - : new ArrayList<>(); + : new HashSet<>(); } } else throw new IllegalStateException( "'" + syncStrategy + "' sync strategy NOT supported!!"); - resultMap = Map.of(syncStrategy, syncStrategyIds); + resultMap = Map.of(syncStrategy, new ArrayList<>(syncStrategyIds)); } else throw new IllegalStateException( diff --git a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelper.java b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelper.java index e36397c0..85dc80a1 100755 --- a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelper.java +++ b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelper.java @@ -108,7 +108,7 @@ private Bundle getAttributedPractitionerDetailsByPractitioner(Practitioner pract List locationHierarchies = getLocationsHierarchy(supervisorCareTeamOrganizationLocationIds); - List attributedLocationsList = getAttributedLocations(locationHierarchies); + Set attributedLocationsList = getAttributedLocations(locationHierarchies); List attributedOrganizationIds = getOrganizationIdsByLocationIds(attributedLocationsList); @@ -158,7 +158,7 @@ private Bundle getAttributedPractitionerDetailsByPractitioner(Practitioner pract } @NotNull - public static List getAttributedLocations(List locationHierarchies) { + public static Set getAttributedLocations(List locationHierarchies) { List parentChildrenList = locationHierarchies.stream() .flatMap( @@ -186,10 +186,10 @@ public static List getAttributedLocations(List locati .map( locationHierarchy -> locationHierarchy.getLocationId().getValue())) - .collect(Collectors.toList()); + .collect(Collectors.toSet()); } - private List getOrganizationIdsByLocationIds(List attributedLocationsList) { + private List getOrganizationIdsByLocationIds(Set attributedLocationsList) { if (attributedLocationsList == null || attributedLocationsList.isEmpty()) { return new ArrayList<>(); } @@ -371,7 +371,7 @@ private List getPractitionerRolesByPractitionerId(String pract private Set getOrganizationIdsByPractitionerRoles( List practitionerRoles) { return practitionerRoles.stream() - .filter(practitionerRole -> practitionerRole.hasOrganization()) + .filter(PractitionerRole::hasOrganization) .map(it -> getReferenceIDPart(it.getOrganization().getReference())) .collect(Collectors.toSet()); } diff --git a/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelperTest.java b/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelperTest.java index 487ace04..4da93052 100644 --- a/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelperTest.java +++ b/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/PractitionerDetailsEndpointHelperTest.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Set; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Identifier; @@ -110,12 +111,12 @@ public void testGetAttributedLocationsWithNoParentChildrenReturnsLocationId() { (LocationHierarchy) parser.parseResource(locationHierarchyNoParentChildren); List hierarchies = Arrays.asList(locationHierarchy); - List attributedLocationIds = + Set attributedLocationIds = PractitionerDetailsEndpointHelper.getAttributedLocations(hierarchies); Assert.assertNotNull(attributedLocationIds); Assert.assertFalse(attributedLocationIds.isEmpty()); Assert.assertEquals(1, attributedLocationIds.size()); - Assert.assertEquals("12345", attributedLocationIds.get(0)); + Assert.assertEquals("12345", attributedLocationIds.iterator().next()); } private Bundle getPractitionerBundle() { From 1dd271301212f857032076504e5fb52ead6d131b Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Fri, 16 Aug 2024 09:39:03 +0300 Subject: [PATCH 03/10] Refactor REL request | Fix large request URI issue - Chunk search by REL sync location request parameters --- exec/pom.xml | 4 +- plugins/pom.xml | 2 +- .../fhir/gateway/plugins/Constants.java | 2 +- .../LocationHierarchyEndpointHelper.java | 2 +- .../plugins/PermissionAccessChecker.java | 2 +- .../gateway/plugins/SyncAccessDecision.java | 114 +++++++++++++++++- .../LocationHierarchyEndpointHelperTest.java | 6 +- .../plugins/SyncAccessDecisionTest.java | 2 +- pom.xml | 2 +- 9 files changed, 123 insertions(+), 13 deletions(-) diff --git a/exec/pom.xml b/exec/pom.xml index c4293e40..17bf1397 100755 --- a/exec/pom.xml +++ b/exec/pom.xml @@ -4,7 +4,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.5 + 2.0.6-rc1 exec @@ -70,7 +70,7 @@ org.smartregister plugins - 2.0.5 + 2.0.6-rc1 diff --git a/plugins/pom.xml b/plugins/pom.xml index e17ccd61..e590c6eb 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -4,7 +4,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.5 + 2.0.6-rc1 plugins diff --git a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/Constants.java b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/Constants.java index ee9cccc2..6d075942 100644 --- a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/Constants.java +++ b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/Constants.java @@ -29,7 +29,7 @@ public class Constants { public static final String PAGINATION_PAGE_NUMBER = "_page"; public static final int PAGINATION_DEFAULT_PAGE_SIZE = 20; public static final int PAGINATION_DEFAULT_PAGE_NUMBER = 1; - public static final String SYNC_LOCATIONS = "_syncLocations"; + public static final String SYNC_LOCATIONS_SEARCH_PARAM = "_syncLocations"; public static final String RELATED_ENTITY_TAG_URL_ENV = "RELATED_ENTITY_TAG_URL"; public static final String DEFAULT_RELATED_ENTITY_TAG_URL = "https://smartregister.org/related-entity-location-tag-id"; 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 e343273f..a97787f7 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 @@ -220,7 +220,7 @@ public Bundle handleNonIdentifierRequest( PractitionerDetailsEndpointHelper practitionerDetailsEndpointHelper, DecodedJWT verifiedJwt) { String mode = request.getParameter(Constants.MODE); - String syncLocationsParam = request.getParameter(Constants.SYNC_LOCATIONS); + String syncLocationsParam = request.getParameter(Constants.SYNC_LOCATIONS_SEARCH_PARAM); String administrativeLevelMin = request.getParameter(Constants.MIN_ADMIN_LEVEL); String administrativeLevelMax = request.getParameter(Constants.MAX_ADMIN_LEVEL); List preFetchAdminLevels = diff --git a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PermissionAccessChecker.java b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PermissionAccessChecker.java index 16a0b1a2..3fc62418 100755 --- a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PermissionAccessChecker.java +++ b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/PermissionAccessChecker.java @@ -334,7 +334,7 @@ private Map> collateSyncStrategyIds( Map parameters = new HashMap<>(requestDetailsReader.getParameters()); - String[] syncLocations = parameters.get(Constants.SYNC_LOCATIONS); + String[] syncLocations = parameters.get(Constants.SYNC_LOCATIONS_SEARCH_PARAM); if (this.userRoles.contains(Constants.ROLE_ALL_LOCATIONS) && syncLocations != null) { diff --git a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java index 2f00df25..eb32eac7 100755 --- a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java +++ b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java @@ -49,7 +49,7 @@ public class SyncAccessDecision implements AccessDecision { private static final Logger logger = LoggerFactory.getLogger(SyncAccessDecision.class); private final String syncStrategy; private final boolean accessGranted; - private Map> syncStrategyIdsMap; + private final Map> syncStrategyIdsMap; private final List roles; private IgnoredResourcesConfig config; private final String keycloakUUID; @@ -57,6 +57,7 @@ public class SyncAccessDecision implements AccessDecision { private FhirContext fhirR4Context; private final IParser fhirR4JsonParser; private IGenericClient fhirR4Client; + private static final int REL_LOCATION_CHUNKSIZE = 20; private final PractitionerDetailsEndpointHelper practitionerDetailsEndpointHelper; @@ -120,8 +121,26 @@ public RequestMutation getRequestMutation(RequestDetailsReader requestDetailsRea forbiddenOperationException.getMessage(), forbiddenOperationException); } - List syncFilterParameterValues = - addSyncFilters(getSyncTags(this.syncStrategy, this.syncStrategyIdsMap)); + + List syncFilterParameterValues; + if (Constants.SyncStrategy.RELATED_ENTITY_LOCATION.equals(syncStrategy)) { + List syncStrategyIdSubList = + this.syncStrategyIdsMap + .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) + .subList(0, REL_LOCATION_CHUNKSIZE); + + syncFilterParameterValues = + addSyncFilters( + getSyncTags( + this.syncStrategy, + Map.of( + Constants.SyncStrategy.RELATED_ENTITY_LOCATION, + syncStrategyIdSubList))); + } else { + syncFilterParameterValues = + addSyncFilters(getSyncTags(this.syncStrategy, this.syncStrategyIdsMap)); + } + requestMutation = RequestMutation.builder() .queryParams( @@ -212,6 +231,75 @@ public String postProcess(RequestDetailsReader request, HttpResponse response) resultContent = this.fhirR4JsonParser.encodeResourceToString(resultContentBundle); } + if (Constants.SyncStrategy.RELATED_ENTITY_LOCATION.equals(syncStrategy)) { + + fhirR4Client + .getFhirContext() + .getRestfulClientFactory() + .setConnectionRequestTimeout(300000); + fhirR4Client.getFhirContext().getRestfulClientFactory().setSocketTimeout(300000); + + int subListSize = 100; + List allResults = new ArrayList<>(); + + String requestPath = + request.getRequestPath() + + "?" + + getRequestParametersString(request.getParameters()); + + for (int startIndex = REL_LOCATION_CHUNKSIZE; + startIndex + < syncStrategyIdsMap + .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) + .size(); + startIndex += subListSize) { + + int endIndex = + Math.min( + startIndex + subListSize, + syncStrategyIdsMap + .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) + .size()); + + List entries = + syncStrategyIdsMap + .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) + .subList(startIndex, endIndex); + + Bundle requestBundle = new Bundle(); + requestBundle.setType(Bundle.BundleType.BATCH); + for (String entry : entries) { + requestBundle.addEntry( + createBundleEntryComponent( + Bundle.HTTPVerb.GET, + requestPath + + "&_tag=" + + Constants.DEFAULT_RELATED_ENTITY_TAG_URL + + "%7C" + + entry, + null)); + } + + Bundle res = fhirR4Client.transaction().withBundle(requestBundle).execute(); + + List sub = + res.getEntry().parallelStream() + .map(it -> (Bundle) it.getResource()) + .flatMap(it -> it.getEntry().stream()) + .collect(Collectors.toList()); + + allResults.addAll(sub); + } + + resultContent = new BasicResponseHandler().handleResponse(response); + + Bundle responseResource = (Bundle) this.fhirR4JsonParser.parseResource(resultContent); + responseResource.getEntry().addAll(allResults); + responseResource.setTotal(allResults.size()); + + return this.fhirR4JsonParser.encodeResourceToString(responseResource); + } + if (includeAttributedPractitioners(request.getRequestPath())) { Bundle practitionerDetailsBundle = this.practitionerDetailsEndpointHelper @@ -222,6 +310,26 @@ public String postProcess(RequestDetailsReader request, HttpResponse response) return resultContent; } + private String getRequestParametersString(Map parameters) { + + StringBuilder queryString = new StringBuilder(); + + for (Map.Entry entry : parameters.entrySet()) { + String key = entry.getKey(); + String[] values = entry.getValue(); + + if (!Constants.SYNC_LOCATIONS_SEARCH_PARAM.equals(key) + && !Constants.TAG_SEARCH_PARAM.equals(key)) { + + for (String value : values) { + queryString.append(key).append("=").append(value).append("&"); + } + } + } + + return queryString.toString(); + } + private boolean includeAttributedPractitioners(String requestPath) { return Constants.SyncStrategy.LOCATION.equalsIgnoreCase(syncStrategy) && roles.contains(SyncAccessDecisionConstants.ROLE_SUPERVISOR) 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 62a14c59..92d9e44a 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 @@ -141,7 +141,9 @@ public void testExtractSyncLocations() { public void testHandleNonIdentifierRequestListModePaginatesLocations() { HttpServletRequest request = mock(HttpServletRequest.class); Mockito.doReturn("list").when(request).getParameter(Constants.MODE); - Mockito.doReturn("1,2,3,4").when(request).getParameter(Constants.SYNC_LOCATIONS); + Mockito.doReturn("1,2,3,4") + .when(request) + .getParameter(Constants.SYNC_LOCATIONS_SEARCH_PARAM); Mockito.doReturn(new StringBuffer("http://test:8080/LocationHierarchy")) .when(request) .getRequestURL(); @@ -149,7 +151,7 @@ public void testHandleNonIdentifierRequestListModePaginatesLocations() { Map parameters = new HashMap<>(); parameters.put(Constants.MODE, new String[] {"list"}); - parameters.put(Constants.SYNC_LOCATIONS, new String[] {"1,2,3,4"}); + parameters.put(Constants.SYNC_LOCATIONS_SEARCH_PARAM, new String[] {"1,2,3,4"}); LocationHierarchyEndpointHelper mockLocationHierarchyEndpointHelper = mock(LocationHierarchyEndpointHelper.class); PractitionerDetailsEndpointHelper mockPractitionerDetailsEndpointHelper = diff --git a/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecisionTest.java b/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecisionTest.java index 762ad3c8..deaa2ac5 100755 --- a/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecisionTest.java +++ b/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecisionTest.java @@ -315,7 +315,7 @@ public void requestMutationWhenLocationUuidAreEmptyShouldNotError() throws IOExc Map parameters = new HashMap<>(); // empty string - parameters.put(Constants.SYNC_LOCATIONS, locations); + parameters.put(Constants.SYNC_LOCATIONS_SEARCH_PARAM, locations); RequestDetails requestDetails = new ServletRequestDetails(); requestDetails.setRequestType(RequestTypeEnum.GET); diff --git a/pom.xml b/pom.xml index 871b1cdb..44af53d3 100755 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.5 + 2.0.6-rc1 pom From bc500af49157f50fce2f629d4530ca84a4727c48 Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Fri, 16 Aug 2024 16:08:58 +0300 Subject: [PATCH 04/10] =?UTF-8?q?Fix=20bugs=20=F0=9F=90=9B=F0=9F=90=9B?= =?UTF-8?q?=F0=9F=90=9B=20-=20Out=20of=20bound=20exception=20on=20REL=20re?= =?UTF-8?q?quests=20-=20Fix=20REL=20resource=20GET=20by=20id=20request=20-?= =?UTF-8?q?=20Return=20correct=20bundle=20SELF=20LINK=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exec/pom.xml | 4 +-- plugins/pom.xml | 2 +- .../gateway/plugins/SyncAccessDecision.java | 26 ++++++++++++++++--- pom.xml | 2 +- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/exec/pom.xml b/exec/pom.xml index 17bf1397..211adee2 100755 --- a/exec/pom.xml +++ b/exec/pom.xml @@ -4,7 +4,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.6-rc1 + 2.0.6-rc2 exec @@ -70,7 +70,7 @@ org.smartregister plugins - 2.0.6-rc1 + 2.0.6-rc2 diff --git a/plugins/pom.xml b/plugins/pom.xml index e590c6eb..c83ab703 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -4,7 +4,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.6-rc1 + 2.0.6-rc2 plugins diff --git a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java index eb32eac7..017b2e24 100755 --- a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java +++ b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -124,10 +125,18 @@ public RequestMutation getRequestMutation(RequestDetailsReader requestDetailsRea List syncFilterParameterValues; if (Constants.SyncStrategy.RELATED_ENTITY_LOCATION.equals(syncStrategy)) { + + int endIndex = + Math.min( + REL_LOCATION_CHUNKSIZE, + syncStrategyIdsMap + .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) + .size()); + List syncStrategyIdSubList = this.syncStrategyIdsMap .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) - .subList(0, REL_LOCATION_CHUNKSIZE); + .subList(0, endIndex); syncFilterParameterValues = addSyncFilters( @@ -293,9 +302,18 @@ public String postProcess(RequestDetailsReader request, HttpResponse response) resultContent = new BasicResponseHandler().handleResponse(response); - Bundle responseResource = (Bundle) this.fhirR4JsonParser.parseResource(resultContent); - responseResource.getEntry().addAll(allResults); - responseResource.setTotal(allResults.size()); + IBaseResource responseResource = this.fhirR4JsonParser.parseResource(resultContent); + + if (responseResource instanceof Bundle) { + ((Bundle) responseResource).getEntry().addAll(allResults); + ((Bundle) responseResource).setTotal(((Bundle) responseResource).getEntry().size()); + + Bundle.BundleLinkComponent selfLinkComponent = new Bundle.BundleLinkComponent(); + selfLinkComponent.setRelation(Bundle.LINK_SELF); + selfLinkComponent.setUrl(request.getCompleteUrl()); + + ((Bundle) responseResource).setLink(Collections.singletonList(selfLinkComponent)); + } return this.fhirR4JsonParser.encodeResourceToString(responseResource); } diff --git a/pom.xml b/pom.xml index 44af53d3..b3fea7a5 100755 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.6-rc1 + 2.0.6-rc2 pom From 9f59e4a4bc1da691f9dcaa1b1151b573c0d16e91 Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Tue, 20 Aug 2024 15:43:43 +0300 Subject: [PATCH 05/10] Fix List entries request fails when REL and Gatewaymode both specified --- exec/pom.xml | 4 +- plugins/pom.xml | 2 +- .../gateway/plugins/SyncAccessDecision.java | 169 +++++++++--------- pom.xml | 2 +- 4 files changed, 88 insertions(+), 89 deletions(-) diff --git a/exec/pom.xml b/exec/pom.xml index 211adee2..f079526c 100755 --- a/exec/pom.xml +++ b/exec/pom.xml @@ -4,7 +4,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.6-rc2 + 2.0.6-rc3 exec @@ -70,7 +70,7 @@ org.smartregister plugins - 2.0.6-rc2 + 2.0.6-rc3 diff --git a/plugins/pom.xml b/plugins/pom.xml index c83ab703..829258fc 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -4,7 +4,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.6-rc2 + 2.0.6-rc3 plugins diff --git a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java index 017b2e24..83c116d7 100755 --- a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java +++ b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java @@ -220,112 +220,111 @@ public String postProcess(RequestDetailsReader request, HttpResponse response) resultContent = new BasicResponseHandler().handleResponse(response); IBaseResource responseResource = this.fhirR4JsonParser.parseResource(resultContent); - switch (gatewayMode) { - case SyncAccessDecisionConstants.LIST_ENTRIES: - resultContentBundle = postProcessModeListEntries(responseResource, request); - break; - - default: - String exceptionMessage = - "The FHIR Gateway Mode header is configured with an un-recognized value" - + " of \'" - + gatewayMode - + '\''; - OperationOutcome operationOutcome = createOperationOutcome(exceptionMessage); - - resultContentBundle = operationOutcome; + if (gatewayMode.equals(SyncAccessDecisionConstants.LIST_ENTRIES)) { + resultContentBundle = postProcessModeListEntries(responseResource, request); + } else { + String exceptionMessage = + "The FHIR Gateway Mode header is configured with an un-recognized value" + + " of \'" + + gatewayMode + + '\''; + OperationOutcome operationOutcome = createOperationOutcome(exceptionMessage); + + resultContentBundle = operationOutcome; } - if (resultContentBundle != null) - resultContent = this.fhirR4JsonParser.encodeResourceToString(resultContentBundle); - } + resultContent = this.fhirR4JsonParser.encodeResourceToString(resultContentBundle); - if (Constants.SyncStrategy.RELATED_ENTITY_LOCATION.equals(syncStrategy)) { + } else if (Constants.SyncStrategy.RELATED_ENTITY_LOCATION.equals(syncStrategy)) { - fhirR4Client - .getFhirContext() - .getRestfulClientFactory() - .setConnectionRequestTimeout(300000); - fhirR4Client.getFhirContext().getRestfulClientFactory().setSocketTimeout(300000); + IBaseResource responseResource = + processRelatedEntityLocationSyncStrategy(request, response); - int subListSize = 100; - List allResults = new ArrayList<>(); + resultContent = this.fhirR4JsonParser.encodeResourceToString(responseResource); - String requestPath = - request.getRequestPath() - + "?" - + getRequestParametersString(request.getParameters()); + } else if (includeAttributedPractitioners(request.getRequestPath())) { + Bundle practitionerDetailsBundle = + this.practitionerDetailsEndpointHelper + .getSupervisorPractitionerDetailsByKeycloakId(keycloakUUID); + resultContent = this.fhirR4JsonParser.encodeResourceToString(practitionerDetailsBundle); + } - for (int startIndex = REL_LOCATION_CHUNKSIZE; - startIndex - < syncStrategyIdsMap - .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) - .size(); - startIndex += subListSize) { + return resultContent; + } - int endIndex = - Math.min( - startIndex + subListSize, - syncStrategyIdsMap - .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) - .size()); + private IBaseResource processRelatedEntityLocationSyncStrategy( + RequestDetailsReader request, HttpResponse response) throws IOException { + String resultContent; + fhirR4Client.getFhirContext().getRestfulClientFactory().setConnectionRequestTimeout(300000); + fhirR4Client.getFhirContext().getRestfulClientFactory().setSocketTimeout(300000); - List entries = - syncStrategyIdsMap - .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) - .subList(startIndex, endIndex); - - Bundle requestBundle = new Bundle(); - requestBundle.setType(Bundle.BundleType.BATCH); - for (String entry : entries) { - requestBundle.addEntry( - createBundleEntryComponent( - Bundle.HTTPVerb.GET, - requestPath - + "&_tag=" - + Constants.DEFAULT_RELATED_ENTITY_TAG_URL - + "%7C" - + entry, - null)); - } + int subListSize = 100; + List allResults = new ArrayList<>(); - Bundle res = fhirR4Client.transaction().withBundle(requestBundle).execute(); + String requestPath = + request.getRequestPath() + + "?" + + getRequestParametersString(request.getParameters()); - List sub = - res.getEntry().parallelStream() - .map(it -> (Bundle) it.getResource()) - .flatMap(it -> it.getEntry().stream()) - .collect(Collectors.toList()); + for (int startIndex = REL_LOCATION_CHUNKSIZE; + startIndex + < syncStrategyIdsMap + .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) + .size(); + startIndex += subListSize) { - allResults.addAll(sub); + int endIndex = + Math.min( + startIndex + subListSize, + syncStrategyIdsMap + .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) + .size()); + + List entries = + syncStrategyIdsMap + .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) + .subList(startIndex, endIndex); + + Bundle requestBundle = new Bundle(); + requestBundle.setType(Bundle.BundleType.BATCH); + for (String entry : entries) { + requestBundle.addEntry( + createBundleEntryComponent( + Bundle.HTTPVerb.GET, + requestPath + + "&_tag=" + + Constants.DEFAULT_RELATED_ENTITY_TAG_URL + + "%7C" + + entry, + null)); } - resultContent = new BasicResponseHandler().handleResponse(response); + Bundle res = fhirR4Client.transaction().withBundle(requestBundle).execute(); - IBaseResource responseResource = this.fhirR4JsonParser.parseResource(resultContent); + List sub = + res.getEntry().parallelStream() + .map(it -> (Bundle) it.getResource()) + .flatMap(it -> it.getEntry().stream()) + .collect(Collectors.toList()); - if (responseResource instanceof Bundle) { - ((Bundle) responseResource).getEntry().addAll(allResults); - ((Bundle) responseResource).setTotal(((Bundle) responseResource).getEntry().size()); + allResults.addAll(sub); + } - Bundle.BundleLinkComponent selfLinkComponent = new Bundle.BundleLinkComponent(); - selfLinkComponent.setRelation(Bundle.LINK_SELF); - selfLinkComponent.setUrl(request.getCompleteUrl()); + resultContent = new BasicResponseHandler().handleResponse(response); - ((Bundle) responseResource).setLink(Collections.singletonList(selfLinkComponent)); - } + IBaseResource responseResource = this.fhirR4JsonParser.parseResource(resultContent); - return this.fhirR4JsonParser.encodeResourceToString(responseResource); - } + if (responseResource instanceof Bundle) { + ((Bundle) responseResource).getEntry().addAll(allResults); + ((Bundle) responseResource).setTotal(((Bundle) responseResource).getEntry().size()); - if (includeAttributedPractitioners(request.getRequestPath())) { - Bundle practitionerDetailsBundle = - this.practitionerDetailsEndpointHelper - .getSupervisorPractitionerDetailsByKeycloakId(keycloakUUID); - resultContent = this.fhirR4JsonParser.encodeResourceToString(practitionerDetailsBundle); - } + Bundle.BundleLinkComponent selfLinkComponent = new Bundle.BundleLinkComponent(); + selfLinkComponent.setRelation(Bundle.LINK_SELF); + selfLinkComponent.setUrl(request.getCompleteUrl()); - return resultContent; + ((Bundle) responseResource).setLink(Collections.singletonList(selfLinkComponent)); + } + return responseResource; } private String getRequestParametersString(Map parameters) { diff --git a/pom.xml b/pom.xml index b3fea7a5..57c6df2e 100755 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.6-rc2 + 2.0.6-rc3 pom From f195a30b17ea989c7c1208478ae1f2f86378dfc0 Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Tue, 20 Aug 2024 18:07:02 +0300 Subject: [PATCH 06/10] =?UTF-8?q?Fix=20build=20=F0=9F=92=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway/plugins/SyncAccessDecision.java | 3 +- .../plugins/SyncAccessDecisionTest.java | 58 ++++++++++++------- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java index 83c116d7..d364a0d3 100755 --- a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java +++ b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java @@ -228,9 +228,8 @@ public String postProcess(RequestDetailsReader request, HttpResponse response) + " of \'" + gatewayMode + '\''; - OperationOutcome operationOutcome = createOperationOutcome(exceptionMessage); - resultContentBundle = operationOutcome; + resultContentBundle = createOperationOutcome(exceptionMessage); } resultContent = this.fhirR4JsonParser.encodeResourceToString(resultContentBundle); diff --git a/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecisionTest.java b/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecisionTest.java index deaa2ac5..244c337d 100755 --- a/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecisionTest.java +++ b/plugins/src/test/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecisionTest.java @@ -8,9 +8,13 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpResponse; @@ -44,15 +48,15 @@ @RunWith(MockitoJUnitRunner.class) public class SyncAccessDecisionTest { - private List locationIds = new ArrayList<>(); + private final List locationIds = new ArrayList<>(); - private List careTeamIds = new ArrayList<>(); + private final List careTeamIds = new ArrayList<>(); - private List organisationIds = new ArrayList<>(); + private final List organisationIds = new ArrayList<>(); - private List userRoles = new ArrayList<>(); + private final List userRoles = new ArrayList<>(); - private List relatedEntityLocationIds = new ArrayList<>(); + private final List relatedEntityLocationIds = new ArrayList<>(); private SyncAccessDecision testInstance; @@ -199,7 +203,7 @@ public void preProcessWhenNotOneClientRoleIsAddedShouldThrowError() throws IOExc try (MockedStatic mockPractitionerDetailsEndpointHelper = Mockito.mockStatic(PractitionerDetailsEndpointHelper.class)) { userRoles.add(Constants.ROLE_ANDROID_CLIENT); - List selectedRelatedEntityLocationIds = new ArrayList<>(); + Set selectedRelatedEntityLocationIds = new HashSet<>(); String srelocationid1 = "srelocationid1"; String srelocationid2 = "srelocationid2"; @@ -240,17 +244,23 @@ public void preProcessWhenNotOneClientRoleIsAddedShouldThrowError() throws IOExc RequestMutation mutatedRequest = testInstance.getRequestMutation(new TestRequestDetailsToReader(requestDetails)); - Assert.assertTrue( - mutatedRequest - .getQueryParams() - .get(Constants.TAG_SEARCH_PARAM) - .get(0) - .contains( - StringUtils.join( - selectedRelatedEntityLocationIds, - Constants.PARAM_VALUES_SEPARATOR - + Constants.DEFAULT_RELATED_ENTITY_TAG_URL - + Constants.CODE_URL_VALUE_SEPARATOR))); + List list = new ArrayList<>(selectedRelatedEntityLocationIds); + Collections.reverse(list); + + String expected = ""; + for (String item : list) { + expected += + Constants.DEFAULT_RELATED_ENTITY_TAG_URL + + Constants.CODE_URL_VALUE_SEPARATOR + + item + + Constants.PARAM_VALUES_SEPARATOR; + } + + Assert.assertEquals( + expected.substring(0, expected.length() - 1), + mutatedRequest.getQueryParams().get(Constants.TAG_SEARCH_PARAM).get(0)); + + Collections.reverse(relatedEntityLocationIds); Assert.assertFalse( mutatedRequest .getQueryParams() @@ -265,12 +275,19 @@ public void preProcessWhenNotOneClientRoleIsAddedShouldThrowError() throws IOExc } } + private String searchTagHelper(String tag, Set values) { + return values.stream() + .sorted(Collections.reverseOrder()) + .map(it -> tag + it) + .collect(Collectors.joining(",")); + } + @Test - public void requestMutationWhenLocationUuidAreEmptyShouldNotError() throws IOException { + public void requestMutationWhenLocationUuidAreEmptyShouldNotError() { try (MockedStatic mockPractitionerDetailsEndpointHelper = Mockito.mockStatic(PractitionerDetailsEndpointHelper.class)) { userRoles.add(Constants.ROLE_ANDROID_CLIENT); - List selectedRelatedEntityLocationIds = new ArrayList<>(); + Set selectedRelatedEntityLocationIds = new HashSet<>(); String srelocationid1 = ""; String srelocationid2 = " "; @@ -371,8 +388,7 @@ public void preProcessShouldAddCareTeamIdFiltersWhenUserIsAssignedToCareTeamsOnl } @Test - public void preProcessShouldAddOrganisationIdFiltersWhenUserIsAssignedToOrganisationsOnly() - throws IOException { + public void preProcessShouldAddOrganisationIdFiltersWhenUserIsAssignedToOrganisationsOnly() { userRoles.add(Constants.ROLE_ANDROID_CLIENT); organisationIds.add("organizationid1"); organisationIds.add("organizationid2"); From a885207c1cfd8c6f9d52e6d4bc666f9172279a1b Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Tue, 20 Aug 2024 18:42:20 +0300 Subject: [PATCH 07/10] Remove List Resource list-entries mode via Custom Query Params - Remove this since doesn't work on current server versions --- README.md | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/README.md b/README.md index ea9896fd..6acbd937 100755 --- a/README.md +++ b/README.md @@ -298,21 +298,7 @@ deprecated in favor of the `mode` query parameter. ### Custom Query Parameters -#### Mode - -##### List Resource - -When fetching `List` resources, the endpoint returns a list of references which -can then be used to query for the actual resources. With this query parameter -value configured the response is instead a Bundle that contains all the actual -(referenced) resources. To activate this mode, supply a `mode` query parameter -and give it a value of `list-entries` - -Example: - -``` -/List?mode=list-entries -``` +#### Mode #### Pagination From 1d76e30a13138079a91ccd5134a5acd49997c8e0 Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Wed, 21 Aug 2024 15:19:18 +0300 Subject: [PATCH 08/10] Add Github Release step to Docker Publish workflow --- .github/workflows/docker-publish.yml | 4 ++++ README.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index b6c0e549..c79eb88a 100755 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -91,3 +91,7 @@ jobs: - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} + + - name: Github Release + uses: softprops/action-gh-release@v2 + if: startsWith(github.ref, 'refs/tags/') diff --git a/README.md b/README.md index 6acbd937..59809712 100755 --- a/README.md +++ b/README.md @@ -298,7 +298,7 @@ deprecated in favor of the `mode` query parameter. ### Custom Query Parameters -#### Mode +#### Mode #### Pagination From 979018b4530d3564cdf7b282a8091364a2dae427 Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Wed, 21 Aug 2024 15:20:26 +0300 Subject: [PATCH 09/10] Release version 1.0.6 --- exec/pom.xml | 4 ++-- plugins/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/exec/pom.xml b/exec/pom.xml index f079526c..e2f16991 100755 --- a/exec/pom.xml +++ b/exec/pom.xml @@ -4,7 +4,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.6-rc3 + 2.0.6 exec @@ -70,7 +70,7 @@ org.smartregister plugins - 2.0.6-rc3 + 2.0.6 diff --git a/plugins/pom.xml b/plugins/pom.xml index 829258fc..ad685610 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -4,7 +4,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.6-rc3 + 2.0.6 plugins diff --git a/pom.xml b/pom.xml index 57c6df2e..0d301408 100755 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.smartregister opensrp-gateway-plugin - 2.0.6-rc3 + 2.0.6 pom From 9889c865ca683ba470ae214bd02f3ab8a78d2ddf Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Wed, 21 Aug 2024 17:08:09 +0300 Subject: [PATCH 10/10] Move Magic Numbers to Inner Constants file --- .../fhir/gateway/plugins/SyncAccessDecision.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java index d364a0d3..d4205ad9 100755 --- a/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java +++ b/plugins/src/main/java/org/smartregister/fhir/gateway/plugins/SyncAccessDecision.java @@ -58,7 +58,6 @@ public class SyncAccessDecision implements AccessDecision { private FhirContext fhirR4Context; private final IParser fhirR4JsonParser; private IGenericClient fhirR4Client; - private static final int REL_LOCATION_CHUNKSIZE = 20; private final PractitionerDetailsEndpointHelper practitionerDetailsEndpointHelper; @@ -128,7 +127,7 @@ public RequestMutation getRequestMutation(RequestDetailsReader requestDetailsRea int endIndex = Math.min( - REL_LOCATION_CHUNKSIZE, + SyncAccessDecisionConstants.REL_LOCATION_INITIAL_CHUNK_SIZE, syncStrategyIdsMap .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) .size()); @@ -257,7 +256,6 @@ private IBaseResource processRelatedEntityLocationSyncStrategy( fhirR4Client.getFhirContext().getRestfulClientFactory().setConnectionRequestTimeout(300000); fhirR4Client.getFhirContext().getRestfulClientFactory().setSocketTimeout(300000); - int subListSize = 100; List allResults = new ArrayList<>(); String requestPath = @@ -265,16 +263,16 @@ private IBaseResource processRelatedEntityLocationSyncStrategy( + "?" + getRequestParametersString(request.getParameters()); - for (int startIndex = REL_LOCATION_CHUNKSIZE; + for (int startIndex = SyncAccessDecisionConstants.REL_LOCATION_INITIAL_CHUNK_SIZE; startIndex < syncStrategyIdsMap .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) .size(); - startIndex += subListSize) { + startIndex += SyncAccessDecisionConstants.REL_LOCATION_CHUNK_SIZE) { int endIndex = Math.min( - startIndex + subListSize, + startIndex + SyncAccessDecisionConstants.REL_LOCATION_CHUNK_SIZE, syncStrategyIdsMap .get(Constants.SyncStrategy.RELATED_ENTITY_LOCATION) .size()); @@ -689,5 +687,9 @@ public static final class SyncAccessDecisionConstants { public static final String LIST_ENTRIES = "list-entries"; public static final String ROLE_SUPERVISOR = "SUPERVISOR"; public static final String ENDPOINT_PRACTITIONER_DETAILS = "PractitionerDetail"; + public static final int REL_LOCATION_CHUNK_SIZE = + 100; // Magic Number Alert - Do not change value for maximum stability + private static final int REL_LOCATION_INITIAL_CHUNK_SIZE = + 20; // Magic Number Alert - Do not change value for maximum stability } }