Search in sources :

Example 6 with Title

use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.

the class PieceCreateFlowInventoryManagerTest method testShouldNotCreateHoldingPieceCreateForPackagePoLineWithCreateInventoryInstance.

@Test
void testShouldNotCreateHoldingPieceCreateForPackagePoLineWithCreateInventoryInstance() {
    String orderId = UUID.randomUUID().toString();
    String locationId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    String titleId = UUID.randomUUID().toString();
    String pieceId = UUID.randomUUID().toString();
    Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(UUID.randomUUID().toString());
    Piece piece = new Piece().withId(pieceId).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").withPoLineEstimatedPrice(1d);
    CompositePoLine compPOL = new CompositePoLine().withIsPackage(true).withPurchaseOrderId(orderId).withOrderFormat(ELECTRONIC_RESOURCE).withId(lineId).withCheckinItems(false).withEresource(new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE)).withLocations(List.of(loc)).withCost(cost);
    CompositePurchaseOrder compositePurchaseOrder = new CompositePurchaseOrder().withId(orderId).withCompositePoLines(List.of(compPOL));
    doReturn(completedFuture(piece)).when(pieceStorageService).getPieceById(pieceId, requestContext);
    doReturn(completedFuture(title)).when(titlesService).getTitleById(piece.getTitleId(), requestContext);
    doReturn(completedFuture(null)).when(titlesService).saveTitle(title, requestContext);
    doReturn(completedFuture(title)).when(inventoryManager).openOrderHandlePackageLineInstance(title, false, requestContext);
    PieceCreationHolder holder = new PieceCreationHolder().withPieceToCreate(piece).withCreateItem(true);
    holder.withOrderInformation(compositePurchaseOrder);
    pieceCreateFlowInventoryManager.processInventory(holder.getOriginPoLine(), holder.getPieceToCreate(), holder.isCreateItem(), requestContext).join();
    assertNull(piece.getItemId());
    assertNull(piece.getHoldingId());
    assertEquals(locationId, piece.getLocationId());
    verify(titlesService).getTitleById(piece.getTitleId(), requestContext);
    verify(pieceUpdateInventoryService, times(0)).handleHoldingsRecord(eq(compPOL), any(Location.class), eq(title.getInstanceId()), eq(requestContext));
    verify(pieceUpdateInventoryService, times(0)).manualPieceFlowCreateItemRecord(piece, compPOL, requestContext);
}
Also used : PieceCreationHolder(org.folio.models.pieces.PieceCreationHolder) Piece(org.folio.rest.jaxrs.model.Piece) Title(org.folio.rest.jaxrs.model.Title) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) Eresource(org.folio.rest.jaxrs.model.Eresource) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 7 with Title

use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.

the class PieceCreateFlowInventoryManagerTest method testPieceCreateForPackagePoLineWithCreateInventoryInstanceHoldingItem.

@Test
void testPieceCreateForPackagePoLineWithCreateInventoryInstanceHoldingItem() {
    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 pieceId = UUID.randomUUID().toString();
    Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(UUID.randomUUID().toString());
    Piece piece = new Piece().withId(pieceId).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").withPoLineEstimatedPrice(1d);
    CompositePoLine compPOL = new CompositePoLine().withIsPackage(true).withPurchaseOrderId(orderId).withOrderFormat(ELECTRONIC_RESOURCE).withId(lineId).withEresource(new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING_ITEM)).withLocations(List.of(loc)).withCost(cost);
    CompositePurchaseOrder compositePurchaseOrder = new CompositePurchaseOrder().withId(orderId).withCompositePoLines(List.of(compPOL));
    doReturn(completedFuture(piece)).when(pieceStorageService).getPieceById(pieceId, requestContext);
    doReturn(completedFuture(List.of(piece))).when(pieceStorageService).getPiecesByHoldingId(piece.getId(), requestContext);
    doReturn(completedFuture(title)).when(titlesService).getTitleById(piece.getTitleId(), requestContext);
    doReturn(completedFuture(null)).when(titlesService).saveTitle(title, requestContext);
    doReturn(completedFuture(itemId)).when(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(piece, compPOL, requestContext);
    doReturn(completedFuture(title)).when(inventoryManager).openOrderHandlePackageLineInstance(title, false, requestContext);
    doReturn(completedFuture(holdingId)).when(pieceUpdateInventoryService).handleHoldingsRecord(eq(compPOL), any(Location.class), eq(title.getInstanceId()), eq(requestContext));
    doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(piece, requestContext);
    PieceCreationHolder holder = new PieceCreationHolder().withPieceToCreate(piece).withCreateItem(true);
    holder.withOrderInformation(compositePurchaseOrder);
    pieceCreateFlowInventoryManager.processInventory(holder.getOriginPoLine(), holder.getPieceToCreate(), holder.isCreateItem(), requestContext).join();
    assertEquals(itemId, piece.getItemId());
    assertEquals(holdingId, piece.getHoldingId());
    verify(titlesService).getTitleById(piece.getTitleId(), requestContext);
    verify(pieceUpdateInventoryService, times(0)).handleHoldingsRecord(eq(compPOL), any(Location.class), eq(title.getInstanceId()), eq(requestContext));
    verify(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(piece, compPOL, requestContext);
}
Also used : PieceCreationHolder(org.folio.models.pieces.PieceCreationHolder) Piece(org.folio.rest.jaxrs.model.Piece) Title(org.folio.rest.jaxrs.model.Title) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) Eresource(org.folio.rest.jaxrs.model.Eresource) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 8 with Title

