From bdb3693e966a7070a72e7458aae9cb5105c888a6 Mon Sep 17 00:00:00 2001 From: saba_zedginidze Date: Wed, 27 Nov 2024 19:59:05 +0400 Subject: [PATCH] [MODORDERS-1210] Store updated pieces --- .../flows/update/PieceUpdateFlowManager.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/folio/service/pieces/flows/update/PieceUpdateFlowManager.java b/src/main/java/org/folio/service/pieces/flows/update/PieceUpdateFlowManager.java index 6a3ed5b09..873b452f7 100644 --- a/src/main/java/org/folio/service/pieces/flows/update/PieceUpdateFlowManager.java +++ b/src/main/java/org/folio/service/pieces/flows/update/PieceUpdateFlowManager.java @@ -103,7 +103,7 @@ public Future updatePiecesStatuses(List pieceIds, PieceBatchStatus .map(entry -> new PieceBatchStatusUpdateHolder(newStatus, entry.getValue(), entry.getKey())) .map(holder -> basePieceFlowHolderBuilder.updateHolderWithOrderInformation(holder, requestContext) .compose(v -> updatePoLine(holder, requestContext)) - .map(v -> updatePiecesStatusesByPoLine(holder, requestContext))) + .compose(v -> updatePiecesStatusesByPoLine(holder, requestContext))) .toList()) .compose(HelperUtils::collectResultsOnSuccess) .mapEmpty(); @@ -144,12 +144,16 @@ protected Future updatePoLine(T holder, Li .onFailure(t -> log.error("Failed to update PO line with id: '{}' for pieceIds: {}", originPoLine.getId(), pieceIds, t)); } - private boolean updatePiecesStatusesByPoLine(PieceBatchStatusUpdateHolder holder, RequestContext requestContext) { + private Future updatePiecesStatusesByPoLine(PieceBatchStatusUpdateHolder holder, RequestContext requestContext) { var isAnyPiecesUpdated = holder.getPieces().stream().anyMatch(piece -> updatePieceStatus(piece, piece.getReceivingStatus(), holder.getReceivingStatus())); - if (isAnyPiecesUpdated) { - pieceService.receiptConsistencyPiecePoLine(holder.getPoLineId(), requestContext); - } - return isAnyPiecesUpdated; + var updates = holder.getPieces().stream().map(piece -> pieceStorageService.updatePiece(piece, requestContext)).toList(); + return HelperUtils.collectResultsOnSuccess(updates) + .map(v -> { + if (isAnyPiecesUpdated) { + pieceService.receiptConsistencyPiecePoLine(holder.getPoLineId(), requestContext); + } + return isAnyPiecesUpdated; + }); } private List getPieceLocations(List pieces, CompositePoLine poLine) {