use of org.folio.service.inventory.InventoryManager.HOLDING_PERMANENT_LOCATION_ID in project mod-orders by folio-org.
the class PieceDeleteFlowManagerTest method shouldUpdateLineQuantityIfPoLineIsNotPackageAndManualPieceCreateFalseAndInventoryInstanceVsHoldingAndDeleteHoldingAndPiece.
@Test
void shouldUpdateLineQuantityIfPoLineIsNotPackageAndManualPieceCreateFalseAndInventoryInstanceVsHoldingAndDeleteHoldingAndPiece() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String itemId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
JsonObject holding = new JsonObject();
holding.put(ID, holdingId);
holding.put(HOLDING_PERMANENT_LOCATION_ID, locationId);
JsonObject item = new JsonObject().put(ID, itemId);
item.put(ITEM_STATUS, new JsonObject().put(ITEM_STATUS_NAME, ItemStatus.ON_ORDER.value()));
Piece piece = new Piece().withId(UUID.randomUUID().toString()).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1).withListUnitPriceElectronic(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
PoLine poLine = new PoLine().withIsPackage(false).withCheckinItems(false).withOrderFormat(PoLine.OrderFormat.ELECTRONIC_RESOURCE).withEresource(new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING)).withPurchaseOrderId(orderId).withId(lineId).withLocations(List.of(loc)).withCost(cost);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
doReturn(completedFuture(piece)).when(pieceStorageService).getPieceById(piece.getId(), requestContext);
doReturn(completedFuture(null)).when(protectionService).isOperationRestricted(any(List.class), any(ProtectedOperationType.class), eq(requestContext));
doReturn(completedFuture(null)).when(pieceStorageService).deletePiece(eq(piece.getId()), eq(true), eq(requestContext));
doReturn(completedFuture(null)).when(inventoryManager).getNumberOfRequestsByItemId(eq(piece.getItemId()), eq(requestContext));
doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holdingId, requestContext);
doReturn(completedFuture(null)).when(inventoryManager).getItemsByHoldingId(holdingId, requestContext);
doReturn(completedFuture(null)).when(inventoryManager).deleteHoldingById(piece.getHoldingId(), true, requestContext);
doReturn(completedFuture(null)).when(inventoryManager).getItemRecordById(itemId, true, requestContext);
doReturn(completedFuture(null)).when(inventoryManager).deleteItem(itemId, true, requestContext);
doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holdingId, true, requestContext);
doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(piece, requestContext);
doReturn(completedFuture(new ArrayList())).when(inventoryManager).getItemsByHoldingId(holdingId, requestContext);
final ArgumentCaptor<PieceDeletionHolder> PieceDeletionHolderCapture = ArgumentCaptor.forClass(PieceDeletionHolder.class);
doAnswer((Answer<CompletableFuture<Void>>) invocation -> {
PieceDeletionHolder answerHolder = invocation.getArgument(0);
answerHolder.withOrderInformation(purchaseOrder, poLine);
return completedFuture(null);
}).when(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(PieceDeletionHolderCapture.capture(), eq(requestContext));
final ArgumentCaptor<PieceDeletionHolder> pieceDeletionHolderCapture = ArgumentCaptor.forClass(PieceDeletionHolder.class);
doReturn(completedFuture(null)).when(pieceDeleteFlowPoLineService).updatePoLine(pieceDeletionHolderCapture.capture(), eq(requestContext));
// When
pieceDeleteFlowManager.deletePiece(piece.getId(), true, requestContext).get();
// Then
PieceDeletionHolder holder = PieceDeletionHolderCapture.getValue();
verify(pieceStorageService).deletePiece(eq(piece.getId()), eq(true), eq(requestContext));
verify(inventoryManager, times(0)).deleteItem(itemId, true, requestContext);
verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(piece, requestContext);
verify(pieceStorageService, times(1)).deletePiece(eq(piece.getId()), eq(true), eq(requestContext));
verify(pieceDeleteFlowPoLineService).updatePoLine(pieceDeletionHolderCapture.capture(), eq(requestContext));
verify(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(holder, requestContext);
}
use of org.folio.service.inventory.InventoryManager.HOLDING_PERMANENT_LOCATION_ID in project mod-orders by folio-org.
the class InventoryInteractionTestHelper method verifyOpenOrderPiecesCreated.
public static void verifyOpenOrderPiecesCreated(List<JsonObject> inventoryItems, List<CompositePoLine> compositePoLines, List<JsonObject> pieceJsons, int expectedWithItemQty) {
// Collect all item id's
List<String> itemIds = inventoryItems.stream().map(item -> item.getString(ID)).collect(Collectors.toList());
List<Piece> pieces = pieceJsons.stream().map(pieceObj -> pieceObj.mapTo(Piece.class)).collect(Collectors.toList());
// Verify quantity of created pieces
int totalForAllPoLines = 0;
for (CompositePoLine poLine : compositePoLines) {
Map<String, List<JsonObject>> createdHoldingsByLocationId = getCreatedHoldings().stream().filter(json -> json.getString("instanceId").equals(poLine.getInstanceId())).collect(groupingBy(json -> json.getString(HOLDING_PERMANENT_LOCATION_ID)));
List<Location> locations = poLine.getLocations().stream().filter(location -> PoLineCommonUtil.isHoldingCreationRequiredForLocation(poLine, location) && !Objects.equals(location.getLocationId(), ID_FOR_INTERNAL_SERVER_ERROR)).collect(Collectors.toList());
// Prepare data first
// Calculated quantities
int expectedElQty = 0;
int expectedPhysQty = 0;
int expectedOthQty = 0;
if (poLine.getCheckinItems() == null || !poLine.getCheckinItems()) {
if (poLine.getOrderFormat() == CompositePoLine.OrderFormat.OTHER) {
// calculatePiecesQuantity(Piece.Format.OTHER, locations);
expectedOthQty += getPhysicalCostQuantity(poLine);
} else {
// calculatePiecesQuantity(Piece.Format.PHYSICAL, locations);
expectedPhysQty += getPhysicalCostQuantity(poLine);
}
// calculatePiecesQuantity(Piece.Format.ELECTRONIC, locations);
expectedElQty = getElectronicCostQuantity(poLine);
}
int expectedWithoutItemQty = calculateInventoryItemsQuantity(poLine, locations);
int expectedWithoutLocation = calculatePiecesQuantityWithoutLocation(poLine).values().stream().mapToInt(Integer::intValue).sum();
// Prepare pieces for PO Line
List<Piece> poLinePieces = pieces.stream().filter(piece -> piece.getPoLineId().equals(poLine.getId())).collect(Collectors.toList());
Map<String, Long> piecesByLocationIdQuantity = poLinePieces.stream().filter(piece -> Objects.nonNull(piece.getLocationId())).collect(groupingBy(Piece::getLocationId, Collectors.counting()));
int expectedTotal = expectedWithItemQty + expectedWithoutItemQty + expectedWithoutLocation;
// Make sure that quantities by piece type and by item presence are the same
assertThat(expectedPhysQty + expectedElQty + expectedOthQty, is(expectedTotal));
assertThat(poLinePieces, hasSize(expectedTotal));
// Verify each piece individually
poLinePieces.forEach(piece -> {
// Check if itemId in inventoryItems match itemId in piece record
if (poLine.getCheckinItems() != null && Boolean.FALSE.equals(poLine.getCheckinItems())) {
if (piece.getLocationId() != null) {
String pieceLocationId = piece.getLocationId();
List<JsonObject> createdHoldingsForLocation = createdHoldingsByLocationId.get(pieceLocationId);
assertNotNull(createdHoldingsForLocation);
}
}
assertThat(piece.getReceivingStatus(), equalTo(Piece.ReceivingStatus.EXPECTED));
if (piece.getItemId() != null) {
assertThat(itemIds, hasItem(piece.getItemId()));
}
assertThat(piece.getFormat(), notNullValue());
});
totalForAllPoLines += expectedTotal;
}
// Make sure that none of pieces missed
assertThat(pieceJsons, hasSize(totalForAllPoLines));
}
use of org.folio.service.inventory.InventoryManager.HOLDING_PERMANENT_LOCATION_ID in project mod-orders by folio-org.
the class InventoryManagerTest method shouldCheckIfTheHoldingExistsWhenLocationIdAlwaysNewHoldingShouldBeCreated.
@Test
void shouldCheckIfTheHoldingExistsWhenLocationIdAlwaysNewHoldingShouldBeCreated() throws IOException {
String instanceId = UUID.randomUUID().toString();
JsonObject holdingsCollection = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH));
String holdingIdExp = extractId(getFirstObjectFromResponse(holdingsCollection, HOLDINGS_RECORDS));
List<JsonObject> holdings = holdingsCollection.getJsonArray(HOLDINGS_RECORDS).stream().map(o -> ((JsonObject) o)).collect(toList());
List<String> locationIds = holdings.stream().map(holding -> holding.getString(HOLDING_PERMANENT_LOCATION_ID)).collect(toList());
Location location = new Location().withLocationId(locationIds.get(0)).withQuantity(1).withQuantityPhysical(1);
doReturn(completedFuture(holdingIdExp)).when(restClient).post(any(RequestEntry.class), any(JsonObject.class), eq(PostResponseType.UUID), eq(String.class), eq(requestContext));
String holdingIdAct = inventoryManager.getOrCreateHoldingsRecord(instanceId, location, requestContext).join();
assertThat(holdingIdAct, equalTo(holdingIdExp));
verify(restClient, times(1)).post(any(RequestEntry.class), any(JsonObject.class), eq(PostResponseType.UUID), eq(String.class), eq(requestContext));
}
use of org.folio.service.inventory.InventoryManager.HOLDING_PERMANENT_LOCATION_ID in project mod-orders by folio-org.
the class PieceDeleteFlowManagerTest method shouldNotUpdateLineQuantityIfPoLineIsPackageAndShouldDeleteHoldingAndItemAndPiece.
@Test
void shouldNotUpdateLineQuantityIfPoLineIsPackageAndShouldDeleteHoldingAndItemAndPiece() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
String itemId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
JsonObject item = new JsonObject().put(ID, itemId);
item.put(ITEM_STATUS, new JsonObject().put(ITEM_STATUS_NAME, ItemStatus.ON_ORDER.value()));
JsonObject holding = new JsonObject().put(ID, holdingId);
holding.put(HOLDING_PERMANENT_LOCATION_ID, locationId);
Piece piece = new Piece().withId(UUID.randomUUID().toString()).withPoLineId(lineId).withItemId(itemId).withTitleId(titleId).withHoldingId(holdingId).withFormat(Piece.Format.ELECTRONIC);
Cost cost = new Cost().withQuantityElectronic(1).withListUnitPriceElectronic(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
PoLine poLine = new PoLine().withIsPackage(true).withPurchaseOrderId(orderId).withId(lineId).withLocations(List.of(loc)).withCost(cost);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
doReturn(completedFuture(piece)).when(pieceStorageService).getPieceById(piece.getId(), requestContext);
doReturn(completedFuture(null)).when(protectionService).isOperationRestricted(any(List.class), any(ProtectedOperationType.class), eq(requestContext));
doReturn(completedFuture(null)).when(pieceStorageService).deletePiece(eq(piece.getId()), eq(true), eq(requestContext));
doReturn(completedFuture(null)).when(inventoryManager).getNumberOfRequestsByItemId(eq(piece.getItemId()), eq(requestContext));
doReturn(completedFuture(item)).when(inventoryManager).getItemRecordById(itemId, true, requestContext);
doReturn(completedFuture(null)).when(inventoryManager).deleteItem(itemId, true, requestContext);
final ArgumentCaptor<PieceDeletionHolder> PieceDeletionHolderCapture = ArgumentCaptor.forClass(PieceDeletionHolder.class);
doAnswer((Answer<CompletableFuture<Void>>) invocation -> {
PieceDeletionHolder answerHolder = invocation.getArgument(0);
answerHolder.withOrderInformation(purchaseOrder, poLine);
return completedFuture(null);
}).when(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(PieceDeletionHolderCapture.capture(), eq(requestContext));
doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holdingId, true, requestContext);
doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(piece, requestContext);
doReturn(completedFuture(new ArrayList())).when(inventoryManager).getItemsByHoldingId(holdingId, requestContext);
final ArgumentCaptor<PieceDeletionHolder> pieceDeletionHolderCapture = ArgumentCaptor.forClass(PieceDeletionHolder.class);
doReturn(completedFuture(null)).when(pieceDeleteFlowPoLineService).updatePoLine(pieceDeletionHolderCapture.capture(), eq(requestContext));
// When
pieceDeleteFlowManager.deletePiece(piece.getId(), true, requestContext).get();
// Then
PieceDeletionHolder holder = PieceDeletionHolderCapture.getValue();
assertNull(poLine.getLocations().get(0).getLocationId());
assertEquals(holdingId, poLine.getLocations().get(0).getHoldingId());
verify(pieceStorageService).deletePiece(eq(piece.getId()), eq(true), eq(requestContext));
verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(piece, requestContext);
// Then
assertNull(poLine.getLocations().get(0).getLocationId());
assertEquals(holdingId, poLine.getLocations().get(0).getHoldingId());
verify(pieceDeleteFlowPoLineService, times(0)).updatePoLine(pieceDeletionHolderCapture.capture(), eq(requestContext));
verify(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(holder, requestContext);
}
use of org.folio.service.inventory.InventoryManager.HOLDING_PERMANENT_LOCATION_ID in project mod-orders by folio-org.
the class PieceDeleteFlowManagerTest method shouldNotUpdateLineQuantityIfPoLineIsNotPackageAndManualPieceCreateTrueAndDeleteHoldingAndItemAndPiece.
@Test
void shouldNotUpdateLineQuantityIfPoLineIsNotPackageAndManualPieceCreateTrueAndDeleteHoldingAndItemAndPiece() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
String itemId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
JsonObject item = new JsonObject().put(ID, itemId);
item.put(ITEM_STATUS, new JsonObject().put(ITEM_STATUS_NAME, ItemStatus.ON_ORDER.value()));
JsonObject holding = new JsonObject().put(ID, holdingId);
holding.put(HOLDING_PERMANENT_LOCATION_ID, locationId);
Piece piece = new Piece().withId(UUID.randomUUID().toString()).withPoLineId(lineId).withItemId(itemId).withTitleId(titleId).withHoldingId(holdingId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1).withListUnitPriceElectronic(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
PoLine poLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withId(lineId).withLocations(List.of(loc)).withCost(cost).withCheckinItems(true);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
doReturn(completedFuture(piece)).when(pieceStorageService).getPieceById(piece.getId(), requestContext);
doReturn(completedFuture(null)).when(protectionService).isOperationRestricted(any(List.class), any(ProtectedOperationType.class), eq(requestContext));
doReturn(completedFuture(null)).when(pieceStorageService).deletePiece(eq(piece.getId()), eq(true), eq(requestContext));
doReturn(completedFuture(null)).when(inventoryManager).getNumberOfRequestsByItemId(eq(piece.getItemId()), eq(requestContext));
doReturn(completedFuture(item)).when(inventoryManager).getItemRecordById(itemId, true, requestContext);
doReturn(completedFuture(null)).when(inventoryManager).deleteItem(itemId, true, requestContext);
doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holdingId, true, requestContext);
doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(piece, requestContext);
doReturn(completedFuture(new ArrayList())).when(inventoryManager).getItemsByHoldingId(holdingId, requestContext);
final ArgumentCaptor<PieceDeletionHolder> PieceDeletionHolderCapture = ArgumentCaptor.forClass(PieceDeletionHolder.class);
doAnswer((Answer<CompletableFuture<Void>>) invocation -> {
PieceDeletionHolder answerHolder = invocation.getArgument(0);
answerHolder.withOrderInformation(purchaseOrder, poLine);
return completedFuture(null);
}).when(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(PieceDeletionHolderCapture.capture(), eq(requestContext));
final ArgumentCaptor<PieceDeletionHolder> pieceDeletionHolderCapture = ArgumentCaptor.forClass(PieceDeletionHolder.class);
doReturn(completedFuture(null)).when(pieceDeleteFlowPoLineService).updatePoLine(pieceDeletionHolderCapture.capture(), eq(requestContext));
// When
pieceDeleteFlowManager.deletePiece(piece.getId(), true, requestContext).get();
// Then
PieceDeletionHolder holder = PieceDeletionHolderCapture.getValue();
assertNull(poLine.getLocations().get(0).getLocationId());
assertEquals(holdingId, poLine.getLocations().get(0).getHoldingId());
verify(pieceStorageService).deletePiece(eq(piece.getId()), eq(true), eq(requestContext));
verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(piece, requestContext);
verify(inventoryManager).deleteItem(itemId, true, requestContext);
verify(pieceDeleteFlowPoLineService, times(0)).updatePoLine(pieceDeletionHolderCapture.capture(), eq(requestContext));
verify(basePieceFlowHolderBuilder).updateHolderWithOrderInformation(holder, requestContext);
}
Aggregations