use of org.folio.models.pieces.PieceCreationHolder in project mod-orders by folio-org.
the class PieceCreateFlowManager method createPiece.
public CompletableFuture<Piece> createPiece(Piece pieceToCreate, boolean createItem, RequestContext requestContext) {
logger.info("manual createPiece start");
PieceCreationHolder holder = new PieceCreationHolder().withPieceToCreate(pieceToCreate).withCreateItem(createItem);
return basePieceFlowHolderBuilder.updateHolderWithOrderInformation(holder, requestContext).thenAccept(v -> defaultPieceFlowsValidator.isPieceRequestValid(pieceToCreate, holder.getOriginPoLine(), createItem)).thenCompose(order -> protectionService.isOperationRestricted(holder.getOriginPurchaseOrder().getAcqUnitIds(), ProtectedOperationType.CREATE, requestContext)).thenCompose(v -> pieceCreateFlowInventoryManager.processInventory(holder.getOriginPoLine(), holder.getPieceToCreate(), holder.isCreateItem(), requestContext)).thenCompose(compPoLine -> updatePoLine(holder, requestContext)).thenCompose(v -> pieceStorageService.insertPiece(pieceToCreate, requestContext));
}
use of org.folio.models.pieces.PieceCreationHolder in project mod-orders by folio-org.
the class PieceCreateFlowPoLineServiceTest method physAddStrategyShouldIncreaseQuantityTo2ForCostAndLocationIfInitiallyWas1AndHoldingIdInPOLAndPieceTheSame.
@Test
@DisplayName("Add 1 physical piece with holding to physical pol with 1 location and same holding id as in piece")
void physAddStrategyShouldIncreaseQuantityTo2ForCostAndLocationIfInitiallyWas1AndHoldingIdInPOLAndPieceTheSame() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece piece = new Piece().withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.PHYSICAL);
Location loc = new Location().withHoldingId(holdingId).withQuantityPhysical(1).withQuantity(1);
Cost cost = new Cost().withQuantityPhysical(1).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withPhysical(physical).withLocations(List.of(loc)).withCost(cost);
PieceCreationHolder incomingUpdateHolder = new PieceCreationHolder().withPieceToCreate(piece).withCreateItem(true);
incomingUpdateHolder.withOrderInformation(purchaseOrder, originPoLine);
doReturn(completedFuture(null)).when(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
// When
pieceCreateFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
assertNull(poLineToSave.getCost().getQuantityElectronic());
assertEquals(2, poLineToSave.getCost().getQuantityPhysical());
assertEquals(1, poLineToSave.getLocations().size());
assertNull(poLineToSave.getLocations().get(0).getQuantityElectronic());
assertEquals(2, poLineToSave.getLocations().get(0).getQuantityPhysical());
assertEquals(2, poLineToSave.getLocations().get(0).getQuantity());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
use of org.folio.models.pieces.PieceCreationHolder in project mod-orders by folio-org.
the class PieceCreateFlowPoLineServiceTest method electAddStrategyShouldIncreaseQuantityTo3ForCostAndLocationIfInitiallyWas2AndLocationIdInPOLAndPieceTheSameInventoryNone.
@ParameterizedTest
@DisplayName("Add 1 electronic piece with location id to electronic pol with 2 location and another location id as in piece")
@CsvSource(value = { "Electronic Resource:Instance:2:3:Electronic:6:6.0", "Electronic Resource:None:2:3:Electronic:6:6.0" }, delimiter = ':')
void electAddStrategyShouldIncreaseQuantityTo3ForCostAndLocationIfInitiallyWas2AndLocationIdInPOLAndPieceTheSameInventoryNone(String lineType, String createInventory, int qty1, int qty2, String pieceFormat, int expQty, double expEstimatedPrice) throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
String locationId1 = UUID.randomUUID().toString();
String locationId2 = UUID.randomUUID().toString();
String locationId3 = UUID.randomUUID().toString();
Piece piece = new Piece().withPoLineId(lineId).withLocationId(locationId3).withFormat(Piece.Format.fromValue(pieceFormat));
Location loc1 = new Location().withLocationId(locationId1).withQuantityElectronic(qty1).withQuantity(qty1);
Location loc2 = new Location().withLocationId(locationId2).withQuantityElectronic(qty2).withQuantity(qty2);
Cost cost = new Cost().withQuantityElectronic(qty1 + qty2).withListUnitPriceElectronic(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice((double) (qty1 + qty2));
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.fromValue(createInventory));
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.fromValue(lineType)).withId(lineId).withEresource(eresource).withLocations(List.of(loc1, loc2)).withCost(cost);
PieceCreationHolder incomingUpdateHolder = new PieceCreationHolder().withPieceToCreate(piece).withCreateItem(true);
incomingUpdateHolder.withOrderInformation(purchaseOrder, originPoLine);
doReturn(completedFuture(null)).when(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
// When
pieceCreateFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
// Then
CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
assertNull(poLineToSave.getCost().getQuantityPhysical());
assertEquals(expQty, poLineToSave.getCost().getQuantityElectronic());
assertEquals(expEstimatedPrice, poLineToSave.getCost().getPoLineEstimatedPrice());
assertEquals(3, poLineToSave.getLocations().size());
Location actLoc1 = poLineToSave.getLocations().stream().filter(loc -> locationId1.equals(loc.getLocationId())).findFirst().get();
Location actLoc2 = poLineToSave.getLocations().stream().filter(loc -> locationId2.equals(loc.getLocationId())).findFirst().get();
Location actLoc3 = poLineToSave.getLocations().stream().filter(loc -> locationId3.equals(loc.getLocationId())).findFirst().get();
assertEquals(qty1, actLoc1.getQuantityElectronic());
assertEquals(qty1, actLoc1.getQuantity());
assertNull(actLoc1.getQuantityPhysical());
assertEquals(qty2, actLoc2.getQuantityElectronic());
assertEquals(qty2, actLoc2.getQuantity());
assertNull(actLoc2.getQuantityPhysical());
assertEquals(1, actLoc3.getQuantityElectronic());
assertEquals(1, actLoc3.getQuantity());
assertNull(actLoc3.getQuantityPhysical());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
use of org.folio.models.pieces.PieceCreationHolder in project mod-orders by folio-org.
the class PieceCreateFlowPoLineServiceTest method shouldIncreaseQuantityTo3ForCostAndLocationIfInitiallyWas2AndHoldingIdInPieceAndMixedPOLWithHoldingId.
@Test
@DisplayName("Add 1 electronic piece with holding id to mixed pol with 1 location with holding id and electronic and physical qty")
void shouldIncreaseQuantityTo3ForCostAndLocationIfInitiallyWas2AndHoldingIdInPieceAndMixedPOLWithHoldingId() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece pieceToCreate = new Piece().withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantityPhysical(1).withQuantity(2);
Cost cost = new Cost().withQuantityElectronic(1).withQuantityPhysical(1).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING);
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.P_E_MIX).withId(lineId).withEresource(eresource).withPhysical(physical).withLocations(List.of(loc)).withCost(cost);
PieceCreationHolder incomingUpdateHolder = new PieceCreationHolder().withPieceToCreate(pieceToCreate).withCreateItem(true);
incomingUpdateHolder.withOrderInformation(purchaseOrder, originPoLine);
doReturn(completedFuture(null)).when(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
// When
pieceCreateFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
// Then
CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
assertEquals(1, poLineToSave.getLocations().size());
assertEquals(3, poLineToSave.getLocations().get(0).getQuantity());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantityPhysical());
assertEquals(2, poLineToSave.getLocations().get(0).getQuantityElectronic());
assertEquals(1, poLineToSave.getCost().getQuantityPhysical());
assertEquals(2, poLineToSave.getCost().getQuantityElectronic());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
use of org.folio.models.pieces.PieceCreationHolder in project mod-orders by folio-org.
the class PieceCreateFlowPoLineServiceTest method electAddStrategyShouldIncreaseQuantityTo2ForCostAndLocationIfInitiallyWas1AndHoldingIdInPOLAndPieceTheSame.
@Test
@DisplayName("Add 1 electronic piece with holding to electronic pol with 1 location and same holding id as in piece")
void electAddStrategyShouldIncreaseQuantityTo2ForCostAndLocationIfInitiallyWas1AndHoldingIdInPOLAndPieceTheSame() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece piece = new Piece().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);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.ELECTRONIC_RESOURCE).withId(lineId).withEresource(eresource).withLocations(List.of(loc)).withCost(cost);
PieceCreationHolder incomingUpdateHolder = new PieceCreationHolder().withPieceToCreate(piece).withCreateItem(true);
incomingUpdateHolder.withOrderInformation(purchaseOrder, originPoLine);
doReturn(completedFuture(null)).when(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
// When
pieceCreateFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
// Then
CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
assertNull(poLineToSave.getCost().getQuantityPhysical());
assertEquals(2, poLineToSave.getCost().getQuantityElectronic());
assertEquals(1, poLineToSave.getLocations().size());
assertNull(poLineToSave.getLocations().get(0).getQuantityPhysical());
assertEquals(2, poLineToSave.getLocations().get(0).getQuantityElectronic());
assertEquals(2, poLineToSave.getLocations().get(0).getQuantity());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
Aggregations