Search in sources :

Example 1 with ReceivedItem

use of org.folio.rest.jaxrs.model.ReceivedItem in project mod-orders by folio-org.

the class CheckinReceivingApiTest method verifyProperQuantityOfHoldingsCreated.

private void verifyProperQuantityOfHoldingsCreated(ReceivingCollection receivingRq) throws IOException {
    Set<String> expectedHoldings = new HashSet<>();
    // get processed poline
    PoLineCollection poLineCollection = new JsonObject(getMockData(POLINES_COLLECTION)).mapTo(PoLineCollection.class);
    PoLine poline = poLineCollection.getPoLines().stream().filter(poLine -> poLine.getId().equals(receivingRq.getToBeReceived().get(0).getPoLineId())).findFirst().get();
    CompositePoLine compPOL = PoLineCommonUtil.convertToCompositePoLine(poline);
    // get processed pieces for receiving
    PieceCollection pieces = new JsonObject(getMockData(PIECE_RECORDS_MOCK_DATA_PATH + "pieceRecordsCollection.json")).mapTo(PieceCollection.class);
    List<String> pieceIds = new ArrayList<>();
    receivingRq.getToBeReceived().get(0).getReceivedItems().forEach(recItem -> pieceIds.add(recItem.getPieceId()));
    // get processed pieces from mock collection
    pieces.getPieces().removeIf(piece -> !pieceIds.contains(piece.getId()));
    for (org.folio.rest.acq.model.Piece piece : pieces.getPieces()) {
        for (ReceivedItem receivedItem : receivingRq.getToBeReceived().get(0).getReceivedItems()) {
            if (receivedItem.getPieceId().equals(piece.getId()) && !receivedItem.getLocationId().equals(piece.getLocationId()) && isHoldingsUpdateRequired(piece, compPOL)) {
                expectedHoldings.add(getInstanceId(poline) + receivedItem.getLocationId());
            }
        }
    }
    assertEquals(expectedHoldings.size(), getCreatedHoldings().size());
}
Also used : PieceCollection(org.folio.rest.acq.model.PieceCollection) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) Matchers.emptyString(org.hamcrest.Matchers.emptyString) PoLineCollection(org.folio.rest.jaxrs.model.PoLineCollection) ReceivedItem(org.folio.rest.jaxrs.model.ReceivedItem) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) PoLine(org.folio.rest.jaxrs.model.PoLine) HashSet(java.util.HashSet)

Example 2 with ReceivedItem

use of org.folio.rest.jaxrs.model.ReceivedItem in project mod-orders by folio-org.

the class ReceivingHelper method receiveInventoryItemAndUpdatePiece.

@Override
protected CompletableFuture<Boolean> receiveInventoryItemAndUpdatePiece(JsonObject item, Piece piece, RequestContext requestContext) {
    ReceivedItem receivedItem = piecesByLineId.get(piece.getPoLineId()).get(piece.getId());
    return receiveItem(item, receivedItem, requestContext).thenApply(v -> {
        updatePieceWithReceivingInfo(piece);
        return true;
    }).exceptionally(e -> {
        logger.error("Item associated with piece '{}' cannot be updated", piece.getId());
        addError(piece.getPoLineId(), piece.getId(), ITEM_UPDATE_FAILED.toError());
        return false;
    });
}
Also used : ReceivingHistoryCollection(org.folio.rest.jaxrs.model.ReceivingHistoryCollection) ITEM_UPDATE_FAILED(org.folio.rest.core.exceptions.ErrorCodes.ITEM_UPDATE_FAILED) AcquisitionsUnitsService(org.folio.service.AcquisitionsUnitsService) Date(java.util.Date) ProcessingStatus(org.folio.rest.jaxrs.model.ProcessingStatus) Autowired(org.springframework.beans.factory.annotation.Autowired) HelperUtils.collectResultsOnSuccess(org.folio.orders.utils.HelperUtils.collectResultsOnSuccess) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) PoLine(org.folio.rest.jaxrs.model.PoLine) StringUtils(org.apache.commons.lang3.StringUtils) Context(io.vertx.core.Context) ArrayList(java.util.ArrayList) HelperUtils.updatePoLineReceiptStatus(org.folio.orders.utils.HelperUtils.updatePoLineReceiptStatus) ReceivingResult(org.folio.rest.jaxrs.model.ReceivingResult) ResourcePathResolver.resourcesPath(org.folio.orders.utils.ResourcePathResolver.resourcesPath) ITEM_BARCODE(org.folio.service.inventory.InventoryManager.ITEM_BARCODE) ITEM_STATUS(org.folio.service.inventory.InventoryManager.ITEM_STATUS) ITEM_ENUMERATION(org.folio.service.inventory.InventoryManager.ITEM_ENUMERATION) Collectors.mapping(java.util.stream.Collectors.mapping) Map(java.util.Map) RequestContext(org.folio.rest.core.models.RequestContext) RECEIVING_HISTORY(org.folio.orders.utils.ResourcePathResolver.RECEIVING_HISTORY) JsonObject(io.vertx.core.json.JsonObject) ITEM_CHRONOLOGY(org.folio.service.inventory.InventoryManager.ITEM_CHRONOLOGY) Location(org.folio.rest.jaxrs.model.Location) MessageAddress(org.folio.orders.events.handlers.MessageAddress) ReceivedItem(org.folio.rest.jaxrs.model.ReceivedItem) Piece(org.folio.rest.jaxrs.model.Piece) ToBeReceived(org.folio.rest.jaxrs.model.ToBeReceived) HelperUtils(org.folio.orders.utils.HelperUtils) ReceivingResults(org.folio.rest.jaxrs.model.ReceivingResults) HelperUtils.handleGetRequest(org.folio.orders.utils.HelperUtils.handleGetRequest) HelperUtils.combineCqlExpressions(org.folio.orders.utils.HelperUtils.combineCqlExpressions) ReceivingCollection(org.folio.rest.jaxrs.model.ReceivingCollection) JsonArray(io.vertx.core.json.JsonArray) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HelperUtils.buildQuery(org.folio.orders.utils.HelperUtils.buildQuery) StreamEx(one.util.streamex.StreamEx) ITEM_LEVEL_CALL_NUMBER(org.folio.service.inventory.InventoryManager.ITEM_LEVEL_CALL_NUMBER) Optional(java.util.Optional) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) ITEM_STATUS_NAME(org.folio.service.inventory.InventoryManager.ITEM_STATUS_NAME) ReceivedItem(org.folio.rest.jaxrs.model.ReceivedItem)

