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());
}
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;
});
}
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);
}
}
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;
}
Aggregations