use of org.folio.rest.core.models.RequestContext in project mod-invoice by folio-org.
the class PaymentCreditWorkflowService method createTransactions.
private CompletionStage<Void> createTransactions(List<InvoiceWorkflowDataHolder> holders, RequestContext requestContext) {
CompletableFuture<Void> future = completedFuture(null);
for (InvoiceWorkflowDataHolder holder : holders) {
Transaction tr = holder.getNewTransaction();
future = future.thenCompose(v -> baseTransactionService.createTransaction(tr, requestContext).thenAccept(t -> {
}).exceptionally(t -> {
logger.error("Failed to create transaction for invoice with id - {}", tr.getSourceInvoiceId(), t);
List<Parameter> parameters = new ArrayList<>();
parameters.add(new Parameter().withKey("invoiceLineId").withValue(tr.getSourceInvoiceLineId()));
parameters.add(new Parameter().withKey(FUND_ID).withValue((tr.getTransactionType() == Transaction.TransactionType.PAYMENT) ? tr.getFromFundId() : tr.getToFundId()));
throw new HttpException(400, TRANSACTION_CREATION_FAILURE.toError().withParameters(parameters));
}));
}
return future;
}
use of org.folio.rest.core.models.RequestContext in project mod-invoice by folio-org.
the class PendingPaymentWorkflowService method handlePendingPaymentsCreation.
public CompletableFuture<Void> handlePendingPaymentsCreation(List<InvoiceWorkflowDataHolder> dataHolders, RequestContext requestContext) {
List<InvoiceWorkflowDataHolder> holders = withNewPendingPayments(dataHolders);
holderValidator.validate(holders);
InvoiceTransactionSummary summary = buildInvoiceTransactionsSummary(holders);
return invoiceTransactionSummaryService.createInvoiceTransactionSummary(summary, requestContext).thenCompose(s -> createPendingPayments(holders, requestContext)).thenCompose(s -> cleanupOldEncumbrances(holders, requestContext));
}
use of org.folio.rest.core.models.RequestContext in project mod-invoice by folio-org.
the class PendingPaymentWorkflowService method createPendingPayments.
private CompletableFuture<Void> createPendingPayments(List<InvoiceWorkflowDataHolder> holders, RequestContext requestContext) {
CompletableFuture<Void> future = completedFuture(null);
for (InvoiceWorkflowDataHolder holder : holders) {
Transaction pendingPayment = holder.getNewTransaction();
future = future.thenCompose(v -> baseTransactionService.createTransaction(pendingPayment, requestContext).thenAccept(t -> {
}).exceptionally(t -> {
logger.error("Failed to create pending payment with id {}", pendingPayment.getId(), t);
throw new HttpException(400, PENDING_PAYMENT_ERROR.toError());
}));
}
return future;
}
use of org.folio.rest.core.models.RequestContext in project mod-orders by folio-org.
the class PurchaseOrderHelper method reopenOrder.
private CompletionStage<Void> reopenOrder(CompositePurchaseOrder compPO, CompositePurchaseOrder poFromStorage, RequestContext requestContext) {
EncumbranceWorkflowStrategy strategy = encumbranceWorkflowStrategyFactory.getStrategy(OrderWorkflowType.CLOSED_TO_OPEN);
CompositePurchaseOrder clonedCompPO = JsonObject.mapFrom(compPO).mapTo(CompositePurchaseOrder.class);
if (CollectionUtils.isEmpty(clonedCompPO.getCompositePoLines())) {
List<CompositePoLine> clonedLines = poFromStorage.getCompositePoLines().stream().map(line -> JsonObject.mapFrom(line).mapTo(CompositePoLine.class)).collect(toList());
clonedCompPO.setCompositePoLines(clonedLines);
}
return strategy.processEncumbrances(clonedCompPO, poFromStorage, requestContext);
}
use of org.folio.rest.core.models.RequestContext in project mod-orders by folio-org.
the class OpenCompositeOrderPieceServiceTest method shouldCreatePieceWithLocationAndHoldingReferenceIfMixedLineContainsLocationAndInventoryIsInstanceOrNoneAndNoCreatedPieces.
@ParameterizedTest
@CsvSource(value = { "P/E Mix:Instance:Instance, Holding:2:3", "P/E Mix:None:Instance, Holding:2:3" }, delimiter = ':')
void shouldCreatePieceWithLocationAndHoldingReferenceIfMixedLineContainsLocationAndInventoryIsInstanceOrNoneAndNoCreatedPieces(String lineType, String elecCreateInventory, String physCreateInventory, int elecQty1, int physQty2) {
// given
String lineId = UUID.randomUUID().toString();
String locationId1 = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
Location location1 = new Location().withLocationId(locationId1).withQuantityElectronic(elecQty1).withQuantity(elecQty1);
Location location2 = new Location().withHoldingId(holdingId).withQuantityPhysical(physQty2).withQuantity(physQty2);
Cost cost = new Cost().withQuantityElectronic(elecQty1 + physQty2);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.fromValue(elecCreateInventory));
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.fromValue(physCreateInventory));
CompositePoLine line = new CompositePoLine().withId(lineId).withCost(cost).withLocations(List.of(location1, location2)).withIsPackage(false).withEresource(eresource).withPhysical(physical).withOrderFormat(CompositePoLine.OrderFormat.fromValue(lineType));
CompositePurchaseOrder compOrder = new CompositePurchaseOrder().withCompositePoLines(List.of(line));
doReturn(completedFuture(null)).when(openCompositeOrderPieceService).openOrderUpdateInventory(any(CompositePoLine.class), any(Piece.class), any(Boolean.class), eq(requestContext));
doReturn(completedFuture(Collections.emptyList())).when(pieceStorageService).getPiecesByPoLineId(line, requestContext);
doReturn(completedFuture(new Piece())).when(pieceStorageService).insertPiece(any(Piece.class), eq(requestContext));
doReturn(completedFuture(null)).when(protectionService).isOperationRestricted(any(List.class), any(ProtectedOperationType.class), eq(requestContext));
doReturn(completedFuture(compOrder)).when(purchaseOrderStorageService).getCompositeOrderByPoLineId(eq(lineId), eq(requestContext));
final ArgumentCaptor<Piece> pieceArgumentCaptor = ArgumentCaptor.forClass(Piece.class);
doAnswer((Answer<CompletableFuture<Piece>>) invocation -> {
Piece piece = invocation.getArgument(0);
return completedFuture(piece);
}).when(pieceStorageService).insertPiece(pieceArgumentCaptor.capture(), eq(requestContext));
// When
List<Piece> createdPieces = openCompositeOrderPieceService.handlePieces(line, titleId, Collections.emptyList(), false, requestContext).join();
// Then
List<Piece> piecesLoc1 = createdPieces.stream().filter(piece -> locationId1.equals(piece.getLocationId())).collect(toList());
assertEquals(elecQty1, piecesLoc1.size());
piecesLoc1.forEach(piece -> {
assertNull(piece.getHoldingId());
assertNull(piece.getItemId());
assertEquals(lineId, piece.getPoLineId());
assertEquals(titleId, piece.getTitleId());
assertEquals(Piece.Format.ELECTRONIC, piece.getFormat());
});
List<Piece> piecesLoc2 = createdPieces.stream().filter(piece -> holdingId.equals(piece.getHoldingId())).collect(toList());
assertEquals(physQty2, piecesLoc2.size());
piecesLoc2.forEach(piece -> {
assertNull(piece.getLocationId());
assertNull(piece.getItemId());
assertEquals(lineId, piece.getPoLineId());
assertEquals(titleId, piece.getTitleId());
assertEquals(Piece.Format.PHYSICAL, piece.getFormat());
});
}
Aggregations