From 241b810157e163c40bc2106c048a1bf67f99a777 Mon Sep 17 00:00:00 2001 From: Saba-Zedginidze-EPAM <148070844+Saba-Zedginidze-EPAM@users.noreply.github.com> Date: Mon, 27 May 2024 15:35:30 +0400 Subject: [PATCH] [MODORDERS-1108] Update PiecesAPI CRUD methods to process inventory in desired tenant (#942) * [MODORDERS-1108] Refactor PieceCreateFlowInventoryManager * [MODORDERS-1108] Refactor PieceDeleteFlowManager * [MODORDERS-1108] Split PieceDeleteFlowManager and create PieceDeleteFlowInventoryManager * [MODORDERS-1108] Refactor PieceUpdateFlowInventoryManager * [MODORDERS-1108] Fix failing PieceUpdate/CreateFlowInventoryManagerTest * [MODORDERS-1108] Fix failing PieceCreateFlowInventoryManagerTest * [MODORDERS-1108] Rebuild * [MODORDERS-1108] Add support for mulitenant * [MODORDERS-1108] a small bug in binding * [MODORDERS-1112] Remove redundant code * [MODORDERS-1112] Make code readable, add PieceDeleteInventoryService, pass missed locationContext * [MODORDERS-1112] Static import createContextWithNewTenantId * [MODORDERS-1112] Update acq-models * [MODORDERS-1112] Minor refactoring * [MODORDERS-1122] Change correct attribute * [MODORDERS-1108] Remove BooleanUtils * [MODORDERS-1108] Replace TRUE with FALSE checks * Revert "[MODORDERS-1108] Replace TRUE with FALSE checks" This reverts commit 3132594a482e3f317474affae988ea050ff981bc. --- ramls/acq-models | 2 +- .../org/folio/config/ApplicationConfig.java | 67 ++++++--- .../open/OpenCompositeOrderPieceService.java | 52 ++++--- .../pieces/PieceDeleteInventoryService.java | 48 +++++++ .../pieces/PieceUpdateInventoryService.java | 61 ++++---- .../PieceCreateFlowInventoryManager.java | 96 +++++-------- .../PieceDeleteFlowInventoryManager.java | 31 ++++ .../flows/delete/PieceDeleteFlowManager.java | 116 ++++----------- .../PieceUpdateFlowInventoryManager.java | 136 ++++++++---------- .../service/titles/TitleInstanceService.java | 3 +- .../folio/service/titles/TitlesService.java | 10 +- .../OpenCompositeOrderPieceServiceTest.java | 4 +- .../PieceCreateFlowInventoryManagerTest.java | 21 ++- .../delete/PieceDeleteFlowManagerTest.java | 21 ++- .../PieceUpdateFlowInventoryManagerTest.java | 29 ++-- 15 files changed, 349 insertions(+), 348 deletions(-) create mode 100644 src/main/java/org/folio/service/pieces/PieceDeleteInventoryService.java create mode 100644 src/main/java/org/folio/service/pieces/flows/delete/PieceDeleteFlowInventoryManager.java diff --git a/ramls/acq-models b/ramls/acq-models index f237891dc..da1f78cd6 160000 --- a/ramls/acq-models +++ b/ramls/acq-models @@ -1 +1 @@ -Subproject commit f237891dc75e31a0e65afe24d8934250f90f9f4c +Subproject commit da1f78cd6503659c37d39011b84509d3341b19ea diff --git a/src/main/java/org/folio/config/ApplicationConfig.java b/src/main/java/org/folio/config/ApplicationConfig.java index 5001b155e..15524d01a 100644 --- a/src/main/java/org/folio/config/ApplicationConfig.java +++ b/src/main/java/org/folio/config/ApplicationConfig.java @@ -100,6 +100,7 @@ import org.folio.service.orders.lines.update.instance.WithoutHoldingOrderLineUpdateInstanceStrategy; import org.folio.service.organization.OrganizationService; import org.folio.service.pieces.PieceChangeReceiptStatusPublisher; +import org.folio.service.pieces.PieceDeleteInventoryService; import org.folio.service.pieces.PieceService; import org.folio.service.pieces.PieceStorageService; import org.folio.service.pieces.PieceUpdateInventoryService; @@ -108,6 +109,7 @@ import org.folio.service.pieces.flows.create.PieceCreateFlowInventoryManager; import org.folio.service.pieces.flows.create.PieceCreateFlowManager; import org.folio.service.pieces.flows.create.PieceCreateFlowPoLineService; +import org.folio.service.pieces.flows.delete.PieceDeleteFlowInventoryManager; import org.folio.service.pieces.flows.delete.PieceDeleteFlowManager; import org.folio.service.pieces.flows.delete.PieceDeleteFlowPoLineService; import org.folio.service.pieces.flows.strategies.ProcessInventoryElectronicStrategy; @@ -521,26 +523,34 @@ PieceChangeReceiptStatusPublisher receiptStatusPublisher() { return new PieceChangeReceiptStatusPublisher(); } - @Bean PieceStorageService pieceStorageService(RestClient restClient) { + @Bean + PieceStorageService pieceStorageService(RestClient restClient) { return new PieceStorageService(restClient); } - @Bean PieceService piecesService(PieceChangeReceiptStatusPublisher receiptStatusPublisher) { + @Bean + PieceService piecesService(PieceChangeReceiptStatusPublisher receiptStatusPublisher) { return new PieceService(receiptStatusPublisher); } - @Bean DefaultPieceFlowsValidator pieceCreateFlowValidator() { + @Bean + DefaultPieceFlowsValidator pieceCreateFlowValidator() { return new DefaultPieceFlowsValidator(); } - @Bean PieceCreateFlowPoLineService pieceCreateFlowPoLineService(PurchaseOrderStorageService purchaseOrderStorageService, - PurchaseOrderLineService purchaseOrderLineService, ReceivingEncumbranceStrategy receivingEncumbranceStrategy) { + @Bean + PieceCreateFlowPoLineService pieceCreateFlowPoLineService(PurchaseOrderStorageService purchaseOrderStorageService, + PurchaseOrderLineService purchaseOrderLineService, + ReceivingEncumbranceStrategy receivingEncumbranceStrategy) { return new PieceCreateFlowPoLineService(purchaseOrderStorageService, purchaseOrderLineService, receivingEncumbranceStrategy); } - @Bean PieceCreateFlowManager pieceCreationService(PieceStorageService pieceStorageService, ProtectionService protectionService, - PieceCreateFlowInventoryManager pieceCreateFlowInventoryManager, DefaultPieceFlowsValidator defaultPieceFlowsValidator, - PieceCreateFlowPoLineService pieceCreateFlowPoLineService, BasePieceFlowHolderBuilder basePieceFlowHolderBuilder) { + @Bean + PieceCreateFlowManager pieceCreationService(PieceStorageService pieceStorageService, ProtectionService protectionService, + PieceCreateFlowInventoryManager pieceCreateFlowInventoryManager, + DefaultPieceFlowsValidator defaultPieceFlowsValidator, + PieceCreateFlowPoLineService pieceCreateFlowPoLineService, + BasePieceFlowHolderBuilder basePieceFlowHolderBuilder) { return new PieceCreateFlowManager(pieceStorageService, protectionService, pieceCreateFlowInventoryManager, defaultPieceFlowsValidator, pieceCreateFlowPoLineService, basePieceFlowHolderBuilder); } @@ -580,36 +590,51 @@ PieceUpdateInventoryService pieceUpdateInventoryService(InventoryItemManager inv return new PieceUpdateInventoryService(inventoryItemManager, inventoryHoldingManager, pieceStorageService); } - @Bean PieceDeleteFlowPoLineService pieceDeleteFlowPoLineService(PurchaseOrderStorageService purchaseOrderStorageService, + @Bean + PieceDeleteInventoryService pieceDeleteInventoryService(InventoryItemManager inventoryItemManager) { + return new PieceDeleteInventoryService(inventoryItemManager); + } + + @Bean + PieceDeleteFlowPoLineService pieceDeleteFlowPoLineService(PurchaseOrderStorageService purchaseOrderStorageService, PurchaseOrderLineService purchaseOrderLineService, ReceivingEncumbranceStrategy receivingEncumbranceStrategy) { return new PieceDeleteFlowPoLineService(purchaseOrderStorageService, purchaseOrderLineService, receivingEncumbranceStrategy); } - @Bean PieceDeleteFlowManager pieceDeletionFlowManager(PieceStorageService pieceStorageService, - ProtectionService protectionService, - InventoryItemManager inventoryItemManager, - PieceUpdateInventoryService pieceUpdateInventoryService, - PieceDeleteFlowPoLineService pieceDeleteFlowPoLineService, - BasePieceFlowHolderBuilder basePieceFlowHolderBuilder, - CirculationRequestsRetriever circulationRequestsRetriever) { - return new PieceDeleteFlowManager(pieceStorageService, protectionService, inventoryItemManager, pieceUpdateInventoryService, - pieceDeleteFlowPoLineService, basePieceFlowHolderBuilder, circulationRequestsRetriever); + @Bean + PieceDeleteFlowManager pieceDeletionFlowManager(PieceDeleteFlowInventoryManager pieceDeleteFlowInventoryManager, + PieceStorageService pieceStorageService, + ProtectionService protectionService, + PieceDeleteFlowPoLineService pieceDeleteFlowPoLineService, + BasePieceFlowHolderBuilder basePieceFlowHolderBuilder, + CirculationRequestsRetriever circulationRequestsRetriever) { + return new PieceDeleteFlowManager(pieceDeleteFlowInventoryManager, pieceStorageService, protectionService, + pieceDeleteFlowPoLineService, basePieceFlowHolderBuilder, circulationRequestsRetriever); + } + + @Bean + PieceDeleteFlowInventoryManager pieceDeleteFlowInventoryManager(PieceDeleteInventoryService pieceDeleteInventoryService, + PieceUpdateInventoryService pieceUpdateInventoryService) { + return new PieceDeleteFlowInventoryManager(pieceDeleteInventoryService, pieceUpdateInventoryService); } - @Bean BasePieceFlowHolderBuilder basePieceFlowHolderBuilder(PurchaseOrderStorageService purchaseOrderStorageService, + @Bean + BasePieceFlowHolderBuilder basePieceFlowHolderBuilder(PurchaseOrderStorageService purchaseOrderStorageService, PurchaseOrderLineService purchaseOrderLineService, TitlesService titlesService) { return new BasePieceFlowHolderBuilder(purchaseOrderStorageService, purchaseOrderLineService, titlesService); } - @Bean PieceUpdateFlowPoLineService pieceUpdateFlowPoLineService(PurchaseOrderStorageService purchaseOrderStorageService, PurchaseOrderLineService purchaseOrderLineService, + @Bean + PieceUpdateFlowPoLineService pieceUpdateFlowPoLineService(PurchaseOrderStorageService purchaseOrderStorageService, PurchaseOrderLineService purchaseOrderLineService, ReceivingEncumbranceStrategy receivingEncumbranceStrategy, PieceDeleteFlowPoLineService pieceDeleteFlowPoLineService, PieceCreateFlowPoLineService pieceCreateFlowPoLineService) { return new PieceUpdateFlowPoLineService(purchaseOrderStorageService, purchaseOrderLineService, receivingEncumbranceStrategy, pieceCreateFlowPoLineService, pieceDeleteFlowPoLineService); } - @Bean PieceUpdateFlowManager pieceUpdateFlowManager(PieceStorageService pieceStorageService, PieceService pieceService, ProtectionService protectionService, + @Bean + PieceUpdateFlowManager pieceUpdateFlowManager(PieceStorageService pieceStorageService, PieceService pieceService, ProtectionService protectionService, PieceUpdateFlowPoLineService pieceUpdateFlowPoLineService, PieceUpdateFlowInventoryManager pieceUpdateFlowInventoryManager, BasePieceFlowHolderBuilder basePieceFlowHolderBuilder, DefaultPieceFlowsValidator defaultPieceFlowsValidator, PurchaseOrderLineService purchaseOrderLineService) { diff --git a/src/main/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderPieceService.java b/src/main/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderPieceService.java index 1517767e5..84adfc51f 100644 --- a/src/main/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderPieceService.java +++ b/src/main/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderPieceService.java @@ -3,6 +3,7 @@ import static java.util.stream.Collectors.toList; import static org.folio.orders.utils.HelperUtils.calculateInventoryItemsQuantity; import static org.folio.orders.utils.HelperUtils.collectResultsOnSuccess; +import static org.folio.orders.utils.RequestContextUtil.createContextWithNewTenantId; import java.util.ArrayList; import java.util.Date; @@ -23,6 +24,7 @@ import org.folio.rest.core.models.RequestContext; import org.folio.rest.jaxrs.model.CompositePoLine; import org.folio.rest.jaxrs.model.Piece; +import org.folio.rest.jaxrs.model.Title; import org.folio.service.ProtectionService; import org.folio.service.inventory.InventoryHoldingManager; import org.folio.service.inventory.InventoryItemManager; @@ -161,36 +163,30 @@ public Future updatePieceRecord(Piece piece, RequestContext requestContext * @return CompletableFuture with void. */ public Future openOrderUpdateInventory(CompositePoLine compPOL, Piece piece, boolean isInstanceMatchingDisabled, RequestContext requestContext) { - if (Boolean.TRUE.equals(compPOL.getIsPackage())) { - return titlesService.getTitleById(piece.getTitleId(), requestContext) - .compose(title -> titlesService.updateTitleWithInstance(title, isInstanceMatchingDisabled, requestContext).map(title::withInstanceId)) - .compose(title -> { - if (piece.getHoldingId() != null) { - return Future.succeededFuture(piece.getHoldingId()); - } - if (!PoLineCommonUtil.isHoldingsUpdateRequired(compPOL)) { - return Future.succeededFuture(); - } - return inventoryHoldingManager.createHoldingAndReturnId(title.getInstanceId(), piece.getLocationId(), requestContext) - .map(holdingId -> { - piece.setLocationId(null); - piece.setHoldingId(holdingId); - return holdingId; - }); - }) - .compose(holdingId -> { - if (PoLineCommonUtil.isItemsUpdateRequired(compPOL)) { - return inventoryItemManager.openOrderCreateItemRecord(compPOL, holdingId, requestContext); - } - return Future.succeededFuture(); - }) - .onSuccess(itemId -> Optional.ofNullable(itemId).ifPresent(piece::withItemId)) - .mapEmpty(); - } - else - { + if (!Boolean.TRUE.equals(compPOL.getIsPackage())) { return inventoryItemManager.updateItemWithPieceFields(piece, requestContext); } + var locationContext = createContextWithNewTenantId(requestContext, piece.getReceivingTenantId()); + return titlesService.getTitleById(piece.getTitleId(), requestContext) + .compose(title -> titlesService.updateTitleWithInstance(title, isInstanceMatchingDisabled, locationContext, requestContext).map(title::withInstanceId)) + .compose(title -> getOrCreateHolding(compPOL, piece, title, locationContext)) + .compose(holdingId -> updateItemsIfNeeded(compPOL, holdingId, locationContext)) + .map(itemId -> Optional.ofNullable(itemId).map(piece::withItemId)) + .mapEmpty(); + } + + private Future getOrCreateHolding(CompositePoLine compPOL, Piece piece, Title title, RequestContext locationContext) { + if (piece.getHoldingId() != null || !PoLineCommonUtil.isHoldingsUpdateRequired(compPOL)) { + return Future.succeededFuture(piece.getHoldingId()); + } + return inventoryHoldingManager.createHoldingAndReturnId(title.getInstanceId(), piece.getLocationId(), locationContext) + .map(holdingId -> piece.withLocationId(null).withHoldingId(holdingId).getHoldingId()); + } + + private Future updateItemsIfNeeded(CompositePoLine compPOL, String holdingId, RequestContext locationContext) { + return PoLineCommonUtil.isItemsUpdateRequired(compPOL) + ? inventoryItemManager.openOrderCreateItemRecord(compPOL, holdingId, locationContext) + : Future.succeededFuture(); } private void validateItemsCreation(CompositePoLine compPOL, int itemsSize) { diff --git a/src/main/java/org/folio/service/pieces/PieceDeleteInventoryService.java b/src/main/java/org/folio/service/pieces/PieceDeleteInventoryService.java new file mode 100644 index 000000000..41ab367de --- /dev/null +++ b/src/main/java/org/folio/service/pieces/PieceDeleteInventoryService.java @@ -0,0 +1,48 @@ +package org.folio.service.pieces; + +import io.vertx.core.Future; +import io.vertx.core.json.JsonObject; +import org.apache.commons.lang3.StringUtils; +import org.folio.models.ItemStatus; +import org.folio.models.pieces.PieceDeletionHolder; +import org.folio.rest.core.models.RequestContext; +import org.folio.rest.jaxrs.model.Piece; +import org.folio.service.inventory.InventoryItemManager; + +import java.util.Optional; + +import static org.folio.service.inventory.InventoryItemManager.ITEM_STATUS; +import static org.folio.service.inventory.InventoryItemManager.ITEM_STATUS_NAME; + +public class PieceDeleteInventoryService { + + private final InventoryItemManager inventoryItemManager; + + public PieceDeleteInventoryService(InventoryItemManager inventoryItemManager) { + this.inventoryItemManager = inventoryItemManager; + } + + public Future deleteItem(PieceDeletionHolder holder, RequestContext requestContext) { + var piece = holder.getPieceToDelete(); + return getOnOrderItemForPiece(piece, requestContext) + .compose(item -> Optional.ofNullable(item) + .map(mItem -> inventoryItemManager.deleteItem(piece.getItemId(), true, requestContext)) + .orElse(Future.succeededFuture())); + } + + private Future getOnOrderItemForPiece(Piece piece, RequestContext requestContext) { + if (StringUtils.isEmpty(piece.getItemId())) { + return Future.succeededFuture(); + } + return inventoryItemManager.getItemRecordById(piece.getItemId(), true, requestContext) + .map(item -> getItemWithStatus(item, ItemStatus.ON_ORDER.value())); + } + + private JsonObject getItemWithStatus(JsonObject item, String status) { + return Optional.ofNullable(item) + .map(itemObj -> itemObj.getJsonObject(ITEM_STATUS)) + .filter(itemStatus -> status.equalsIgnoreCase(itemStatus.getString(ITEM_STATUS_NAME))) + .orElse(null); + } + +} diff --git a/src/main/java/org/folio/service/pieces/PieceUpdateInventoryService.java b/src/main/java/org/folio/service/pieces/PieceUpdateInventoryService.java index 8045edbb7..1f8847952 100644 --- a/src/main/java/org/folio/service/pieces/PieceUpdateInventoryService.java +++ b/src/main/java/org/folio/service/pieces/PieceUpdateInventoryService.java @@ -1,5 +1,6 @@ package org.folio.service.pieces; +import static org.folio.orders.utils.RequestContextUtil.createContextWithNewTenantId; import static org.folio.service.inventory.InventoryHoldingManager.HOLDING_PERMANENT_LOCATION_ID; import java.util.List; @@ -62,32 +63,42 @@ public Future manualPieceFlowCreateItemRecord(Piece piece, CompositePoLi } public Future> deleteHoldingConnectedToPiece(Piece piece, RequestContext requestContext) { - if (piece != null && piece.getHoldingId() != null) { + if (piece == null || piece.getHoldingId() == null) { + return Future.succeededFuture(); + } + var locationContext = createContextWithNewTenantId(requestContext, piece.getReceivingTenantId()); String holdingId = piece.getHoldingId(); - return inventoryHoldingManager.getHoldingById(holdingId, true, requestContext) - .compose(holding -> { - if (holding != null && !holding.isEmpty()) { - return pieceStorageService.getPiecesByHoldingId(holdingId, requestContext) - .map(pieces -> skipPieceToProcess(piece, pieces)) - .compose(existingPieces -> inventoryItemManager.getItemsByHoldingId(holdingId, requestContext) - .map(existingItems-> { - List remainingPieces = skipPieceToProcess(piece, existingPieces); - if (CollectionUtils.isEmpty(remainingPieces) && CollectionUtils.isEmpty(existingItems)) { - return Pair.of(true, holding); - } - return Pair.of(false, new JsonObject()); - })); - } - return Future.succeededFuture(Pair.of(false, new JsonObject())); - }) - .compose(isUpdatePossibleVsHolding -> { - if (isUpdatePossibleVsHolding.getKey() && !isUpdatePossibleVsHolding.getValue().isEmpty()) { - String permanentLocationId = isUpdatePossibleVsHolding.getValue().getString(HOLDING_PERMANENT_LOCATION_ID); - return inventoryHoldingManager.deleteHoldingById(holdingId, true, requestContext) - .map(v -> Pair.of(holdingId, permanentLocationId)); - } - return Future.succeededFuture(); - }); + return inventoryHoldingManager.getHoldingById(holdingId, true, locationContext) + .compose(holding -> getUpdatePossibleForHolding(holding, holdingId, piece, locationContext, requestContext)) + .compose(isUpdatePossibleVsHolding -> deleteHoldingIfPossible(isUpdatePossibleVsHolding, holdingId, locationContext)); + } + + private Future> getUpdatePossibleForHolding(JsonObject holding, String holdingId, Piece piece, + RequestContext locationContext, RequestContext requestContext) { + if (holding == null || holding.isEmpty()) { + return Future.succeededFuture(Pair.of(false, new JsonObject())); + } + return pieceStorageService.getPiecesByHoldingId(holdingId, requestContext) + .map(pieces -> skipPieceToProcess(piece, pieces)) + .compose(existingPieces -> inventoryItemManager.getItemsByHoldingId(holdingId, locationContext) + .map(existingItems-> { + List remainingPieces = skipPieceToProcess(piece, existingPieces); + if (CollectionUtils.isEmpty(remainingPieces) && CollectionUtils.isEmpty(existingItems)) { + return Pair.of(true, holding); + } + return Pair.of(false, new JsonObject()); + }) + ); + } + + private Future> deleteHoldingIfPossible(Pair isUpdatePossibleVsHolding, + String holdingId, RequestContext locationContext) { + var isUpdatePossible = isUpdatePossibleVsHolding.getKey(); + var holding = isUpdatePossibleVsHolding.getValue(); + if (isUpdatePossible && !holding.isEmpty()) { + String permanentLocationId = holding.getString(HOLDING_PERMANENT_LOCATION_ID); + return inventoryHoldingManager.deleteHoldingById(holdingId, true, locationContext) + .map(v -> Pair.of(holdingId, permanentLocationId)); } return Future.succeededFuture(); } diff --git a/src/main/java/org/folio/service/pieces/flows/create/PieceCreateFlowInventoryManager.java b/src/main/java/org/folio/service/pieces/flows/create/PieceCreateFlowInventoryManager.java index 726739a23..ba651b742 100644 --- a/src/main/java/org/folio/service/pieces/flows/create/PieceCreateFlowInventoryManager.java +++ b/src/main/java/org/folio/service/pieces/flows/create/PieceCreateFlowInventoryManager.java @@ -7,7 +7,6 @@ import org.folio.rest.jaxrs.model.CompositePoLine; import org.folio.rest.jaxrs.model.Location; import org.folio.rest.jaxrs.model.Piece; -import org.folio.rest.jaxrs.model.Title; import org.folio.service.inventory.InventoryHoldingManager; import org.folio.service.pieces.PieceUpdateInventoryService; import org.folio.service.pieces.flows.DefaultPieceFlowsValidator; @@ -15,6 +14,8 @@ import io.vertx.core.Future; +import static org.folio.orders.utils.RequestContextUtil.createContextWithNewTenantId; + public class PieceCreateFlowInventoryManager { private final TitlesService titlesService; @@ -29,80 +30,53 @@ public PieceCreateFlowInventoryManager(TitlesService titlesService, this.inventoryHoldingManager = inventoryHoldingManager; } - public Future processInventory(CompositePoLine compPOL, Piece piece, boolean createItem, RequestContext requestContext) { - if (Boolean.TRUE.equals(compPOL.getIsPackage())) { - return packagePoLineUpdateInventory(compPOL, piece, createItem, requestContext); - } - else - { - return nonPackagePoLineUpdateInventory(compPOL, piece, createItem, requestContext); - } + public Future processInventory(CompositePoLine compPOL, Piece piece, boolean createItem, RequestContext requestContext) { + var locationContext = createContextWithNewTenantId(requestContext, piece.getReceivingTenantId()); + return updateInventoryInstanceForPoLine(compPOL, piece, locationContext, requestContext) + .compose(instanceId -> handleHolding(compPOL, piece, instanceId, locationContext)) + .compose(holdingId -> handleItem(compPOL, createItem, piece, locationContext)) + .map(itemId -> Optional.ofNullable(itemId).map(piece::withItemId)) + .mapEmpty(); } - private Future nonPackagePoLineUpdateInventory(CompositePoLine compPOL, Piece piece, boolean createItem, RequestContext requestContext) { - return nonPackageUpdateTitleWithInstance(compPOL, piece.getTitleId(), requestContext) - .compose(instanceId -> handleHolding(compPOL, piece, instanceId, requestContext)) - .compose(holdingId -> handleItem(compPOL, createItem, piece, requestContext)) - .map(itemId -> { - Optional.ofNullable(itemId).ifPresent(piece::withItemId); - return null; - }) - .mapEmpty(); + private Future updateInventoryInstanceForPoLine(CompositePoLine compPOL, Piece piece, RequestContext locationContext, RequestContext requestContext) { + if (!Boolean.TRUE.equals(compPOL.getIsPackage())) { + return Optional.ofNullable(getPoLineInstanceId(compPOL)) + .orElseGet(() -> titlesService.updateTitleWithInstance(piece.getTitleId(), locationContext, requestContext)) + .map(instanceId -> compPOL.withInstanceId(instanceId).getInstanceId()); + } + return titlesService.updateTitleWithInstance(piece.getTitleId(), locationContext, requestContext); } - private Future packagePoLineUpdateInventory(CompositePoLine compPOL, Piece piece, boolean createItem, RequestContext requestContext) { - return titlesService.getTitleById(piece.getTitleId(), requestContext) - .compose(title -> packageUpdateTitleWithInstance(title, requestContext)) - .compose(instanceId -> handleHolding(compPOL, piece, instanceId, requestContext)) - .compose(holdingId -> handleItem(compPOL, createItem, piece, requestContext)) - .map(itemId -> { - Optional.ofNullable(itemId).ifPresent(piece::withItemId); - return null; - }) - .mapEmpty(); + private Future getPoLineInstanceId(CompositePoLine compPOL) { + return compPOL.getInstanceId() != null || PoLineCommonUtil.isInventoryUpdateNotRequired(compPOL) + ? Future.succeededFuture(compPOL.getInstanceId()) + : null; } private Future handleHolding(CompositePoLine compPOL, Piece piece, String instanceId, RequestContext requestContext) { if (piece.getHoldingId() != null) { return Future.succeededFuture(new Location().withHoldingId(piece.getHoldingId())); } - if (instanceId != null && DefaultPieceFlowsValidator.isCreateHoldingForPiecePossible(piece, compPOL)) { - return inventoryHoldingManager.createHoldingAndReturnId(instanceId, piece.getLocationId(), requestContext) - .map(holdingId -> { - Location location = new Location().withLocationId(piece.getLocationId()); - if(holdingId != null) { - piece.setLocationId(null); - piece.setHoldingId(holdingId); - location.setLocationId(null); - location.setHoldingId(holdingId); - } - return location; - }); - } - return Future.succeededFuture(new Location().withLocationId(piece.getLocationId())); - } - private Future handleItem(CompositePoLine compPOL, boolean createItem, Piece piece, RequestContext requestContext) { - if (piece.getItemId() != null) { - return Future.succeededFuture(piece.getItemId()); + var location = new Location().withLocationId(piece.getLocationId()); + if (instanceId == null || !DefaultPieceFlowsValidator.isCreateHoldingForPiecePossible(piece, compPOL)) { + return Future.succeededFuture(location); } - if (createItem && piece.getHoldingId() != null) { - return pieceUpdateInventoryService.manualPieceFlowCreateItemRecord(piece, compPOL, requestContext); - } - return Future.succeededFuture(); + return inventoryHoldingManager.createHoldingAndReturnId(instanceId, piece.getLocationId(), requestContext) + .map(holdingId -> { + if (holdingId != null) { + piece.withLocationId(null).setHoldingId(holdingId); + location.withLocationId(null).setHoldingId(holdingId); + } + return location; + }); } - - private Future nonPackageUpdateTitleWithInstance(CompositePoLine poLine, String titleId, RequestContext requestContext) { - if (poLine.getInstanceId() != null || PoLineCommonUtil.isInventoryUpdateNotRequired(poLine)) { - return Future.succeededFuture(poLine.getInstanceId()); - } - return titlesService.getTitleById(titleId, requestContext) - .compose(title -> titlesService.updateTitleWithInstance(title, requestContext)) - .map(instanceId -> poLine.withInstanceId(instanceId).getInstanceId()); + private Future handleItem(CompositePoLine compPOL, boolean createItem, Piece piece, RequestContext requestContext) { + return piece.getItemId() != null || !createItem || piece.getHoldingId() == null + ? Future.succeededFuture(piece.getItemId()) + : pieceUpdateInventoryService.manualPieceFlowCreateItemRecord(piece, compPOL, requestContext); } - private Future packageUpdateTitleWithInstance(Title title, RequestContext requestContext) { - return titlesService.updateTitleWithInstance(title, requestContext); - } } diff --git a/src/main/java/org/folio/service/pieces/flows/delete/PieceDeleteFlowInventoryManager.java b/src/main/java/org/folio/service/pieces/flows/delete/PieceDeleteFlowInventoryManager.java new file mode 100644 index 000000000..00dbf8078 --- /dev/null +++ b/src/main/java/org/folio/service/pieces/flows/delete/PieceDeleteFlowInventoryManager.java @@ -0,0 +1,31 @@ +package org.folio.service.pieces.flows.delete; + +import io.vertx.core.Future; +import org.apache.commons.lang3.tuple.Pair; +import org.folio.models.pieces.PieceDeletionHolder; +import org.folio.rest.core.models.RequestContext; +import org.folio.service.pieces.PieceDeleteInventoryService; +import org.folio.service.pieces.PieceUpdateInventoryService; + +import static org.folio.orders.utils.RequestContextUtil.createContextWithNewTenantId; + +public class PieceDeleteFlowInventoryManager { + + private final PieceDeleteInventoryService pieceDeleteInventoryService; + private final PieceUpdateInventoryService pieceUpdateInventoryService; + public PieceDeleteFlowInventoryManager(PieceDeleteInventoryService pieceDeleteInventoryService, + PieceUpdateInventoryService pieceUpdateInventoryService) { + this.pieceDeleteInventoryService = pieceDeleteInventoryService; + this.pieceUpdateInventoryService = pieceUpdateInventoryService; + } + + public Future> processInventory(PieceDeletionHolder holder, RequestContext requestContext) { + var locationContext = createContextWithNewTenantId(requestContext, holder.getPieceToDelete().getReceivingTenantId()); + return pieceDeleteInventoryService.deleteItem(holder, locationContext) + .compose(aVoid -> holder.isDeleteHolding() + ? pieceUpdateInventoryService.deleteHoldingConnectedToPiece(holder.getPieceToDelete(), locationContext) + : Future.succeededFuture() + ); + } + +} diff --git a/src/main/java/org/folio/service/pieces/flows/delete/PieceDeleteFlowManager.java b/src/main/java/org/folio/service/pieces/flows/delete/PieceDeleteFlowManager.java index a99e70c87..a3ec3f1e3 100644 --- a/src/main/java/org/folio/service/pieces/flows/delete/PieceDeleteFlowManager.java +++ b/src/main/java/org/folio/service/pieces/flows/delete/PieceDeleteFlowManager.java @@ -1,59 +1,41 @@ package org.folio.service.pieces.flows.delete; import static org.folio.orders.utils.ProtectedOperationType.DELETE; -import static org.folio.service.inventory.InventoryItemManager.ITEM_STATUS; -import static org.folio.service.inventory.InventoryItemManager.ITEM_STATUS_NAME; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.folio.models.ItemStatus; import org.folio.models.pieces.PieceDeletionHolder; import org.folio.rest.RestConstants; import org.folio.rest.core.exceptions.ErrorCodes; import org.folio.rest.core.exceptions.HttpException; import org.folio.rest.core.models.RequestContext; -import org.folio.rest.jaxrs.model.Error; -import org.folio.rest.jaxrs.model.Errors; -import org.folio.rest.jaxrs.model.Piece; import org.folio.service.CirculationRequestsRetriever; import org.folio.service.ProtectionService; -import org.folio.service.inventory.InventoryItemManager; import org.folio.service.pieces.PieceStorageService; -import org.folio.service.pieces.PieceUpdateInventoryService; import org.folio.service.pieces.flows.BasePieceFlowHolderBuilder; import io.vertx.core.Future; -import io.vertx.core.json.JsonObject; public class PieceDeleteFlowManager { + private static final Logger logger = LogManager.getLogger(PieceDeleteFlowManager.class); + private final PieceDeleteFlowInventoryManager pieceDeleteFlowInventoryManager; private final PieceStorageService pieceStorageService; private final ProtectionService protectionService; - private final InventoryItemManager inventoryItemManager; - private final PieceUpdateInventoryService pieceUpdateInventoryService; private final PieceDeleteFlowPoLineService pieceDeleteFlowPoLineService; private final BasePieceFlowHolderBuilder basePieceFlowHolderBuilder; private final CirculationRequestsRetriever circulationRequestsRetriever; - public PieceDeleteFlowManager(PieceStorageService pieceStorageService, + public PieceDeleteFlowManager(PieceDeleteFlowInventoryManager pieceDeleteFlowInventoryManager, + PieceStorageService pieceStorageService, ProtectionService protectionService, - InventoryItemManager inventoryItemManager, - PieceUpdateInventoryService pieceUpdateInventoryService, PieceDeleteFlowPoLineService pieceDeleteFlowPoLineService, BasePieceFlowHolderBuilder basePieceFlowHolderBuilder, CirculationRequestsRetriever circulationRequestsRetriever) { + this.pieceDeleteFlowInventoryManager = pieceDeleteFlowInventoryManager; this.pieceStorageService = pieceStorageService; this.protectionService = protectionService; - this.inventoryItemManager = inventoryItemManager; - this.pieceUpdateInventoryService = pieceUpdateInventoryService; this.pieceDeleteFlowPoLineService = pieceDeleteFlowPoLineService; this.basePieceFlowHolderBuilder = basePieceFlowHolderBuilder; this.circulationRequestsRetriever = circulationRequestsRetriever; @@ -62,89 +44,39 @@ public PieceDeleteFlowManager(PieceStorageService pieceStorageService, public Future deletePiece(String pieceId, boolean deleteHolding, RequestContext requestContext) { PieceDeletionHolder holder = new PieceDeletionHolder().withDeleteHolding(deleteHolding); return pieceStorageService.getPieceById(pieceId, requestContext) - .map(pieceToDelete -> { - holder.withPieceToDelete(pieceToDelete); return null; - }) + .map(holder::withPieceToDelete) .compose(aHolder -> basePieceFlowHolderBuilder.updateHolderWithOrderInformation(holder, requestContext)) - .compose(aHolder -> basePieceFlowHolderBuilder.updateHolderWithTitleInformation(holder, requestContext)) + .compose(aVoid -> basePieceFlowHolderBuilder.updateHolderWithTitleInformation(holder, requestContext)) .compose(aVoid -> protectionService.isOperationRestricted(holder.getTitle().getAcqUnitIds(), DELETE, requestContext)) .compose(aVoid -> isDeletePieceRequestValid(holder, requestContext)) - .compose(aVoid -> processInventory(holder, requestContext)) + .compose(aVoid -> pieceDeleteFlowInventoryManager.processInventory(holder, requestContext)) .compose(pair -> updatePoLine(holder, requestContext)) .compose(aVoid -> pieceStorageService.deletePiece(holder.getPieceToDelete().getId(), true, requestContext)); } private Future isDeletePieceRequestValid(PieceDeletionHolder holder, RequestContext requestContext) { - List combinedErrors = new ArrayList<>(); - if (holder.getPieceToDelete().getItemId() != null) { - return circulationRequestsRetriever.getNumberOfRequestsByItemId(holder.getPieceToDelete().getItemId(), requestContext) - .map(numOfRequests -> { - if (numOfRequests != null && numOfRequests > 0) { - combinedErrors.add(ErrorCodes.REQUEST_FOUND.toError()); - } - return null; - }) - .map(v -> { - if (CollectionUtils.isNotEmpty(combinedErrors)) { - Errors errors = new Errors().withErrors(combinedErrors).withTotalRecords(combinedErrors.size()); - logger.error("Validation error : " + JsonObject.mapFrom(errors).encodePrettily()); - throw new HttpException(RestConstants.VALIDATION_ERROR, errors); - } - return null; - }) - .mapEmpty(); - } - return Future.succeededFuture(); - } - - private Future> processInventory(PieceDeletionHolder holder, RequestContext requestContext) { - return deleteItem(holder, requestContext) - .compose(aVoid -> { - if (holder.isDeleteHolding()) { - return pieceUpdateInventoryService.deleteHoldingConnectedToPiece(holder.getPieceToDelete(), requestContext); - } - return Future.succeededFuture(); - }); - } - - protected Future updatePoLine(PieceDeletionHolder holder, RequestContext requestContext) { - if (!Boolean.TRUE.equals(holder.getOriginPoLine().getIsPackage()) && !Boolean.TRUE.equals(holder.getOriginPoLine().getCheckinItems())) { - return pieceDeleteFlowPoLineService.updatePoLine(holder, requestContext); + var piece = holder.getPieceToDelete(); + if (piece.getItemId() == null) { + return Future.succeededFuture(); } - return Future.succeededFuture(); - } - private Future deleteItem(PieceDeletionHolder holder, RequestContext requestContext) { - Piece piece = holder.getPieceToDelete(); - if (piece.getItemId() != null) { - return getOnOrderItemForPiece(piece, requestContext).compose(item -> { - if (item != null) { - return inventoryItemManager.deleteItem(piece.getItemId(), true, requestContext); + return circulationRequestsRetriever.getNumberOfRequestsByItemId(piece.getItemId(), requestContext) + .compose(totalRequests -> { + if (totalRequests != null && totalRequests > 0) { + logger.error("isDeletePieceRequestValid:: {} Request(s) were found for the given item {} when deleting piece {}", + totalRequests, piece.getItemId(), piece.getId()); + throw new HttpException(RestConstants.VALIDATION_ERROR, ErrorCodes.REQUEST_FOUND.toError()); } return Future.succeededFuture(); - }); - } - return Future.succeededFuture(); + }) + .mapEmpty(); } - private boolean isItemWithStatus(JsonObject item, String status) { - return Optional.ofNullable(item).map(itemP -> item.getJsonObject(ITEM_STATUS)) - .filter(itemStatus -> status.equalsIgnoreCase(itemStatus.getString(ITEM_STATUS_NAME))) - .isPresent(); + protected Future updatePoLine(PieceDeletionHolder holder, RequestContext requestContext) { + var comPOL = holder.getOriginPoLine(); + return Boolean.TRUE.equals(comPOL.getIsPackage()) || Boolean.TRUE.equals(comPOL.getCheckinItems()) + ? Future.succeededFuture() + : pieceDeleteFlowPoLineService.updatePoLine(holder, requestContext); } - private Future getOnOrderItemForPiece(Piece piece, RequestContext requestContext) { - if (StringUtils.isNotEmpty(piece.getItemId())) { - return inventoryItemManager.getItemRecordById(piece.getItemId(), true, requestContext) - .map(item -> { - boolean isOnOrderItem = isItemWithStatus(item, ItemStatus.ON_ORDER.value()); - if (isOnOrderItem) { - return item; - } - return null; - }); - } else { - return Future.succeededFuture(); - } - } } diff --git a/src/main/java/org/folio/service/pieces/flows/update/PieceUpdateFlowInventoryManager.java b/src/main/java/org/folio/service/pieces/flows/update/PieceUpdateFlowInventoryManager.java index 1bd639fd4..8310263a0 100644 --- a/src/main/java/org/folio/service/pieces/flows/update/PieceUpdateFlowInventoryManager.java +++ b/src/main/java/org/folio/service/pieces/flows/update/PieceUpdateFlowInventoryManager.java @@ -1,5 +1,6 @@ package org.folio.service.pieces.flows.update; +import static org.folio.orders.utils.RequestContextUtil.createContextWithNewTenantId; import static org.folio.service.inventory.InventoryItemManager.ID; import static org.folio.service.inventory.InventoryItemManager.ITEM_HOLDINGS_RECORD_ID; import static org.folio.service.inventory.InventoryItemManager.ITEM_PURCHASE_ORDER_LINE_IDENTIFIER; @@ -15,7 +16,6 @@ import org.folio.rest.jaxrs.model.CompositePoLine; import org.folio.rest.jaxrs.model.Location; import org.folio.rest.jaxrs.model.Piece; -import org.folio.rest.jaxrs.model.Title; import org.folio.service.inventory.InventoryHoldingManager; import org.folio.service.inventory.InventoryItemManager; import org.folio.service.pieces.PieceUpdateInventoryService; @@ -26,6 +26,7 @@ import io.vertx.core.json.JsonObject; public class PieceUpdateFlowInventoryManager { + private static final Logger logger = LogManager.getLogger(PieceUpdateFlowInventoryManager.class); private static final String UPDATE_INVENTORY_FOR_LINE_DONE = "Update inventory for line done"; @@ -45,73 +46,62 @@ public PieceUpdateFlowInventoryManager(TitlesService titlesService, } public Future processInventory(PieceUpdateHolder holder, RequestContext requestContext) { - return inventoryItemManager.updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext) - .compose(aVoid -> { - if (Boolean.TRUE.equals(holder.getOriginPoLine().getIsPackage())) { - return packagePoLineUpdateInventory(holder, requestContext); - } else { - return nonPackagePoLineUpdateInventory(holder, requestContext); - } - }); + final var locationContext = createContextWithNewTenantId(requestContext, holder.getPieceToUpdate().getReceivingTenantId()); + return inventoryItemManager.updateItemWithPieceFields(holder.getPieceToUpdate(), locationContext) + .compose(v -> updateInventoryForPoLine(holder, locationContext, requestContext) + .map(holder::withInstanceId) + .compose(aHolder -> handleHolding(holder, locationContext)) + .compose(holdingId -> handleItem(holder, locationContext)) + .map(itemId -> Optional.ofNullable(itemId).map(holder.getPieceToUpdate()::withItemId)) + .compose(aVoid -> deleteHolding(holder, requestContext)) + .onSuccess(pair -> logger.debug(UPDATE_INVENTORY_FOR_LINE_DONE)) + .mapEmpty() + ); } - private Future nonPackagePoLineUpdateInventory(PieceUpdateHolder holder, RequestContext requestContext) { - return nonPackageUpdateTitleWithInstance(holder, requestContext) - .map(holder::withInstanceId) - .compose(aHolder -> handleHolding(holder, requestContext)) - .compose(holdingId -> handleItem(holder, requestContext)) - .map(itemId -> { - Optional.ofNullable(itemId).ifPresent(holder.getPieceToUpdate()::withItemId); - return null; - }) - .compose(aVoid -> deleteHolding(holder, requestContext)) - .onSuccess(pair -> logger.debug(UPDATE_INVENTORY_FOR_LINE_DONE)) - .mapEmpty(); + private Future updateInventoryForPoLine(PieceUpdateHolder holder, RequestContext locationContext, RequestContext requestContext) { + CompositePoLine poLineToSave = holder.getPoLineToSave(); + Piece pieceToUpdate = holder.getPieceToUpdate(); + if (!Boolean.TRUE.equals(poLineToSave.getIsPackage())) { + return Optional.ofNullable(getPoLineInstanceId(poLineToSave)) + .orElseGet(() -> titlesService.updateTitleWithInstance(pieceToUpdate.getTitleId(), locationContext, requestContext)) + .map(instanceId -> poLineToSave.withInstanceId(instanceId).getInstanceId()); + } + return titlesService.updateTitleWithInstance(pieceToUpdate.getTitleId(), locationContext, requestContext); } - private Future packagePoLineUpdateInventory(PieceUpdateHolder holder, RequestContext requestContext) { - return titlesService.getTitleById(holder.getPieceToUpdate().getTitleId(), requestContext) - .compose(title -> packageUpdateTitleWithInstance(title, requestContext)) - .map(holder::withInstanceId) - .compose(aHolder -> handleHolding(holder, requestContext)) - .compose(holdingId -> handleItem(holder, requestContext)) - .map(itemId -> { - Optional.ofNullable(itemId).ifPresent(holder.getPieceToUpdate()::withItemId); - return null; - }) - .compose(aVoid -> deleteHolding(holder, requestContext)) - .onSuccess(pair -> logger.debug(UPDATE_INVENTORY_FOR_LINE_DONE)) - .mapEmpty(); + private Future getPoLineInstanceId(CompositePoLine compPOL) { + return compPOL.getInstanceId() != null || PoLineCommonUtil.isInventoryUpdateNotRequired(compPOL) + ? Future.succeededFuture(compPOL.getInstanceId()) + : null; } private Future> deleteHolding(PieceUpdateHolder holder, RequestContext requestContext) { - if (holder.isDeleteHolding()) { - return pieceUpdateInventoryService.deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); - } - return Future.succeededFuture(); + return holder.isDeleteHolding() + ? pieceUpdateInventoryService.deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext) + : Future.succeededFuture(); } private Future handleHolding(PieceUpdateHolder holder, RequestContext requestContext) { - CompositePoLine poLineToSave = holder.getPoLineToSave(); - Piece pieceToUpdate = holder.getPieceToUpdate(); + var pieceToUpdate = holder.getPieceToUpdate(); if (pieceToUpdate.getHoldingId() != null) { return Future.succeededFuture(new Location().withHoldingId(pieceToUpdate.getHoldingId())); } - String instanceId = holder.getInstanceId(); - if (instanceId != null && DefaultPieceFlowsValidator.isCreateHoldingForPiecePossible(pieceToUpdate, poLineToSave)) { - return inventoryHoldingManager.createHoldingAndReturnId(instanceId, pieceToUpdate.getLocationId(), requestContext) - .map(holdingId -> { - Location location = new Location().withLocationId(pieceToUpdate.getLocationId()); - Optional.ofNullable(holdingId).ifPresent(holdingIdP -> { - pieceToUpdate.setLocationId(null); - pieceToUpdate.setHoldingId(holdingId); - location.setLocationId(null); - location.setHoldingId(holdingId); - }); - return location; - }); + + var poLineToSave = holder.getPoLineToSave(); + var instanceId = holder.getInstanceId(); + var location = new Location().withLocationId(pieceToUpdate.getLocationId()); + if (instanceId == null || !DefaultPieceFlowsValidator.isCreateHoldingForPiecePossible(pieceToUpdate, poLineToSave)) { + return Future.succeededFuture(location); } - return Future.succeededFuture(new Location().withLocationId(pieceToUpdate.getLocationId())); + return inventoryHoldingManager.createHoldingAndReturnId(instanceId, pieceToUpdate.getLocationId(), requestContext) + .map(holdingId -> { + if (holdingId != null) { + pieceToUpdate.withLocationId(null).setHoldingId(holdingId); + location.withLocationId(null).setHoldingId(holdingId); + } + return location; + }); } private Future handleItem(PieceUpdateHolder holder, RequestContext requestContext) { @@ -122,37 +112,23 @@ private Future handleItem(PieceUpdateHolder holder, RequestContext reque } return inventoryItemManager.getItemRecordById(pieceToUpdate.getItemId(), true, requestContext) .compose(jsonItem -> { - boolean jsonItemFound = jsonItem != null && !jsonItem.isEmpty(); - if (holder.isCreateItem() && !jsonItemFound && pieceToUpdate.getHoldingId() != null) { - return pieceUpdateInventoryService.manualPieceFlowCreateItemRecord(pieceToUpdate, poLineToSave, requestContext); - } - if (jsonItemFound) { - return updateItemWithFields(jsonItem, poLineToSave, pieceToUpdate) - .compose(ignored -> inventoryItemManager.updateItem(jsonItem, requestContext).map(item -> jsonItem.getString(ID))); + if (jsonItem != null && !jsonItem.isEmpty()) { + updateItemWithFields(jsonItem, poLineToSave, pieceToUpdate); + return inventoryItemManager.updateItem(jsonItem, requestContext) + .map(v -> jsonItem.getString(ID)); } - return Future.succeededFuture(); - }); - } - private Future updateItemWithFields(JsonObject item, CompositePoLine compPOL, Piece piece) { - Optional.ofNullable(piece.getHoldingId()) - .ifPresent(pieceHoldingId -> item.put(ITEM_HOLDINGS_RECORD_ID, piece.getHoldingId())); - item.put(ITEM_PURCHASE_ORDER_LINE_IDENTIFIER, compPOL.getId()); - return Future.succeededFuture(); + return holder.isCreateItem() && pieceToUpdate.getHoldingId() != null + ? pieceUpdateInventoryService.manualPieceFlowCreateItemRecord(pieceToUpdate, poLineToSave, requestContext) + : Future.succeededFuture(); + }); } - private Future nonPackageUpdateTitleWithInstance(PieceUpdateHolder holder, RequestContext requestContext) { - CompositePoLine poLineToSave = holder.getPoLineToSave(); - Piece pieceToUpdate = holder.getPieceToUpdate(); - if (poLineToSave.getInstanceId() != null || PoLineCommonUtil.isInventoryUpdateNotRequired(poLineToSave)) { - return Future.succeededFuture(poLineToSave.getInstanceId()); + private void updateItemWithFields(JsonObject item, CompositePoLine compPOL, Piece piece) { + if (piece.getHoldingId() != null) { + item.put(ITEM_HOLDINGS_RECORD_ID, piece.getHoldingId()); } - return titlesService.getTitleById(pieceToUpdate.getTitleId(), requestContext) - .compose(title -> titlesService.updateTitleWithInstance(title, requestContext)) - .map(instanceId -> poLineToSave.withInstanceId(instanceId).getInstanceId()); + item.put(ITEM_PURCHASE_ORDER_LINE_IDENTIFIER, compPOL.getId()); } - private Future packageUpdateTitleWithInstance(Title title, RequestContext requestContext) { - return titlesService.updateTitleWithInstance(title, requestContext); - } } diff --git a/src/main/java/org/folio/service/titles/TitleInstanceService.java b/src/main/java/org/folio/service/titles/TitleInstanceService.java index 41b48088b..795dbad4c 100644 --- a/src/main/java/org/folio/service/titles/TitleInstanceService.java +++ b/src/main/java/org/folio/service/titles/TitleInstanceService.java @@ -33,7 +33,8 @@ private Future createShadowInstance(String instanceId, RequestContext re private Future createInventoryInstance(String shadowInstId, Title title, boolean isInstanceMatchingDisabled, RequestContext requestContext) { if (shadowInstId != null) { return Future.succeededFuture(shadowInstId); - } else if (title.getInstanceId() != null) { + } + if (title.getInstanceId() != null) { return Future.succeededFuture(title.getInstanceId()); } return inventoryInstanceManager.getOrCreateInstanceRecord(title, isInstanceMatchingDisabled, requestContext); diff --git a/src/main/java/org/folio/service/titles/TitlesService.java b/src/main/java/org/folio/service/titles/TitlesService.java index 8bd6a1fe6..a6677a92f 100644 --- a/src/main/java/org/folio/service/titles/TitlesService.java +++ b/src/main/java/org/folio/service/titles/TitlesService.java @@ -126,17 +126,17 @@ public Future>> fetchNonPackageTitles(CompositePurchaseO return getTitlesByPoLineIds(lineIds, requestContext); } - private List getNonPackageLineIds(List compositePoLines) { return compositePoLines.stream().filter(line -> !line.getIsPackage()).map(CompositePoLine::getId).collect(toList()); } - public Future updateTitleWithInstance(Title title, RequestContext requestContext) { - return updateTitleWithInstance(title, false, requestContext); + public Future updateTitleWithInstance(String titleId, RequestContext locationContext, RequestContext requestContext) { + return getTitleById(titleId, requestContext) + .compose(title -> updateTitleWithInstance(title, false, locationContext, requestContext)); } - public Future updateTitleWithInstance(Title title, boolean isInstanceMatchingDisabled, RequestContext requestContext) { - return titleInstanceService.getOrCreateInstance(title, isInstanceMatchingDisabled, requestContext) + public Future updateTitleWithInstance(Title title, boolean isInstanceMatchingDisabled, RequestContext locationContext, RequestContext requestContext) { + return titleInstanceService.getOrCreateInstance(title, isInstanceMatchingDisabled, locationContext) .map(title::withInstanceId) .compose(entity -> saveTitle(entity, requestContext) .map(v -> entity.getInstanceId())); diff --git a/src/test/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderPieceServiceTest.java b/src/test/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderPieceServiceTest.java index d4eebf89f..989ca4e2f 100644 --- a/src/test/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderPieceServiceTest.java +++ b/src/test/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderPieceServiceTest.java @@ -205,7 +205,7 @@ void testUpdateInventoryPositiveCaseIfPOLIsPackage() { SharingInstance sharingInstance = new SharingInstance(UUID.randomUUID(), UUID.randomUUID().toString(), UUID.randomUUID().toString()); doReturn(succeededFuture(title)).when(titlesService).getTitleById(piece.getTitleId(), requestContext); - doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title), anyBoolean(), eq(requestContext)); + doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title), anyBoolean(), eq(requestContext), eq(requestContext)); doReturn(succeededFuture(sharingInstance)) .when(inventoryInstanceManager).createShadowInstanceIfNeeded(eq(instanceId), any(String.class), eq(requestContext)); @@ -238,7 +238,7 @@ void testShouldUpdateInventoryPositiveCaseIfLineIsPackageAndPieceContainsHolding doReturn(succeededFuture(title)).when(titlesService).getTitleById(piece.getTitleId(), requestContext); doReturn(succeededFuture(itemId)).when(inventoryItemManager).openOrderCreateItemRecord(line, holdingId, requestContext); - doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title), anyBoolean(), eq(requestContext)); + doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title), anyBoolean(), eq(requestContext), eq(requestContext)); //When openCompositeOrderPieceService.openOrderUpdateInventory(line, piece, false, requestContext).result(); diff --git a/src/test/java/org/folio/service/pieces/flows/create/PieceCreateFlowInventoryManagerTest.java b/src/test/java/org/folio/service/pieces/flows/create/PieceCreateFlowInventoryManagerTest.java index 0618dd050..f7a229bf4 100644 --- a/src/test/java/org/folio/service/pieces/flows/create/PieceCreateFlowInventoryManagerTest.java +++ b/src/test/java/org/folio/service/pieces/flows/create/PieceCreateFlowInventoryManagerTest.java @@ -115,7 +115,7 @@ void testPieceCreateForPackagePoLineWithCreateInventoryInstanceHoldingItem() { String instanceId = UUID.randomUUID().toString(); Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(instanceId); - Piece piece = new Piece().withId(pieceId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.ELECTRONIC); + Piece piece = new Piece().withId(pieceId).withTitleId(titleId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.ELECTRONIC); Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1); Cost cost = new Cost().withQuantityElectronic(1) .withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD") @@ -129,8 +129,7 @@ void testPieceCreateForPackagePoLineWithCreateInventoryInstanceHoldingItem() { doReturn(succeededFuture(piece)).when(pieceStorageService).getPieceById(pieceId, requestContext); doReturn(succeededFuture(List.of(piece))).when(pieceStorageService).getPiecesByHoldingId(piece.getId(), requestContext); - doReturn(succeededFuture(title)).when(titlesService).getTitleById(piece.getTitleId(), requestContext); - doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title), eq(requestContext)); + doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title.getId()), eq(requestContext), eq(requestContext)); doReturn(succeededFuture(itemId)).when(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(piece, compPOL, requestContext); doReturn(succeededFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(piece, requestContext); @@ -143,7 +142,7 @@ void testPieceCreateForPackagePoLineWithCreateInventoryInstanceHoldingItem() { assertEquals(itemId, piece.getItemId()); assertEquals(holdingId, piece.getHoldingId()); - verify(titlesService).getTitleById(piece.getTitleId(), requestContext); + verify(titlesService).updateTitleWithInstance(piece.getTitleId(), requestContext, requestContext); verify(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(piece, compPOL, requestContext); } @@ -158,7 +157,7 @@ void testShouldNotCreateHoldingPieceCreateForPackagePoLineWithCreateInventoryIns String instanceId = UUID.randomUUID().toString(); Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(instanceId); - Piece piece = new Piece().withId(pieceId).withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC); + Piece piece = new Piece().withId(pieceId).withTitleId(titleId).withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC); Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantity(1); Cost cost = new Cost().withQuantityElectronic(1) .withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD") @@ -171,8 +170,7 @@ void testShouldNotCreateHoldingPieceCreateForPackagePoLineWithCreateInventoryIns .withLocations(List.of(loc)).withCost(cost); CompositePurchaseOrder compositePurchaseOrder = new CompositePurchaseOrder().withId(orderId).withCompositePoLines(List.of(compPOL)); doReturn(succeededFuture(piece)).when(pieceStorageService).getPieceById(pieceId, requestContext); - doReturn(succeededFuture(title)).when(titlesService).getTitleById(piece.getTitleId(), requestContext); - doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title), eq(requestContext)); + doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title.getId()), eq(requestContext), eq(requestContext)); PieceCreationHolder holder = new PieceCreationHolder().withPieceToCreate(piece).withCreateItem(true); holder.withOrderInformation(compositePurchaseOrder); @@ -184,7 +182,7 @@ void testShouldNotCreateHoldingPieceCreateForPackagePoLineWithCreateInventoryIns assertNull(piece.getItemId()); assertNull(piece.getHoldingId()); assertEquals(locationId, piece.getLocationId()); - verify(titlesService).getTitleById(piece.getTitleId(), requestContext); + verify(titlesService).updateTitleWithInstance(piece.getTitleId(), requestContext, requestContext); verify(pieceUpdateInventoryService, times(0)).manualPieceFlowCreateItemRecord(piece, compPOL, requestContext); } @@ -200,7 +198,7 @@ void testShouldNotCreateHoldingPieceCreateForNonPackagePoLineWithCreateInventory String instanceId = UUID.randomUUID().toString(); Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(instanceId); - Piece piece = new Piece().withId(pieceId).withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC); + Piece piece = new Piece().withId(pieceId).withTitleId(titleId).withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC); Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantity(1); Cost cost = new Cost().withQuantityElectronic(1) .withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD") @@ -212,8 +210,7 @@ void testShouldNotCreateHoldingPieceCreateForNonPackagePoLineWithCreateInventory .withLocations(List.of(loc)).withCost(cost); CompositePurchaseOrder compositePurchaseOrder = new CompositePurchaseOrder().withId(orderId).withCompositePoLines(List.of(compPOL)); doReturn(succeededFuture(piece)).when(pieceStorageService).getPieceById(pieceId, requestContext); - doReturn(succeededFuture(title)).when(titlesService).getTitleById(piece.getTitleId(), requestContext); - doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title), eq(requestContext)); + doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title.getId()), eq(requestContext), eq(requestContext)); PieceCreationHolder holder = new PieceCreationHolder().withPieceToCreate(piece).withCreateItem(true); holder.withOrderInformation(compositePurchaseOrder); @@ -225,7 +222,7 @@ void testShouldNotCreateHoldingPieceCreateForNonPackagePoLineWithCreateInventory assertNull(piece.getItemId()); assertNull(piece.getHoldingId()); assertEquals(locationId, piece.getLocationId()); - verify(titlesService).getTitleById(piece.getTitleId(), requestContext); + verify(titlesService).updateTitleWithInstance(piece.getTitleId(), requestContext, requestContext); verify(pieceUpdateInventoryService, times(0)).manualPieceFlowCreateItemRecord(piece, compPOL, requestContext); } diff --git a/src/test/java/org/folio/service/pieces/flows/delete/PieceDeleteFlowManagerTest.java b/src/test/java/org/folio/service/pieces/flows/delete/PieceDeleteFlowManagerTest.java index 727062fe9..07848cb01 100644 --- a/src/test/java/org/folio/service/pieces/flows/delete/PieceDeleteFlowManagerTest.java +++ b/src/test/java/org/folio/service/pieces/flows/delete/PieceDeleteFlowManagerTest.java @@ -49,6 +49,7 @@ import org.folio.service.ProtectionService; import org.folio.service.inventory.InventoryHoldingManager; import org.folio.service.inventory.InventoryItemManager; +import org.folio.service.pieces.PieceDeleteInventoryService; import org.folio.service.pieces.PieceStorageService; import org.folio.service.pieces.PieceUpdateInventoryService; import org.folio.service.pieces.flows.BasePieceFlowHolderBuilder; @@ -408,15 +409,25 @@ public CirculationRequestsRetriever circulationRequestsRetriever() { return mock(CirculationRequestsRetriever.class); } - @Bean PieceDeleteFlowManager pieceDeleteFlowManager(PieceStorageService pieceStorageService, + @Bean + PieceDeleteInventoryService pieceDeleteInventoryService(InventoryItemManager inventoryItemManager) { + return new PieceDeleteInventoryService(inventoryItemManager); + } + + @Bean + PieceDeleteFlowInventoryManager pieceDeleteFlowInventoryManager(PieceDeleteInventoryService pieceDeleteInventoryService, + PieceUpdateInventoryService pieceUpdateInventoryService) { + return new PieceDeleteFlowInventoryManager(pieceDeleteInventoryService, pieceUpdateInventoryService); + } + + @Bean PieceDeleteFlowManager pieceDeleteFlowManager(PieceDeleteFlowInventoryManager pieceDeleteFlowInventoryManager, + PieceStorageService pieceStorageService, ProtectionService protectionService, - InventoryItemManager inventoryItemManager, - PieceUpdateInventoryService pieceUpdateInventoryService, PieceDeleteFlowPoLineService pieceDeleteFlowPoLineService, BasePieceFlowHolderBuilder basePieceFlowHolderBuilder, CirculationRequestsRetriever circulationRequestsRetriever) { - return new PieceDeleteFlowManager(pieceStorageService, protectionService, inventoryItemManager, - pieceUpdateInventoryService, pieceDeleteFlowPoLineService, basePieceFlowHolderBuilder, circulationRequestsRetriever); + return new PieceDeleteFlowManager(pieceDeleteFlowInventoryManager, pieceStorageService, protectionService, + pieceDeleteFlowPoLineService, basePieceFlowHolderBuilder, circulationRequestsRetriever); } } diff --git a/src/test/java/org/folio/service/pieces/flows/update/PieceUpdateFlowInventoryManagerTest.java b/src/test/java/org/folio/service/pieces/flows/update/PieceUpdateFlowInventoryManagerTest.java index 221ed9b43..b691f536b 100644 --- a/src/test/java/org/folio/service/pieces/flows/update/PieceUpdateFlowInventoryManagerTest.java +++ b/src/test/java/org/folio/service/pieces/flows/update/PieceUpdateFlowInventoryManagerTest.java @@ -31,7 +31,6 @@ import org.folio.ApiTestSuite; import org.folio.models.ItemStatus; -import org.folio.models.consortium.SharingInstance; import org.folio.models.pieces.PieceUpdateHolder; import org.folio.rest.core.models.RequestContext; import org.folio.rest.jaxrs.model.Cost; @@ -152,11 +151,11 @@ void shouldDeleteHoldingWhenElecPieceUpdateForPackagePoLineWithCreateInventoryAl doReturn(succeededFuture(new ArrayList())).when(inventoryItemManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext); doReturn(succeededFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); doReturn(succeededFuture(itemId)).when(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext); - doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title), eq(requestContext)); + doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title.getId()), eq(requestContext), eq(requestContext)); pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).result(); - verify(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext); + verify(titlesService).updateTitleWithInstance(pieceToUpdate.getTitleId(), requestContext, requestContext); verify(inventoryHoldingManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext)); verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); verify(inventoryItemManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext); @@ -201,11 +200,11 @@ void shouldDeleteHoldingWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAl doReturn(succeededFuture(new ArrayList())).when(inventoryItemManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext); doReturn(succeededFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); doReturn(succeededFuture(itemId)).when(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext); - doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title), eq(requestContext)); + doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title.getId()), eq(requestContext), eq(requestContext)); pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).result(); - verify(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext); + verify(titlesService).updateTitleWithInstance(pieceToUpdate.getTitleId(), requestContext, requestContext); verify(inventoryHoldingManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext)); verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); verify(inventoryItemManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext); @@ -251,11 +250,11 @@ void shouldDeleteHoldingWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAl doReturn(succeededFuture(new ArrayList())).when(inventoryItemManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext); doReturn(succeededFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); doReturn(succeededFuture(itemId)).when(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext); - doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title), eq(requestContext)); + doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title.getId()), eq(requestContext), eq(requestContext)); pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).result(); - verify(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext); + verify(titlesService).updateTitleWithInstance(pieceToUpdate.getTitleId(), requestContext, requestContext); verify(inventoryHoldingManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext)); verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); verify(inventoryItemManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext); @@ -304,13 +303,13 @@ void shouldUpdateItemWithNewHoldingIdWhenPhysPieceUpdateForPackagePoLineWithCrea doReturn(succeededFuture(holding)).when(inventoryHoldingManager).getHoldingById(holder.getPieceFromStorage().getHoldingId(), true, requestContext); doReturn(succeededFuture(new ArrayList())).when(inventoryItemManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext); doReturn(succeededFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); - doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title), eq(requestContext)); + doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title.getId()), eq(requestContext), eq(requestContext)); pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).result(); assertEquals(holdingId, item.getString(ITEM_HOLDINGS_RECORD_ID)); assertEquals(holder.getPoLineToSave().getId(), item.getString(ITEM_PURCHASE_ORDER_LINE_IDENTIFIER)); - verify(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext); + verify(titlesService).updateTitleWithInstance(pieceToUpdate.getTitleId(), requestContext, requestContext); verify(inventoryHoldingManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext)); verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); verify(inventoryItemManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext); @@ -358,11 +357,11 @@ void shouldDeleteHoldingWhenElecPieceUpdateForNonPackagePoLineWithCreateInventor doReturn(succeededFuture(new ArrayList())).when(inventoryItemManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext); doReturn(succeededFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); doReturn(succeededFuture(itemId)).when(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext); - doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title), eq(requestContext)); + doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title.getId()), eq(requestContext), eq(requestContext)); pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).result(); - verify(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext); + verify(titlesService).updateTitleWithInstance(pieceToUpdate.getTitleId(), requestContext, requestContext); verify(inventoryHoldingManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext)); verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); verify(inventoryItemManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext); @@ -407,11 +406,11 @@ void shouldDeleteHoldingWhenPhysPieceUpdateForNonPackagePoLineWithCreateInventor doReturn(succeededFuture(new ArrayList())).when(inventoryItemManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext); doReturn(succeededFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); doReturn(succeededFuture(itemId)).when(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext); - doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title), eq(requestContext)); + doReturn(succeededFuture(instanceId)).when(titlesService).updateTitleWithInstance(eq(title.getId()), eq(requestContext), eq(requestContext)); pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).result(); - verify(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext); + verify(titlesService).updateTitleWithInstance(pieceToUpdate.getTitleId(), requestContext, requestContext); verify(inventoryHoldingManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext)); verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); verify(inventoryItemManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext); @@ -458,7 +457,7 @@ void shouldDeleteHoldingWhenPhysPieceUpdateForNonPackagePoLineWithCreateInventor pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).result(); - verify(titlesService, times(0)).getTitleById(pieceToUpdate.getTitleId(), requestContext); + verify(titlesService, times(0)).updateTitleWithInstance(pieceToUpdate.getTitleId(), requestContext, requestContext); verify(inventoryHoldingManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext)); verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); verify(inventoryItemManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext); @@ -511,7 +510,7 @@ void shouldUpdateItemWithNewHoldingIdWhenPhysPieceUpdateForNonPackagePoLineWithC assertEquals(holdingId, item.getString(ITEM_HOLDINGS_RECORD_ID)); assertEquals(holder.getPoLineToSave().getId(), item.getString(ITEM_PURCHASE_ORDER_LINE_IDENTIFIER)); - verify(titlesService, times(0)).getTitleById(pieceToUpdate.getTitleId(), requestContext); + verify(titlesService, times(0)).updateTitleWithInstance(pieceToUpdate.getTitleId(), requestContext, requestContext); verify(inventoryHoldingManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext)); verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext); verify(inventoryItemManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);