From f5583b9fca31e78b5d0174cce0168462061b3e36 Mon Sep 17 00:00:00 2001 From: saba_zedginidze Date: Thu, 19 Dec 2024 17:13:49 +0400 Subject: [PATCH 1/6] [MODORDSTOR-435] Use batch piece update endpoint for batch status update --- ramls/acq-models | 2 +- .../java/org/folio/orders/utils/ResourcePathResolver.java | 2 ++ .../java/org/folio/service/pieces/PieceStorageService.java | 7 +++++++ .../pieces/flows/update/PieceUpdateFlowManager.java | 4 ++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ramls/acq-models b/ramls/acq-models index c0c72775d..a8f2fef0b 160000 --- a/ramls/acq-models +++ b/ramls/acq-models @@ -1 +1 @@ -Subproject commit c0c72775d08c28a77d1475df435497e8b0020667 +Subproject commit a8f2fef0b41fbe99f917a39857821b93c417b1a9 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 5eed324f9..56b76e0e8 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 @@ -27,6 +27,7 @@ import org.folio.rest.jaxrs.model.Parameter; import org.folio.rest.jaxrs.model.Piece; import org.folio.rest.jaxrs.model.PieceBatchStatusCollection; +import org.folio.rest.jaxrs.model.PieceCollection; import org.folio.service.ProtectionService; import org.folio.service.orders.PurchaseOrderLineService; import org.folio.service.pieces.PieceService; @@ -176,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(new PieceCollection().withPieces(holder.getPieces()), requestContext) .compose(v -> asFuture(() -> pieceService.receiptConsistencyPiecePoLine(holder.getOrderLineId(), requestContext))); } From 91e4e32d0eb1f82dfa7fe96870c0405af70d7cad Mon Sep 17 00:00:00 2001 From: saba_zedginidze Date: Thu, 19 Dec 2024 18:13:08 +0400 Subject: [PATCH 2/6] [MODORDSTOR-435] Update unit tests --- .../service/pieces/flows/update/PieceUpdateFlowManagerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1fbb37eeb..8f9ee880c 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, requestContext); From 6d143294768cc31438673aef73f61c0aa265f9d8 Mon Sep 17 00:00:00 2001 From: Azizbek Khushvakov Date: Mon, 23 Dec 2024 17:10:02 +0500 Subject: [PATCH 3/6] [MODORDERS-1224] - Invoice encumbrance link not removed because of acquisition unit --- descriptors/ModuleDescriptor-template.json | 1 + .../pieces/PieceBatchStatusUpdateHolder.java | 6 ++++++ .../flows/update/PieceUpdateFlowManager.java | 3 +-- src/test/java/org/folio/rest/impl/MockServer.java | 14 ++++++++++++++ .../org/folio/rest/impl/PiecesClaimingApiTest.java | 4 ++-- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index f90e258bb..9e5621479 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/service/pieces/flows/update/PieceUpdateFlowManager.java b/src/main/java/org/folio/service/pieces/flows/update/PieceUpdateFlowManager.java index 97cdb5dbe..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 @@ -27,7 +27,6 @@ import org.folio.rest.jaxrs.model.Parameter; import org.folio.rest.jaxrs.model.Piece; import org.folio.rest.jaxrs.model.PieceBatchStatusCollection; -import org.folio.rest.jaxrs.model.PieceCollection; import org.folio.service.ProtectionService; import org.folio.service.orders.PurchaseOrderLineService; import org.folio.service.pieces.PieceService; @@ -178,7 +177,7 @@ private Future updatePiecesStatusesByPoLine(PieceBatchStatusUpdateHolder h if (!Boolean.TRUE.equals(isAnyPiecesUpdated)) { return Future.succeededFuture(); } - return pieceStorageService.updatePiecesBatch(new PieceCollection().withPieces(holder.getPieces()), requestContext) + 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..d056631c9 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(resourcePath(PIECES_STORAGE_BATCH)).handler(ctx -> handlePutBatchSubObj(ctx, PIECES_STORAGE_BATCH)); 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,14 @@ private void handlePutGenericSubObj(RoutingContext ctx, String subObj) { } } + private void handlePutBatchSubObj(RoutingContext ctx, String subObj) { + logger.info("handlePutPiecesBatch got: PUT {}", ctx.request().path()); + addServerRqRsData(HttpMethod.PUT, subObj, ctx.body().asJsonObject()); + 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(); From 0aa95823443c24e06dbad9e4afd3192478675f70 Mon Sep 17 00:00:00 2001 From: Azizbek Khushvakov Date: Mon, 23 Dec 2024 17:34:06 +0500 Subject: [PATCH 4/6] [MODORDERS-1224] - Invoice encumbrance link not removed because of acquisition unit --- src/test/java/org/folio/rest/impl/MockServer.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/folio/rest/impl/MockServer.java b/src/test/java/org/folio/rest/impl/MockServer.java index d056631c9..d9ea346b0 100644 --- a/src/test/java/org/folio/rest/impl/MockServer.java +++ b/src/test/java/org/folio/rest/impl/MockServer.java @@ -689,7 +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(resourcePath(PIECES_STORAGE_BATCH)).handler(ctx -> handlePutBatchSubObj(ctx, PIECES_STORAGE_BATCH)); + 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)); @@ -2143,9 +2143,10 @@ private void handlePutGenericSubObj(RoutingContext ctx, String subObj) { } } - private void handlePutBatchSubObj(RoutingContext ctx, String subObj) { + private void handlePutPiecesBatch(RoutingContext ctx) { logger.info("handlePutPiecesBatch got: PUT {}", ctx.request().path()); - addServerRqRsData(HttpMethod.PUT, subObj, ctx.body().asJsonObject()); + JsonObject body = ctx.body().asJsonObject(); + addServerRqRsData(HttpMethod.PUT, PIECES_STORAGE, body); ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) .setStatusCode(204) .end(); From b85683e8c12d96471dc17f9d3cbd3eea6483cc28 Mon Sep 17 00:00:00 2001 From: Azizbek Khushvakov Date: Mon, 23 Dec 2024 17:46:35 +0500 Subject: [PATCH 5/6] Fix test --- src/test/java/org/folio/rest/impl/MockServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/folio/rest/impl/MockServer.java b/src/test/java/org/folio/rest/impl/MockServer.java index d9ea346b0..7cff075c5 100644 --- a/src/test/java/org/folio/rest/impl/MockServer.java +++ b/src/test/java/org/folio/rest/impl/MockServer.java @@ -2146,7 +2146,7 @@ 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, body); + addServerRqRsData(HttpMethod.PUT, PIECES_STORAGE_BATCH, body); ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) .setStatusCode(204) .end(); From 2a7a6bd911e35eeaabb4f1190be111e8c2efe5e1 Mon Sep 17 00:00:00 2001 From: Azizbek Khushvakov Date: Mon, 23 Dec 2024 17:54:29 +0500 Subject: [PATCH 6/6] Fix module descriptor --- descriptors/ModuleDescriptor-template.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index 9e5621479..0b66f7c57 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -635,7 +635,7 @@ "modulePermissions": [ "orders-storage.pieces.item.put", "orders-storage.pieces.collection.get", - "orders-storage.pieces-batch.collection.put" + "orders-storage.pieces-batch.collection.put", "orders-storage.po-lines.item.get", "orders-storage.po-lines.item.put", "orders-storage.po-lines.collection.get",