use of org.folio.completablefuture.FolioVertxCompletableFuture in project mod-invoice by folio-org.
the class InvoiceHelper method getInvoices.
/**
* Gets list of invoice
*
* @param limit Limit the number of elements returned in the response
* @param offset Skip over a number of elements by specifying an offset value for the query
* @param query A query expressed as a CQL string using valid searchable fields
* @return completable future with {@link InvoiceCollection} on success or an exception if processing fails
*/
public CompletableFuture<InvoiceCollection> getInvoices(int limit, int offset, String query) {
CompletableFuture<InvoiceCollection> future = new FolioVertxCompletableFuture<>(ctx);
RequestContext requestContext = new RequestContext(ctx, okapiHeaders);
try {
buildGetInvoicesQuery(query).thenCompose(getInvoicesQuery -> invoiceService.getInvoices(getInvoicesQuery, offset, limit, requestContext)).thenCompose(invoiceCollection -> invoiceService.updateInvoicesTotals(invoiceCollection, requestContext).thenAccept(v -> {
logger.info("Successfully retrieved invoices: {}", invoiceCollection);
future.complete(invoiceCollection);
})).exceptionally(t -> {
logger.error("Error getting invoices", t);
future.completeExceptionally(t);
return null;
});
} catch (Exception e) {
future.completeExceptionally(e);
}
return future;
}
use of org.folio.completablefuture.FolioVertxCompletableFuture in project mod-orders by folio-org.
the class InventoryManager method openOrderCreateItemRecord.
/**
* Return id of created Item
*/
public CompletableFuture<String> openOrderCreateItemRecord(CompositePoLine compPOL, String holdingId, RequestContext requestContext) {
final int ITEM_QUANTITY = 1;
logger.debug("Handling {} items for PO Line and holdings with id={}", ITEM_QUANTITY, holdingId);
FolioVertxCompletableFuture<String> itemFuture = new FolioVertxCompletableFuture<>(requestContext.getContext());
try {
Piece pieceWithHoldingId = new Piece().withHoldingId(holdingId);
if (compPOL.getOrderFormat() == ELECTRONIC_RESOURCE) {
createMissingElectronicItems(compPOL, pieceWithHoldingId, ITEM_QUANTITY, requestContext).thenApply(idS -> itemFuture.complete(idS.get(0))).exceptionally(itemFuture::completeExceptionally);
} else {
createMissingPhysicalItems(compPOL, pieceWithHoldingId, ITEM_QUANTITY, requestContext).thenApply(idS -> itemFuture.complete(idS.get(0))).exceptionally(itemFuture::completeExceptionally);
}
} catch (Exception e) {
itemFuture.completeExceptionally(e);
}
return itemFuture;
}
use of org.folio.completablefuture.FolioVertxCompletableFuture in project mod-orders by folio-org.
the class PoNumberHelper method getPoNumber.
public CompletableFuture<PoNumber> getPoNumber(RequestContext requestContext) {
FolioVertxCompletableFuture<PoNumber> future = new FolioVertxCompletableFuture<>(requestContext.getContext());
generatePoNumber(requestContext).thenAccept(number -> {
logger.info("The PO Number '{}' is not in use yet", number);
future.complete(new PoNumber().withPoNumber(number));
}).exceptionally(t -> {
future.completeExceptionally(t.getCause());
return null;
});
return future;
}
use of org.folio.completablefuture.FolioVertxCompletableFuture in project mod-orders by folio-org.
the class PieceUpdateFlowManager method updatePiece.
// Flow to update piece
// 1. Before update, get piece by id from storage and store receiving status
// 2. Update piece with new content and complete future
// 3. Create a message and check if receivingStatus is not consistent with storage; if yes - send a message to event bus
public CompletableFuture<Void> updatePiece(Piece pieceToUpdate, boolean createItem, boolean deleteHolding, RequestContext requestContext) {
CompletableFuture<Void> future = new FolioVertxCompletableFuture<>(requestContext.getContext());
PieceUpdateHolder holder = new PieceUpdateHolder().withPieceToUpdate(pieceToUpdate).withCreateItem(createItem).withDeleteHolding(deleteHolding);
pieceStorageService.getPieceById(pieceToUpdate.getId(), requestContext).thenAccept(holder::withPieceFromStorage).thenCompose(aHolder -> basePieceFlowHolderBuilder.updateHolderWithOrderInformation(holder, requestContext)).thenAccept(v -> defaultPieceFlowsValidator.isPieceRequestValid(pieceToUpdate, holder.getOriginPoLine(), createItem)).thenCompose(purchaseOrder -> protectionService.isOperationRestricted(holder.getOriginPurchaseOrder().getAcqUnitIds(), UPDATE, requestContext)).thenCompose(v -> pieceUpdateFlowInventoryManager.processInventory(holder, requestContext)).thenCompose(vVoid -> updatePoLine(holder, requestContext)).thenAccept(afterUpdate -> {
JsonObject messageToEventBus = new JsonObject();
messageToEventBus.put("poLineIdUpdate", holder.getPieceToUpdate().getPoLineId());
Piece.ReceivingStatus receivingStatusStorage = holder.getPieceFromStorage().getReceivingStatus();
Piece.ReceivingStatus receivingStatusUpdate = holder.getPieceToUpdate().getReceivingStatus();
logger.debug("receivingStatusStorage -- {}", receivingStatusStorage);
logger.debug("receivingStatusUpdate -- {}", receivingStatusUpdate);
if (receivingStatusStorage.compareTo(receivingStatusUpdate) != 0) {
pieceService.receiptConsistencyPiecePoLine(messageToEventBus, requestContext);
}
}).thenCompose(aVoid -> pieceStorageService.updatePiece(holder.getPieceToUpdate(), requestContext)).thenAccept(future::complete).exceptionally(t -> {
logger.error("User to update piece with id={}", holder.getPieceToUpdate().getId(), t.getCause());
future.completeExceptionally(t);
return null;
});
return future;
}
use of org.folio.completablefuture.FolioVertxCompletableFuture in project mod-invoice by folio-org.
the class InvoiceHelper method getInvoice.
/**
* Gets invoice by id and calculates totals
*
* @param id invoice uuid
* @return completable future with {@link Invoice} on success or an exception if processing fails
*/
public CompletableFuture<Invoice> getInvoice(String id) {
CompletableFuture<Invoice> future = new FolioVertxCompletableFuture<>(ctx);
RequestContext requestContext = new RequestContext(ctx, okapiHeaders);
getInvoiceRecord(id).thenCompose(invoice -> protectionHelper.isOperationRestricted(invoice.getAcqUnitIds(), ProtectedOperationType.READ).thenApply(aVoid -> invoice)).thenCompose(invoice -> invoiceService.recalculateTotals(invoice, requestContext).thenApply(b -> invoice)).thenAccept(future::complete).exceptionally(t -> {
logger.error("Failed to get an Invoice by id={}", id, t.getCause());
future.completeExceptionally(t);
return null;
});
return future;
}
Aggregations