use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.

the class PieceCreateFlowInventoryManagerTest method testShouldNotCreateHoldingPieceCreateForNonPackagePoLineWithCreateInventoryInstance.

@Test
void testShouldNotCreateHoldingPieceCreateForNonPackagePoLineWithCreateInventoryInstance() {
    String orderId = UUID.randomUUID().toString();
    String locationId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    String titleId = UUID.randomUUID().toString();
    String pieceId = UUID.randomUUID().toString();
    Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(UUID.randomUUID().toString());
    Piece piece = new Piece().withId(pieceId).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").withPoLineEstimatedPrice(1d);
    CompositePoLine compPOL = new CompositePoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(ELECTRONIC_RESOURCE).withId(lineId).withEresource(new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE)).withLocations(List.of(loc)).withCost(cost);
    CompositePurchaseOrder compositePurchaseOrder = new CompositePurchaseOrder().withId(orderId).withCompositePoLines(List.of(compPOL));
    doReturn(completedFuture(piece)).when(pieceStorageService).getPieceById(pieceId, requestContext);
    doReturn(completedFuture(title)).when(titlesService).getTitleById(piece.getTitleId(), requestContext);
    doReturn(completedFuture(null)).when(titlesService).saveTitle(title, requestContext);
    doReturn(completedFuture(title)).when(inventoryManager).openOrderHandlePackageLineInstance(title, false, requestContext);
    PieceCreationHolder holder = new PieceCreationHolder().withPieceToCreate(piece).withCreateItem(true);
    holder.withOrderInformation(compositePurchaseOrder);
    pieceCreateFlowInventoryManager.processInventory(holder.getOriginPoLine(), holder.getPieceToCreate(), holder.isCreateItem(), requestContext).join();
    assertNull(piece.getItemId());
    assertNull(piece.getHoldingId());
    assertEquals(locationId, piece.getLocationId());
    verify(titlesService).getTitleById(piece.getTitleId(), requestContext);
    verify(pieceUpdateInventoryService, times(0)).handleHoldingsRecord(eq(compPOL), any(Location.class), eq(title.getInstanceId()), eq(requestContext));
    verify(pieceUpdateInventoryService, times(0)).manualPieceFlowCreateItemRecord(piece, compPOL, requestContext);
}
Also used : PieceCreationHolder(org.folio.models.pieces.PieceCreationHolder) Piece(org.folio.rest.jaxrs.model.Piece) Title(org.folio.rest.jaxrs.model.Title) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) Eresource(org.folio.rest.jaxrs.model.Eresource) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 9 with Title

use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.

the class PieceUpdateFlowInventoryManagerTest method shouldDeleteHoldingWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHolding.

@Test
void shouldDeleteHoldingWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHolding() {
    String orderId = UUID.randomUUID().toString();
    String holdingFromStorageId = UUID.randomUUID().toString();
    String holdingId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    String titleId = UUID.randomUUID().toString();
    String itemId = UUID.randomUUID().toString();
    String pieceId = UUID.randomUUID().toString();
    String instanceId = UUID.randomUUID().toString();
    Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(instanceId);
    JsonObject holding = new JsonObject().put(ID, holdingFromStorageId);
    holding.put(HOLDING_PERMANENT_LOCATION_ID, UUID.randomUUID().toString());
    Piece pieceFromStorage = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingFromStorageId).withFormat(Piece.Format.PHYSICAL);
    Piece pieceToUpdate = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.PHYSICAL);
    Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
    Cost cost = new Cost().withQuantityElectronic(1);
    PoLine poLine = new PoLine().withIsPackage(true).withPurchaseOrderId(orderId).withId(lineId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM)).withLocations(List.of(loc)).withCost(cost);
    PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    PieceUpdateHolder holder = new PieceUpdateHolder().withPieceToUpdate(pieceToUpdate).withPieceFromStorage(pieceFromStorage).withCreateItem(true).withDeleteHolding(true);
    holder.withOrderInformation(purchaseOrder, poLine);
    doReturn(completedFuture(title)).when(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
    doReturn(completedFuture(new JsonObject())).when(inventoryManager).getItemRecordById(pieceToUpdate.getItemId(), true, requestContext);
    doReturn(completedFuture(List.of(itemId))).when(inventoryManager).createMissingPhysicalItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
    doReturn(completedFuture(null)).when(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
    doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holder.getPieceFromStorage().getHoldingId(), true, requestContext);
    doReturn(completedFuture(new ArrayList())).when(inventoryManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext);
    doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
    doReturn(completedFuture(itemId)).when(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext);
    pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).join();
    verify(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
    verify(inventoryManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext));
    verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
    verify(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
    verify(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext);
}
Also used : Physical(org.folio.rest.jaxrs.model.Physical) PieceUpdateHolder(org.folio.models.pieces.PieceUpdateHolder) Piece(org.folio.rest.jaxrs.model.Piece) PoLine(org.folio.rest.jaxrs.model.PoLine) ArrayList(java.util.ArrayList) Title(org.folio.rest.jaxrs.model.Title) JsonObject(io.vertx.core.json.JsonObject) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 10 with Title

