From a967e5e9f307b5b41300fabc6a83681c0f6bb50d Mon Sep 17 00:00:00 2001 From: Irakli Merabishvili Date: Mon, 27 Jan 2025 18:37:14 +0400 Subject: [PATCH] MCBFF-38: fix fetching service point by location id --- descriptors/ModuleDescriptor-template.json | 2 ++ .../circulationbff/service/InventoryService.java | 2 ++ .../service/impl/CheckInServiceImpl.java | 14 ++++++++------ .../service/impl/InventoryServiceImpl.java | 9 +++++++++ .../folio/circulationbff/api/CheckInApiTest.java | 15 +++++++++++++-- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index 1870a86..a2d403c 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -155,6 +155,8 @@ "search.instances.collection.get", "inventory-storage.items.item.get", "inventory-storage.items.collection.get", + "inventory-storage.locations.item.get", + "inventory-storage.locations.collection.get", "inventory-storage.service-points.item.get", "inventory-storage.service-points.collection.get" ] diff --git a/src/main/java/org/folio/circulationbff/service/InventoryService.java b/src/main/java/org/folio/circulationbff/service/InventoryService.java index 213c67d..38b32b6 100644 --- a/src/main/java/org/folio/circulationbff/service/InventoryService.java +++ b/src/main/java/org/folio/circulationbff/service/InventoryService.java @@ -1,9 +1,11 @@ package org.folio.circulationbff.service; import org.folio.circulationbff.domain.dto.Item; +import org.folio.circulationbff.domain.dto.Location; import org.folio.circulationbff.domain.dto.ServicePoint; public interface InventoryService { Item fetchItem(String id); + Location fetchLocation(String id); ServicePoint fetchServicePoint(String id); } diff --git a/src/main/java/org/folio/circulationbff/service/impl/CheckInServiceImpl.java b/src/main/java/org/folio/circulationbff/service/impl/CheckInServiceImpl.java index 43dac9f..16a1785 100644 --- a/src/main/java/org/folio/circulationbff/service/impl/CheckInServiceImpl.java +++ b/src/main/java/org/folio/circulationbff/service/impl/CheckInServiceImpl.java @@ -57,17 +57,19 @@ private String getEffectiveLocationServicePoint(String itemId) { if (Objects.equals(itemTenantId, userTenantsService.getCurrentTenant())) { log.info("getEffectiveLocationServicePoint: same tenant case {}", itemTenantId); var item = inventoryService.fetchItem(itemId); - var servicePoint = inventoryService.fetchServicePoint(item.getEffectiveLocationId()); + var location = inventoryService.fetchLocation(item.getEffectiveLocationId()); + var servicePoint = inventoryService.fetchServicePoint(location.getPrimaryServicePoint().toString()); return servicePoint.getName(); } else { log.info("getEffectiveLocationServicePoint: cross tenant case {}", itemTenantId); - var item = executionService.executeSystemUserScoped( - itemTenantId, + var item = executionService.executeSystemUserScoped(itemTenantId, () -> inventoryService.fetchItem(itemId) ); - var servicePoint = executionService.executeSystemUserScoped( - itemTenantId, - () -> inventoryService.fetchServicePoint(item.getEffectiveLocationId()) + var location = executionService.executeSystemUserScoped(itemTenantId, + () -> inventoryService.fetchLocation(item.getEffectiveLocationId()) + ); + var servicePoint = executionService.executeSystemUserScoped(itemTenantId, + () -> inventoryService.fetchServicePoint(location.getPrimaryServicePoint().toString()) ); return servicePoint.getName(); } diff --git a/src/main/java/org/folio/circulationbff/service/impl/InventoryServiceImpl.java b/src/main/java/org/folio/circulationbff/service/impl/InventoryServiceImpl.java index a5779a1..3b812c2 100644 --- a/src/main/java/org/folio/circulationbff/service/impl/InventoryServiceImpl.java +++ b/src/main/java/org/folio/circulationbff/service/impl/InventoryServiceImpl.java @@ -3,8 +3,10 @@ import lombok.RequiredArgsConstructor; import lombok.extern.log4j.Log4j2; import org.folio.circulationbff.client.feign.ItemStorageClient; +import org.folio.circulationbff.client.feign.LocationClient; import org.folio.circulationbff.client.feign.ServicePointClient; import org.folio.circulationbff.domain.dto.Item; +import org.folio.circulationbff.domain.dto.Location; import org.folio.circulationbff.domain.dto.ServicePoint; import org.folio.circulationbff.service.InventoryService; import org.springframework.stereotype.Service; @@ -14,6 +16,7 @@ @Log4j2 public class InventoryServiceImpl implements InventoryService { private final ItemStorageClient itemClient; + private final LocationClient locationClient; private final ServicePointClient servicePointClient; @Override @@ -22,6 +25,12 @@ public Item fetchItem(String id) { return itemClient.findItem(id); } + @Override + public Location fetchLocation(String id) { + log.info("fetchLocation:: fetching location {}", id); + return locationClient.findLocation(id); + } + @Override public ServicePoint fetchServicePoint(String id) { log.info("fetchServicePoint:: fetching service point {}", id); diff --git a/src/test/java/org/folio/circulationbff/api/CheckInApiTest.java b/src/test/java/org/folio/circulationbff/api/CheckInApiTest.java index f3af981..c81bb21 100644 --- a/src/test/java/org/folio/circulationbff/api/CheckInApiTest.java +++ b/src/test/java/org/folio/circulationbff/api/CheckInApiTest.java @@ -17,6 +17,7 @@ import org.folio.circulationbff.domain.dto.CheckInRequest; import org.folio.circulationbff.domain.dto.Item; +import org.folio.circulationbff.domain.dto.Location; import org.folio.circulationbff.domain.dto.SearchInstance; import org.folio.circulationbff.domain.dto.SearchInstances; import org.folio.circulationbff.domain.dto.SearchItem; @@ -54,13 +55,18 @@ void checkInSuccess() { .withHeader(HEADER_TENANT, WireMock.equalTo(TENANT_ID_CONSORTIUM)) .willReturn(jsonResponse(checkinItem, SC_OK))); + var primaryServicePoint = randomUUID(); + var location = new Location().primaryServicePoint(primaryServicePoint); + wireMockServer.stubFor(WireMock.get(urlMatching("/locations/effectiveLocationId")) + .withHeader(HEADER_TENANT, WireMock.equalTo(TENANT_ID_CONSORTIUM)) + .willReturn(jsonResponse(location, SC_OK))); var servicePointResponse = """ { "name": "updated service point", "holdShelfClosedLibraryDateManagement": "Keep_the_current_due_date" } """; - wireMockServer.stubFor(WireMock.get(urlMatching("/service-points/effectiveLocationId")) + wireMockServer.stubFor(WireMock.get(urlMatching("/service-points/" + primaryServicePoint)) .withHeader(HEADER_TENANT, WireMock.equalTo(TENANT_ID_CONSORTIUM)) .willReturn(jsonResponse(servicePointResponse, SC_OK))); @@ -89,13 +95,18 @@ void checkInSuccessCrossTenant() { .withHeader(HEADER_TENANT, WireMock.equalTo(TENANT_ID_COLLEGE)) .willReturn(jsonResponse(checkinItem, SC_OK))); + var primaryServicePoint = randomUUID(); + var location = new Location().primaryServicePoint(primaryServicePoint); + wireMockServer.stubFor(WireMock.get(urlMatching("/locations/effectiveLocationId")) + .withHeader(HEADER_TENANT, WireMock.equalTo(TENANT_ID_COLLEGE)) + .willReturn(jsonResponse(location, SC_OK))); var servicePointResponse = """ { "name": "updated service point", "holdShelfClosedLibraryDateManagement": "Keep_the_current_due_date" } """; - wireMockServer.stubFor(WireMock.get(urlMatching("/service-points/effectiveLocationId")) + wireMockServer.stubFor(WireMock.get(urlMatching("/service-points/" + primaryServicePoint)) .withHeader(HEADER_TENANT, WireMock.equalTo(TENANT_ID_COLLEGE)) .willReturn(jsonResponse(servicePointResponse, SC_OK)));