Skip to content

Commit

Permalink
[MODORDSTOR-435] Use batch piece update endpoint for batch status update
Browse files Browse the repository at this point in the history
  • Loading branch information
Saba-Zedginidze-EPAM committed Dec 19, 2024
1 parent f0f3832 commit f5583b9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
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 @@ -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;
Expand Down Expand Up @@ -176,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(new PieceCollection().withPieces(holder.getPieces()), requestContext)
.compose(v -> asFuture(() -> pieceService.receiptConsistencyPiecePoLine(holder.getOrderLineId(), requestContext)));
}

Expand Down

0 comments on commit f5583b9

Please sign in to comment.