diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index f90e258bb..0b66f7c57 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -635,6 +635,7 @@ "modulePermissions": [ "orders-storage.pieces.item.put", "orders-storage.pieces.collection.get", + "orders-storage.pieces-batch.collection.put", "orders-storage.po-lines.item.get", "orders-storage.po-lines.item.put", "orders-storage.po-lines.collection.get", diff --git a/src/main/java/org/folio/models/pieces/PieceBatchStatusUpdateHolder.java b/src/main/java/org/folio/models/pieces/PieceBatchStatusUpdateHolder.java index 23570a86d..3de298b2e 100644 --- a/src/main/java/org/folio/models/pieces/PieceBatchStatusUpdateHolder.java +++ b/src/main/java/org/folio/models/pieces/PieceBatchStatusUpdateHolder.java @@ -2,7 +2,9 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import org.apache.commons.collections.CollectionUtils; import org.folio.rest.jaxrs.model.Piece; +import org.folio.rest.jaxrs.model.PieceCollection; import java.util.List; @@ -31,4 +33,8 @@ public String getTitleId() { return null; } + public PieceCollection getPieceCollection() { + return new PieceCollection().withPieces(pieces).withTotalRecords(CollectionUtils.size(pieces)); + } + } diff --git a/src/main/java/org/folio/orders/utils/ResourcePathResolver.java b/src/main/java/org/folio/orders/utils/ResourcePathResolver.java index aa8e91a94..64f197063 100644 --- a/src/main/java/org/folio/orders/utils/ResourcePathResolver.java +++ b/src/main/java/org/folio/orders/utils/ResourcePathResolver.java @@ -26,6 +26,7 @@ private ResourcePathResolver() { public static final String REPORTING_CODES = "reportingCodes"; public static final String PURCHASE_ORDER_STORAGE = "purchaseOrder"; public static final String PIECES_STORAGE = "pieces"; + public static final String PIECES_STORAGE_BATCH = "pieces-batch"; public static final String ORGANIZATION_STORAGE = "organizations"; public static final String RECEIVING_HISTORY = "receiving-history"; public static final String RECEIPT_STATUS = "receiptStatus"; @@ -79,6 +80,7 @@ private ResourcePathResolver() { apis.put(PO_NUMBER, "/orders-storage/po-number"); apis.put(PURCHASE_ORDER_STORAGE, "/orders-storage/purchase-orders"); apis.put(PIECES_STORAGE, "/orders-storage/pieces"); + apis.put(PIECES_STORAGE_BATCH, "/orders-storage/pieces-batch"); apis.put(ORGANIZATION_STORAGE, "/organizations-storage/organizations"); apis.put(RECEIVING_HISTORY, "/orders-storage/receiving-history"); apis.put(PO_LINE_NUMBER, "/orders-storage/po-line-number"); diff --git a/src/main/java/org/folio/service/pieces/PieceStorageService.java b/src/main/java/org/folio/service/pieces/PieceStorageService.java index 466cab229..979e5414e 100644 --- a/src/main/java/org/folio/service/pieces/PieceStorageService.java +++ b/src/main/java/org/folio/service/pieces/PieceStorageService.java @@ -6,6 +6,7 @@ import static org.folio.orders.utils.QueryUtils.convertIdsToCqlQuery; import static org.folio.orders.utils.QueryUtils.getCqlExpressionForFieldNullValue; import static org.folio.orders.utils.ResourcePathResolver.PIECES_STORAGE; +import static org.folio.orders.utils.ResourcePathResolver.PIECES_STORAGE_BATCH; import static org.folio.orders.utils.ResourcePathResolver.resourcesPath; import static org.folio.rest.RestConstants.MAX_IDS_FOR_GET_RQ_15; @@ -40,6 +41,7 @@ public class PieceStorageService { private static final String PIECES_BY_HOLDING_ID_QUERY = "holdingId==%s"; private static final String PIECE_STORAGE_ENDPOINT = resourcesPath(PIECES_STORAGE); private static final String PIECE_STORAGE_BY_ID_ENDPOINT = PIECE_STORAGE_ENDPOINT + "/{id}"; + private static final String PIECES_STORAGE_BATCH_ENDPOINT = resourcesPath(PIECES_STORAGE_BATCH); private final ConsortiumConfigurationService consortiumConfigurationService; private final ConsortiumUserTenantsRetriever consortiumUserTenantsRetriever; @@ -82,6 +84,11 @@ public Future updatePiece(Piece piece, RequestContext requestContext) { return restClient.put(requestEntry, piece, requestContext); } + public Future updatePiecesBatch(PieceCollection pieceCollection, RequestContext requestContext) { + RequestEntry requestEntry = new RequestEntry(PIECES_STORAGE_BATCH_ENDPOINT); + return restClient.put(requestEntry, pieceCollection, requestContext); + } + public Future insertPiece(Piece piece, RequestContext requestContext) { RequestEntry requestEntry = new RequestEntry(PIECE_STORAGE_ENDPOINT); return restClient.post(requestEntry, piece, Piece.class, requestContext); 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 ec1298fc2..ab309358b 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 @@ -177,8 +177,7 @@ private Future updatePiecesStatusesByPoLine(PieceBatchStatusUpdateHolder h if (!Boolean.TRUE.equals(isAnyPiecesUpdated)) { return Future.succeededFuture(); } - var updates = holder.getPieces().stream().map(piece -> pieceStorageService.updatePiece(piece, requestContext)).toList(); - return HelperUtils.collectResultsOnSuccess(updates) + return pieceStorageService.updatePiecesBatch(holder.getPieceCollection(), requestContext) .compose(v -> asFuture(() -> pieceService.receiptConsistencyPiecePoLine(holder.getOrderLineId(), requestContext))); } diff --git a/src/test/java/org/folio/rest/impl/MockServer.java b/src/test/java/org/folio/rest/impl/MockServer.java index fa2d2073a..7cff075c5 100644 --- a/src/test/java/org/folio/rest/impl/MockServer.java +++ b/src/test/java/org/folio/rest/impl/MockServer.java @@ -75,6 +75,7 @@ import static org.folio.orders.utils.ResourcePathResolver.ORDER_TEMPLATES; import static org.folio.orders.utils.ResourcePathResolver.ORGANIZATION_STORAGE; import static org.folio.orders.utils.ResourcePathResolver.PIECES_STORAGE; +import static org.folio.orders.utils.ResourcePathResolver.PIECES_STORAGE_BATCH; import static org.folio.orders.utils.ResourcePathResolver.PO_LINES_BATCH_STORAGE; import static org.folio.orders.utils.ResourcePathResolver.PO_LINES_STORAGE; import static org.folio.orders.utils.ResourcePathResolver.PO_LINE_NUMBER; @@ -437,6 +438,10 @@ public static List getPieceUpdates() { return serverRqRs.get(PIECES_STORAGE, HttpMethod.PUT); } + public static List getPieceBatchUpdates() { + return serverRqRs.get(PIECES_STORAGE_BATCH, HttpMethod.PUT); + } + public static List getPieceDeletions() { return serverRqRs.get(PIECES_STORAGE, HttpMethod.DELETE); } @@ -684,6 +689,7 @@ private Router defineRoutes() { router.put(resourcePath(PO_LINES_STORAGE)).handler(ctx -> handlePutGenericSubObj(ctx, PO_LINES_STORAGE)); router.put(resourcesPath(PO_LINES_BATCH_STORAGE)).handler(ctx -> handlePutGenericSubObj(ctx, PO_LINES_BATCH_STORAGE)); router.put(resourcePath(PIECES_STORAGE)).handler(ctx -> handlePutGenericSubObj(ctx, PIECES_STORAGE)); + router.put(resourcesPath(PIECES_STORAGE_BATCH)).handler(this::handlePutPiecesBatch); // without id param router.put(resourcePath(REPORTING_CODES)).handler(ctx -> handlePutGenericSubObj(ctx, REPORTING_CODES)); router.put(resourcePath(ALERTS)).handler(ctx -> handlePutGenericSubObj(ctx, ALERTS)); router.put("/inventory/items/:id").handler(ctx -> handlePutGenericSubObj(ctx, ITEM_RECORDS)); @@ -2137,6 +2143,15 @@ private void handlePutGenericSubObj(RoutingContext ctx, String subObj) { } } + private void handlePutPiecesBatch(RoutingContext ctx) { + logger.info("handlePutPiecesBatch got: PUT {}", ctx.request().path()); + JsonObject body = ctx.body().asJsonObject(); + addServerRqRsData(HttpMethod.PUT, PIECES_STORAGE_BATCH, body); + ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) + .setStatusCode(204) + .end(); + } + private static void addServerRqRsData(HttpMethod method, String objName, JsonObject data) { List entries = serverRqRs.get(objName, method); if (entries == null) { diff --git a/src/test/java/org/folio/rest/impl/PiecesClaimingApiTest.java b/src/test/java/org/folio/rest/impl/PiecesClaimingApiTest.java index 1e80e8b58..de6c6f60c 100644 --- a/src/test/java/org/folio/rest/impl/PiecesClaimingApiTest.java +++ b/src/test/java/org/folio/rest/impl/PiecesClaimingApiTest.java @@ -58,8 +58,8 @@ import static org.folio.rest.impl.MockServer.getDataExportSpringJobCreations; import static org.folio.rest.impl.MockServer.getDataExportSpringJobExecutions; import static org.folio.rest.impl.MockServer.getOrganizationSearches; +import static org.folio.rest.impl.MockServer.getPieceBatchUpdates; import static org.folio.rest.impl.MockServer.getPieceSearches; -import static org.folio.rest.impl.MockServer.getPieceUpdates; import static org.folio.rest.impl.MockServer.getPoLineSearches; import static org.folio.rest.impl.MockServer.getPurchaseOrderRetrievals; import static org.folio.rest.jaxrs.model.ClaimingPieceResult.Status.FAILURE; @@ -189,7 +189,7 @@ void testPostPiecesClaim(String name, int vendorIdx, int poLineIdx, int pieceIdx purchaseOrderRetrievals.forEach(entry -> logger.info("Retrieved PurchaseOrder: {}", entry)); var organizationSearches = getOrganizationSearches(); - var pieceUpdates = getPieceUpdates(); + var pieceUpdates = getPieceBatchUpdates(); var jobCreations = getDataExportSpringJobCreations(); var jobExecutions = getDataExportSpringJobExecutions(); diff --git a/src/test/java/org/folio/service/pieces/flows/update/PieceUpdateFlowManagerTest.java b/src/test/java/org/folio/service/pieces/flows/update/PieceUpdateFlowManagerTest.java index 96331a062..592f998d0 100644 --- a/src/test/java/org/folio/service/pieces/flows/update/PieceUpdateFlowManagerTest.java +++ b/src/test/java/org/folio/service/pieces/flows/update/PieceUpdateFlowManagerTest.java @@ -347,7 +347,7 @@ void shouldUpdatePiecesStatusesSuccessfully() { doReturn(succeededFuture(poLine2)).when(purchaseOrderLineService).getOrderLineById(poLine2.getId(), requestContext); doReturn(succeededFuture(purchaseOrder)).when(purchaseOrderStorageService).getPurchaseOrderById(purchaseOrder.getId(), requestContext); doReturn(succeededFuture()).when(pieceUpdateFlowPoLineService).updatePoLine(any(), eq(requestContext)); - doReturn(succeededFuture()).when(pieceStorageService).updatePiece(any(), eq(requestContext)); + doReturn(succeededFuture()).when(pieceStorageService).updatePiecesBatch(any(), eq(requestContext)); doNothing().when(pieceService).receiptConsistencyPiecePoLine(anyString(), eq(requestContext)); Future result = pieceUpdateFlowManager.updatePiecesStatuses(pieceIds, receivingStatus, null, null, null, requestContext);