use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.

the class PieceUpdateFlowInventoryManagerTest method shouldUpdateItemWithNewHoldingIdWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHolding.

@Test
void shouldUpdateItemWithNewHoldingIdWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHolding() {
    String orderId = UUID.randomUUID().toString();
    String holdingFromStorageId = UUID.randomUUID().toString();
    String holdingId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    String titleId = UUID.randomUUID().toString();
    String itemId = UUID.randomUUID().toString();
    String pieceId = UUID.randomUUID().toString();
    String instanceId = UUID.randomUUID().toString();
    Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(instanceId);
    JsonObject item = new JsonObject().put(ID, itemId);
    item.put(ITEM_STATUS, new JsonObject().put(ITEM_STATUS_NAME, ItemStatus.ON_ORDER.value()));
    item.put(ITEM_HOLDINGS_RECORD_ID, holdingFromStorageId);
    JsonObject holding = new JsonObject().put(ID, holdingFromStorageId);
    holding.put(HOLDING_PERMANENT_LOCATION_ID, UUID.randomUUID().toString());
    Piece pieceFromStorage = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingFromStorageId).withFormat(Piece.Format.PHYSICAL);
    Piece pieceToUpdate = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.PHYSICAL);
    Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
    Cost cost = new Cost().withQuantityElectronic(1);
    PoLine poLine = new PoLine().withIsPackage(true).withPurchaseOrderId(orderId).withId(lineId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM)).withLocations(List.of(loc)).withCost(cost);
    PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    PieceUpdateHolder holder = new PieceUpdateHolder().withPieceToUpdate(pieceToUpdate).withPieceFromStorage(pieceFromStorage).withCreateItem(true).withDeleteHolding(true);
    holder.withOrderInformation(purchaseOrder, poLine);
    doReturn(completedFuture(title)).when(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
    doReturn(completedFuture(item)).when(inventoryManager).getItemRecordById(pieceToUpdate.getItemId(), true, requestContext);
    doReturn(completedFuture(null)).when(inventoryManager).updateItem(item, requestContext);
    doReturn(completedFuture(List.of(itemId))).when(inventoryManager).createMissingPhysicalItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
    doReturn(completedFuture(null)).when(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
    doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holder.getPieceFromStorage().getHoldingId(), true, requestContext);
    doReturn(completedFuture(new ArrayList())).when(inventoryManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext);
    doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
    pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).join();
    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(inventoryManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext));
    verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
    verify(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
    verify(inventoryManager, times(0)).createMissingElectronicItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
    verify(inventoryManager, times(0)).createMissingPhysicalItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
    verify(inventoryManager).updateItem(item, requestContext);
}
Also used : Physical(org.folio.rest.jaxrs.model.Physical) PieceUpdateHolder(org.folio.models.pieces.PieceUpdateHolder) Piece(org.folio.rest.jaxrs.model.Piece) PoLine(org.folio.rest.jaxrs.model.PoLine) ArrayList(java.util.ArrayList) Title(org.folio.rest.jaxrs.model.Title) JsonObject(io.vertx.core.json.JsonObject) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Aggregations

Title (org.folio.rest.jaxrs.model.Title)42 Test (org.junit.jupiter.api.Test)28 Piece (org.folio.rest.jaxrs.model.Piece)23 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)19 Location (org.folio.rest.jaxrs.model.Location)19 JsonObject (io.vertx.core.json.JsonObject)17 ArrayList (java.util.ArrayList)10 List (java.util.List)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 Cost (org.folio.rest.jaxrs.model.Cost)8 PoLine (org.folio.rest.jaxrs.model.PoLine)8 PurchaseOrder (org.folio.rest.jaxrs.model.PurchaseOrder)8 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)7 Collectors (java.util.stream.Collectors)7 Eresource (org.folio.rest.jaxrs.model.Eresource)7 Context (io.vertx.core.Context)6 Map (java.util.Map)6 PieceUpdateHolder (org.folio.models.pieces.PieceUpdateHolder)6 Optional (java.util.Optional)5 LogManager (org.apache.logging.log4j.LogManager)5