Example 3 with ReceivedItem

use of org.folio.rest.jaxrs.model.ReceivedItem in project mod-orders by folio-org.

the class ReceivingHelper method updatePieceWithReceivingInfo.

/**
 * Updates piece record with receiving information
 *
 * @param piece
 *          piece record to be updated with receiving info
 */
private void updatePieceWithReceivingInfo(Piece piece) {
    // Get ReceivedItem corresponding to piece record
    ReceivedItem receivedItem = piecesByLineId.get(piece.getPoLineId()).get(piece.getId());
    piece.setCaption(receivedItem.getCaption());
    piece.setComment(receivedItem.getComment());
    if (StringUtils.isNotEmpty(receivedItem.getLocationId())) {
        piece.setLocationId(receivedItem.getLocationId());
    }
    if (StringUtils.isNotEmpty(receivedItem.getHoldingId())) {
        piece.setHoldingId(receivedItem.getHoldingId());
    }
    piece.setEnumeration(receivedItem.getEnumeration());
    piece.setChronology(receivedItem.getChronology());
    piece.setDisplayOnHolding(receivedItem.getDisplayOnHolding());
    // Piece record might be received or rolled-back to Expected
    if (inventoryManager.isOnOrderItemStatus(receivedItem)) {
        piece.setReceivedDate(null);
        piece.setReceivingStatus(Piece.ReceivingStatus.EXPECTED);
    } else {
        piece.setReceivedDate(new Date());
        piece.setReceivingStatus(Piece.ReceivingStatus.RECEIVED);
    }
}
Also used : ReceivedItem(org.folio.rest.jaxrs.model.ReceivedItem) Date(java.util.Date)

Example 4 with ReceivedItem

use of org.folio.rest.jaxrs.model.ReceivedItem in project mod-orders by folio-org.

the class ReceivingHelper method prepareResponseBody.

private ReceivingResults prepareResponseBody(ReceivingCollection receivingCollection, Map<String, List<Piece>> piecesGroupedByPoLine) {
    ReceivingResults results = new ReceivingResults();
    results.setTotalRecords(receivingCollection.getTotalRecords());
    for (ToBeReceived toBeReceived : receivingCollection.getToBeReceived()) {
        String poLineId = toBeReceived.getPoLineId();
        ReceivingResult result = new ReceivingResult();
        results.getReceivingResults().add(result);
        // Get all processed piece records for PO Line
        Map<String, Piece> processedPiecesForPoLine = StreamEx.of(piecesGroupedByPoLine.getOrDefault(poLineId, Collections.emptyList())).toMap(Piece::getId, piece -> piece);
        Map<String, Integer> resultCounts = new HashMap<>();
        resultCounts.put(ProcessingStatus.Type.SUCCESS.toString(), 0);
        resultCounts.put(ProcessingStatus.Type.FAILURE.toString(), 0);
        for (ReceivedItem receivedItem : toBeReceived.getReceivedItems()) {
            String pieceId = receivedItem.getPieceId();
            calculateProcessingErrors(poLineId, result, processedPiecesForPoLine, resultCounts, pieceId);
        }
        result.withPoLineId(poLineId).withProcessedSuccessfully(resultCounts.get(ProcessingStatus.Type.SUCCESS.toString())).withProcessedWithError(resultCounts.get(ProcessingStatus.Type.FAILURE.toString()));
    }
    return results;
}
Also used : ReceivingResult(org.folio.rest.jaxrs.model.ReceivingResult) ReceivedItem(org.folio.rest.jaxrs.model.ReceivedItem) HashMap(java.util.HashMap) ToBeReceived(org.folio.rest.jaxrs.model.ToBeReceived) Piece(org.folio.rest.jaxrs.model.Piece) ReceivingResults(org.folio.rest.jaxrs.model.ReceivingResults)

Aggregations

ReceivedItem (org.folio.rest.jaxrs.model.ReceivedItem)4 JsonObject (io.vertx.core.json.JsonObject)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Piece (org.folio.rest.jaxrs.model.Piece)2 PoLine (org.folio.rest.jaxrs.model.PoLine)2 Context (io.vertx.core.Context)1 JsonArray (io.vertx.core.json.JsonArray)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors.collectingAndThen (java.util.stream.Collectors.collectingAndThen)1 Collectors.mapping (java.util.stream.Collectors.mapping)1 Collectors.toList (java.util.stream.Collectors.toList)1 StreamEx (one.util.streamex.StreamEx)1 StringUtils (org.apache.commons.lang3.StringUtils)1