Search in sources :

Example 1 with UPDATE

use of org.folio.orders.utils.ProtectedOperationType.UPDATE 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;
}
Also used : UPDATE(org.folio.orders.utils.ProtectedOperationType.UPDATE) Piece(org.folio.rest.jaxrs.model.Piece) DefaultPieceFlowsValidator(org.folio.service.pieces.flows.DefaultPieceFlowsValidator) BasePieceFlowHolderBuilder(org.folio.service.pieces.flows.BasePieceFlowHolderBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture) Logger(org.apache.logging.log4j.Logger) ProtectionService(org.folio.service.ProtectionService) RequestContext(org.folio.rest.core.models.RequestContext) PieceService(org.folio.service.pieces.PieceService) JsonObject(io.vertx.core.json.JsonObject) LogManager(org.apache.logging.log4j.LogManager) PieceStorageService(org.folio.service.pieces.PieceStorageService) PieceUpdateHolder(org.folio.models.pieces.PieceUpdateHolder) PieceUpdateHolder(org.folio.models.pieces.PieceUpdateHolder) JsonObject(io.vertx.core.json.JsonObject) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 FolioVertxCompletableFuture (org.folio.completablefuture.FolioVertxCompletableFuture)1 PieceUpdateHolder (org.folio.models.pieces.PieceUpdateHolder)1 UPDATE (org.folio.orders.utils.ProtectedOperationType.UPDATE)1 RequestContext (org.folio.rest.core.models.RequestContext)1 Piece (org.folio.rest.jaxrs.model.Piece)1 ProtectionService (org.folio.service.ProtectionService)1 PieceService (org.folio.service.pieces.PieceService)1 PieceStorageService (org.folio.service.pieces.PieceStorageService)1 BasePieceFlowHolderBuilder (org.folio.service.pieces.flows.BasePieceFlowHolderBuilder)1 DefaultPieceFlowsValidator (org.folio.service.pieces.flows.DefaultPieceFlowsValidator)1