Skip to content

Commit

Permalink
MCBFF-38: fix fetching service point by location id
Browse files Browse the repository at this point in the history
  • Loading branch information
imerabishvili committed Jan 27, 2025
1 parent 0e725cd commit a967e5e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
2 changes: 2 additions & 0 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +16,7 @@
@Log4j2
public class InventoryServiceImpl implements InventoryService {
private final ItemStorageClient itemClient;
private final LocationClient locationClient;
private final ServicePointClient servicePointClient;

@Override
Expand All @@ -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);
Expand Down
15 changes: 13 additions & 2 deletions src/test/java/org/folio/circulationbff/api/CheckInApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));

Expand Down Expand Up @@ -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)));

Expand Down

0 comments on commit a967e5e

Please sign in to comment.