Skip to content

Commit

Permalink
[MODORDSTOR-435] Use batch piece update endpoint for batch status upd…
Browse files Browse the repository at this point in the history
…ate (#1072)

* [MODORDSTOR-435] Use batch piece update endpoint for batch status update

* [MODORDSTOR-435] Update unit tests

* [MODORDERS-1224] - Invoice encumbrance link not removed because of acquisition unit

* [MODORDERS-1224] - Invoice encumbrance link not removed because of acquisition unit

* Fix test

* Fix module descriptor

---------

Co-authored-by: Azizbek Khushvakov <[email protected]>
Co-authored-by: Azizbek Khushvakov <[email protected]>
  • Loading branch information
3 people authored Dec 23, 2024
1 parent 8ab6e5d commit de6bc3a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -31,4 +33,8 @@ public String getTitleId() {
return null;
}

public PieceCollection getPieceCollection() {
return new PieceCollection().withPieces(pieces).withTotalRecords(CollectionUtils.size(pieces));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -82,6 +84,11 @@ public Future<Void> updatePiece(Piece piece, RequestContext requestContext) {
return restClient.put(requestEntry, piece, requestContext);
}

public Future<Void> updatePiecesBatch(PieceCollection pieceCollection, RequestContext requestContext) {
RequestEntry requestEntry = new RequestEntry(PIECES_STORAGE_BATCH_ENDPOINT);
return restClient.put(requestEntry, pieceCollection, requestContext);
}

public Future<Piece> insertPiece(Piece piece, RequestContext requestContext) {
RequestEntry requestEntry = new RequestEntry(PIECE_STORAGE_ENDPOINT);
return restClient.post(requestEntry, piece, Piece.class, requestContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ private Future<Void> 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)));
}

Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/folio/rest/impl/MockServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -437,6 +438,10 @@ public static List<JsonObject> getPieceUpdates() {
return serverRqRs.get(PIECES_STORAGE, HttpMethod.PUT);
}

public static List<JsonObject> getPieceBatchUpdates() {
return serverRqRs.get(PIECES_STORAGE_BATCH, HttpMethod.PUT);
}

public static List<JsonObject> getPieceDeletions() {
return serverRqRs.get(PIECES_STORAGE, HttpMethod.DELETE);
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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<JsonObject> entries = serverRqRs.get(objName, method);
if (entries == null) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/folio/rest/impl/PiecesClaimingApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void> result = pieceUpdateFlowManager.updatePiecesStatuses(pieceIds, receivingStatus, null, null, null, requestContext);
Expand Down

0 comments on commit de6bc3a

Please sign in to comment.