Search in sources :

Example 1 with ITEM_HOLDINGS_RECORD_ID

use of org.folio.service.inventory.InventoryManager.ITEM_HOLDINGS_RECORD_ID in project mod-orders by folio-org.

the class CheckinReceivePiecesHelper method processItemsUpdate.

protected CompletableFuture<Map<String, List<Piece>>> processItemsUpdate(Map<String, Map<String, Location>> pieceLocationsGroupedByPoLine, Map<String, List<Piece>> piecesGroupedByPoLine, List<JsonObject> items, PoLineAndTitleById poLinesAndTitlesById, RequestContext requestContext) {
    List<CompletableFuture<Boolean>> futuresForItemsUpdates = new ArrayList<>();
    Map<String, Piece> piecesWithItems = collectPiecesWithItemId(piecesGroupedByPoLine);
    // If there are no pieces with ItemId, continue
    if (piecesWithItems.isEmpty()) {
        return completedFuture(piecesGroupedByPoLine);
    }
    for (JsonObject item : items) {
        String itemId = item.getString(ID);
        Piece piece = piecesWithItems.get(itemId);
        CompositePoLine poLine = poLinesAndTitlesById.poLineById.get(piece.getPoLineId());
        if (poLine == null)
            continue;
        Title title = poLinesAndTitlesById.titleById.get(piece.getTitleId());
        if (title == null)
            continue;
        Location pieceLocation = pieceLocationsGroupedByPoLine.get(poLine.getId()).get(piece.getId());
        if (holdingUpdateOnCheckinReceiveRequired(piece, pieceLocation, poLine) && !isRevertToOnOrder(piece)) {
            String holdingKey = buildProcessedHoldingKey(pieceLocation, title.getInstanceId());
            String holdingId = processedHoldings.get(holdingKey);
            item.put(ITEM_HOLDINGS_RECORD_ID, holdingId);
        }
        futuresForItemsUpdates.add(receiveInventoryItemAndUpdatePiece(item, piece, requestContext));
    }
    return collectResultsOnSuccess(futuresForItemsUpdates).thenApply(results -> {
        if (logger.isDebugEnabled()) {
            long successQty = results.stream().filter(result -> result).count();
            logger.debug("{} out of {} inventory item(s) successfully updated", successQty, results.size());
        }
        return piecesGroupedByPoLine;
    });
}
Also used : ITEM_UPDATE_FAILED(org.folio.rest.core.exceptions.ErrorCodes.ITEM_UPDATE_FAILED) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ProcessingStatus(org.folio.rest.jaxrs.model.ProcessingStatus) Autowired(org.springframework.beans.factory.annotation.Autowired) HelperUtils.collectResultsOnSuccess(org.folio.orders.utils.HelperUtils.collectResultsOnSuccess) PoLine(org.folio.rest.jaxrs.model.PoLine) PIECE_NOT_FOUND(org.folio.rest.core.exceptions.ErrorCodes.PIECE_NOT_FOUND) StringUtils(org.apache.commons.lang3.StringUtils) Context(io.vertx.core.Context) PoLineCommonUtil(org.folio.orders.utils.PoLineCommonUtil) HelperUtils.convertIdsToCqlQuery(org.folio.orders.utils.HelperUtils.convertIdsToCqlQuery) ProtectionService(org.folio.service.ProtectionService) Map(java.util.Map) PIECE_ALREADY_RECEIVED(org.folio.rest.core.exceptions.ErrorCodes.PIECE_ALREADY_RECEIVED) JsonObject(io.vertx.core.json.JsonObject) FULLY_RECEIVED(org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.FULLY_RECEIVED) ReceiptStatus(org.folio.rest.jaxrs.model.PoLine.ReceiptStatus) HelperUtils.handlePutRequest(org.folio.orders.utils.HelperUtils.handlePutRequest) Location(org.folio.rest.jaxrs.model.Location) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Collection(java.util.Collection) AWAITING_RECEIPT(org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.AWAITING_RECEIPT) Set(java.util.Set) HelperUtils.handleGetRequest(org.folio.orders.utils.HelperUtils.handleGetRequest) Collectors(java.util.stream.Collectors) List(java.util.List) PIECE_POL_MISMATCH(org.folio.rest.core.exceptions.ErrorCodes.PIECE_POL_MISMATCH) Logger(org.apache.logging.log4j.Logger) Eresource(org.folio.rest.jaxrs.model.Eresource) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) StreamEx(one.util.streamex.StreamEx) Optional(java.util.Optional) USER_HAS_NO_PERMISSIONS(org.folio.rest.core.exceptions.ErrorCodes.USER_HAS_NO_PERMISSIONS) PIECES_STORAGE(org.folio.orders.utils.ResourcePathResolver.PIECES_STORAGE) PIECE_NOT_RETRIEVED(org.folio.rest.core.exceptions.ErrorCodes.PIECE_NOT_RETRIEVED) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) ArrayList(java.util.ArrayList) MAX_IDS_FOR_GET_RQ(org.folio.rest.RestConstants.MAX_IDS_FOR_GET_RQ) ITEM_HOLDINGS_RECORD_ID(org.folio.service.inventory.InventoryManager.ITEM_HOLDINGS_RECORD_ID) HashSet(java.util.HashSet) ReceivingResult(org.folio.rest.jaxrs.model.ReceivingResult) Title(org.folio.rest.jaxrs.model.Title) GET_PURCHASE_ORDERS(org.folio.helper.PurchaseOrderHelper.GET_PURCHASE_ORDERS) ResourcePathResolver.resourcesPath(org.folio.orders.utils.ResourcePathResolver.resourcesPath) TitlesService(org.folio.service.titles.TitlesService) PIECE_UPDATE_FAILED(org.folio.rest.core.exceptions.ErrorCodes.PIECE_UPDATE_FAILED) PieceCreateFlowInventoryManager(org.folio.service.pieces.flows.create.PieceCreateFlowInventoryManager) RequestContext(org.folio.rest.core.models.RequestContext) EMPTY(org.apache.commons.lang3.StringUtils.EMPTY) InventoryManager(org.folio.service.inventory.InventoryManager) ReceivingItemResult(org.folio.rest.jaxrs.model.ReceivingItemResult) Physical(org.folio.rest.jaxrs.model.Physical) Piece(org.folio.rest.jaxrs.model.Piece) HelperUtils(org.folio.orders.utils.HelperUtils) LOC_NOT_PROVIDED(org.folio.rest.core.exceptions.ErrorCodes.LOC_NOT_PROVIDED) EntryStream(one.util.streamex.EntryStream) PARTIALLY_RECEIVED(org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.PARTIALLY_RECEIVED) Error(org.folio.rest.jaxrs.model.Error) ResourcePathResolver.resourceByIdPath(org.folio.orders.utils.ResourcePathResolver.resourceByIdPath) HelperUtils.buildQuery(org.folio.orders.utils.HelperUtils.buildQuery) PurchaseOrderCollection(org.folio.rest.jaxrs.model.PurchaseOrderCollection) ITEM_NOT_RETRIEVED(org.folio.rest.core.exceptions.ErrorCodes.ITEM_NOT_RETRIEVED) PurchaseOrderLineService(org.folio.service.orders.PurchaseOrderLineService) HelperUtils.encodeQuery(org.folio.orders.utils.HelperUtils.encodeQuery) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) CompletableFuture(java.util.concurrent.CompletableFuture) Piece(org.folio.rest.jaxrs.model.Piece) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Title(org.folio.rest.jaxrs.model.Title) Location(org.folio.rest.jaxrs.model.Location)

Aggregations

Context (io.vertx.core.Context)1 JsonObject (io.vertx.core.json.JsonObject)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)1 EntryStream (one.util.streamex.EntryStream)1 StreamEx (one.util.streamex.StreamEx)1 StringUtils (org.apache.commons.lang3.StringUtils)1 EMPTY (org.apache.commons.lang3.StringUtils.EMPTY)1