diff --git a/src/main/java/org/folio/circulationbff/service/impl/CirculationBffServiceImpl.java b/src/main/java/org/folio/circulationbff/service/impl/CirculationBffServiceImpl.java index 5dc6849..b74366e 100644 --- a/src/main/java/org/folio/circulationbff/service/impl/CirculationBffServiceImpl.java +++ b/src/main/java/org/folio/circulationbff/service/impl/CirculationBffServiceImpl.java @@ -52,39 +52,50 @@ public SearchSlipCollection fetchSearchSlipsByServicePointId(String servicePoint @Override public AllowedServicePoints getAllowedServicePoints(AllowedServicePointParams params, String tenantId) { log.info("getAllowedServicePoints:: params: {}", params); - if (settingsService.isEcsTlrFeatureEnabled()) { - if (userTenantsService.isCentralTenant()) { - log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled and we are in the central " + - "tenant. Calling local mod-tlr."); - return ecsTlrClient.getAllowedServicePoints(params); - } else { - if (params.getRequestId() == null) { - log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled, requestId param is " + - "missing. Calling local mod-circulation."); - return circulationClient.allowedServicePoints(params); - } else { - var request = circulationClient.getRequestById(params.getRequestId().toString()); - if (request.getEcsRequestPhase() == null) { - log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled, but request is not " + - "an ECS request. Calling local mod-circulation."); - return circulationClient.allowedServicePoints(params); - } else { - log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled and request is " + - "an ECS request. Calling central mod-tlr."); - String patronGroupId = params.getRequesterId() == null ? null : - userService.find(params.getRequesterId().toString()).getPatronGroup(); - params.setPatronGroupId(patronGroupId != null ? UUID.fromString(patronGroupId) : null); - params.setRequesterId(null); - return executionService.executeSystemUserScoped(userTenantsService.getCentralTenant(), - () -> ecsTlrClient.getAllowedServicePoints(params)); - } - } - } - } else { + + if (!settingsService.isEcsTlrFeatureEnabled()) { log.info("getAllowedServicePoints:: Ecs TLR Feature is disabled. " + "Calling local mod-circulation."); return circulationClient.allowedServicePoints(params); } + + if (userTenantsService.isCentralTenant()) { + log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled and we are in the central " + + "tenant. Calling local mod-tlr."); + return ecsTlrClient.getAllowedServicePoints(params); + } + + log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled and current tenant is not " + + "central."); + + if (params.getRequestId() == null) { + log.info("getAllowedServicePoints:: Request ID is missing (creation). Calling central mod-tlr."); + // This should handle both mediated request and local data tenant request cases. + // In case of a local request, central mod-tlr should call mod-circulation of the current + // data tenant anyway. + return getAllowedSpFromCentralTlr(params); + } + + log.info("getAllowedServicePoints:: Request ID is present (editing)."); + + var request = circulationClient.getRequestById(params.getRequestId().toString()); + if (request.getEcsRequestPhase() == null) { + log.info("getAllowedServicePoints:: Request is not an ECS request. Calling local mod-circulation."); + return circulationClient.allowedServicePoints(params); + } + + log.info("getAllowedServicePoints:: Ecs TLR Feature is enabled and request is " + + "an ECS request. Calling central mod-tlr."); + return getAllowedSpFromCentralTlr(params); + } + + private AllowedServicePoints getAllowedSpFromCentralTlr(AllowedServicePointParams params) { + String patronGroupId = params.getRequesterId() == null ? null : + userService.find(params.getRequesterId().toString()).getPatronGroup(); + params.setPatronGroupId(patronGroupId != null ? UUID.fromString(patronGroupId) : null); + params.setRequesterId(null); + return executionService.executeSystemUserScoped(userTenantsService.getCentralTenant(), + () -> ecsTlrClient.getAllowedServicePoints(params)); } @Override diff --git a/src/main/java/org/folio/circulationbff/service/impl/UserTenantsServiceImpl.java b/src/main/java/org/folio/circulationbff/service/impl/UserTenantsServiceImpl.java index 64472c7..2420659 100644 --- a/src/main/java/org/folio/circulationbff/service/impl/UserTenantsServiceImpl.java +++ b/src/main/java/org/folio/circulationbff/service/impl/UserTenantsServiceImpl.java @@ -70,13 +70,14 @@ public boolean isCentralTenant(String tenantId) { private UserTenant getFirstUserTenant() { log.info("getFirstUserTenant:: finding first userTenant"); UserTenantCollection userTenants = userTenantsClient.getUserTenants(1); - log.info("getFirstUserTenant:: userTenants: {}", () -> userTenants); + log.debug("getFirstUserTenant:: userTenants: {}", userTenants); if (userTenants == null || CollectionUtils.isEmpty(userTenants.getUserTenants())) { log.warn("getFirstUserTenant: failed to fetch user tenants"); return null; } var firstUserTenant = userTenants.getUserTenants().get(0); - log.info("getFirstUserTenant:: result: {}", firstUserTenant); + log.debug("getFirstUserTenant:: result: {}", + () -> firstUserTenant == null ? null : firstUserTenant.getId()); return firstUserTenant; } } diff --git a/src/test/java/org/folio/circulationbff/api/CirculationBffRequestsApiTest.java b/src/test/java/org/folio/circulationbff/api/CirculationBffRequestsApiTest.java index 54581db..1a9e4ec 100644 --- a/src/test/java/org/folio/circulationbff/api/CirculationBffRequestsApiTest.java +++ b/src/test/java/org/folio/circulationbff/api/CirculationBffRequestsApiTest.java @@ -152,8 +152,9 @@ void allowedSpCallsDataTenantCirculationWhenEcsTlrEnabledWithoutRequestId() { allowedSpResponseConsortium.setHold(Set.of( buildAllowedServicePoint("SP_consortium_1"), buildAllowedServicePoint("SP_consortium_2"))); - wireMockServer.stubFor(WireMock.get(urlPathEqualTo(CIRCULATION_ALLOWED_SERVICE_POINT_URL)) - .withHeader(HEADER_TENANT, equalTo(TENANT_ID_COLLEGE)) + + wireMockServer.stubFor(WireMock.get(urlPathEqualTo(TLR_ALLOWED_SERVICE_POINT_URL)) + .withHeader(HEADER_TENANT, equalTo(TENANT_ID_CONSORTIUM)) .willReturn(jsonResponse(asJsonString(allowedSpResponseConsortium), SC_OK))); var operation = "create"; @@ -174,7 +175,8 @@ void allowedSpCallsDataTenantCirculationWhenEcsTlrEnabledWithoutRequestId() { containsInAnyOrder("SP_consortium_1", "SP_consortium_2"))); wireMockServer.verify(getRequestedFor(urlPathEqualTo( - CIRCULATION_ALLOWED_SERVICE_POINT_URL)) + TLR_ALLOWED_SERVICE_POINT_URL)) + .withHeader(HEADER_TENANT, equalTo(TENANT_ID_CONSORTIUM)) .withQueryParam("instanceId", equalTo(instanceId.toString())) .withQueryParam("operation", equalTo(operation)) );