use of org.folio.rest.jaxrs.model.ReceivingResult in project mod-orders by folio-org.
the class CheckinReceivingApiTest method testPostReceivingPhysicalWithErrors.
@Test
void testPostReceivingPhysicalWithErrors() throws IOException {
logger.info("=== Test POST Receiving - Receive physical resources with different errors");
ReceivingCollection receivingRq = getMockAsJson(RECEIVING_RQ_MOCK_DATA_PATH + "receive-physical-resources-6-of-10-with-errors.json").mapTo(ReceivingCollection.class);
CompositePoLine poLines = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(3).mapTo(CompositePoLine.class);
MockServer.addMockTitles(Collections.singletonList(poLines));
ReceivingResults results = verifyPostResponse(ORDERS_RECEIVING_ENDPOINT, JsonObject.mapFrom(receivingRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10), APPLICATION_JSON, 200).as(ReceivingResults.class);
assertThat(results.getTotalRecords(), is(receivingRq.getTotalRecords()));
assertThat(results.getReceivingResults(), hasSize(1));
ReceivingResult receivingResult = results.getReceivingResults().get(0);
assertThat(receivingResult.getPoLineId(), not(is(emptyString())));
assertThat(receivingResult.getProcessedSuccessfully(), is(5));
assertThat(receivingResult.getProcessedWithError(), is(5));
Set<String> errorCodes = new HashSet<>();
for (ReceivingItemResult receivingItemResult : receivingResult.getReceivingItemResults()) {
assertThat(receivingItemResult.getPieceId(), not(is(emptyString())));
assertThat(receivingItemResult.getProcessingStatus(), not(nullValue()));
if (receivingItemResult.getProcessingStatus().getType() == SUCCESS) {
assertThat(receivingItemResult.getProcessingStatus().getError(), nullValue());
} else {
assertThat(receivingItemResult.getProcessingStatus().getError(), not(nullValue()));
errorCodes.add(receivingItemResult.getProcessingStatus().getError().getCode());
}
}
assertThat(errorCodes, containsInAnyOrder(PIECE_ALREADY_RECEIVED.getCode(), PIECE_POL_MISMATCH.getCode(), PIECE_NOT_FOUND.getCode(), ITEM_UPDATE_FAILED.getCode(), PIECE_UPDATE_FAILED.getCode()));
List<JsonObject> itemUpdates = getItemUpdates();
List<JsonObject> polUpdates = getPoLineUpdates();
assertThat(getPoLineSearches(), hasSize(1));
assertThat(polUpdates, hasSize(1));
assertThat(itemUpdates, hasSize(6));
itemUpdates.forEach(item -> {
assertThat(item.getJsonObject(ITEM_STATUS), notNullValue());
assertThat(item.getJsonObject(ITEM_STATUS).getString(ITEM_STATUS_NAME), equalTo(ReceivedItem.ItemStatus.IN_PROCESS.value()));
});
polUpdates.forEach(pol -> {
PoLine poLine = pol.mapTo(PoLine.class);
assertThat(poLine.getReceiptStatus(), is(PoLine.ReceiptStatus.PARTIALLY_RECEIVED));
assertThat(poLine.getReceiptDate(), is(nullValue()));
});
verifyProperQuantityOfHoldingsCreated(receivingRq);
// Verify messages sent via event bus
verifyOrderStatusUpdateEvent(1);
}
use of org.folio.rest.jaxrs.model.ReceivingResult in project mod-orders by folio-org.
the class CheckinReceivingApiTest method testPostCheckInPhysicalWithMissingItem.
@Test
void testPostCheckInPhysicalWithMissingItem() {
logger.info("=== Test POST Checkin - CheckIn physical resource with only one item updated");
CompositePoLine poLines = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(7).mapTo(CompositePoLine.class);
MockServer.addMockTitles(Collections.singletonList(poLines));
CheckinCollection checkInRq = getMockAsJson(CHECKIN_RQ_MOCK_DATA_PATH + "checkin-pe-mix-2-physical-resources.json").mapTo(CheckinCollection.class);
ReceivingResults results = verifyPostResponse(ORDERS_CHECKIN_ENDPOINT, JsonObject.mapFrom(checkInRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10), APPLICATION_JSON, 200).as(ReceivingResults.class);
assertThat(results.getTotalRecords(), equalTo(checkInRq.getTotalRecords()));
ReceivingResult receivingResult = results.getReceivingResults().get(0);
for (ReceivingItemResult receivingItemResult : receivingResult.getReceivingItemResults()) {
assertThat(receivingItemResult.getPieceId(), not(is(emptyString())));
assertThat(receivingItemResult.getProcessingStatus(), not(nullValue()));
assertThat(receivingItemResult.getProcessingStatus().getType(), is(SUCCESS));
assertThat(receivingItemResult.getProcessingStatus().getError(), nullValue());
}
List<JsonObject> pieceSearches = getPieceSearches();
List<JsonObject> pieceUpdates = getPieceUpdates();
List<JsonObject> itemsSearches = getItemsSearches();
List<JsonObject> itemUpdates = getItemUpdates();
List<JsonObject> polSearches = getPoLineSearches();
List<JsonObject> polUpdates = getPoLineUpdates();
assertThat(pieceSearches, not(nullValue()));
assertThat(pieceUpdates, not(nullValue()));
assertThat(itemsSearches, not(nullValue()));
assertThat(itemUpdates, not(nullValue()));
assertThat(polSearches, not(nullValue()));
assertThat(polUpdates, not(nullValue()));
assertThat(pieceSearches, hasSize(2));
assertThat(pieceUpdates, hasSize(2));
assertThat(itemsSearches, hasSize(1));
assertThat(itemUpdates, hasSize(1));
assertThat(polSearches, hasSize(1));
assertThat(polUpdates, hasSize(1));
itemUpdates.forEach(item -> {
assertThat(item.getJsonObject(ITEM_STATUS), notNullValue());
assertThat(item.getJsonObject(ITEM_STATUS).getString(ITEM_STATUS_NAME), equalTo(CheckInPiece.ItemStatus.IN_PROCESS.value()));
});
polUpdates.forEach(pol -> {
PoLine poLine = pol.mapTo(PoLine.class);
assertThat(poLine.getCheckinItems(), is(true));
assertThat(poLine.getReceiptStatus(), is(PoLine.ReceiptStatus.PARTIALLY_RECEIVED));
assertThat(poLine.getReceiptDate(), is(notNullValue()));
});
// Verify message is sent via event bus
verifyCheckinOrderStatusUpdateEvent(1);
}
use of org.folio.rest.jaxrs.model.ReceivingResult in project mod-orders by folio-org.
the class CheckinHelper method prepareResponseBody.
private ReceivingResults prepareResponseBody(CheckinCollection checkinCollection, Map<String, List<Piece>> piecesGroupedByPoLine) {
ReceivingResults results = new ReceivingResults();
results.setTotalRecords(checkinCollection.getTotalRecords());
for (ToBeCheckedIn toBeCheckedIn : checkinCollection.getToBeCheckedIn()) {
String poLineId = toBeCheckedIn.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 (CheckInPiece checkinPiece : toBeCheckedIn.getCheckInPieces()) {
String pieceId = checkinPiece.getId();
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;
}
use of org.folio.rest.jaxrs.model.ReceivingResult 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;
}
use of org.folio.rest.jaxrs.model.ReceivingResult in project mod-orders by folio-org.
the class CheckinReceivingApiTest method verifyReceivingSuccessRs.
private Map<String, Set<String>> verifyReceivingSuccessRs(ReceivingResults results) {
Map<String, Set<String>> pieceIdsByPol = new HashMap<>();
for (ReceivingResult receivingResult : results.getReceivingResults()) {
assertThat(receivingResult.getPoLineId(), not(is(emptyString())));
assertThat(receivingResult.getProcessedSuccessfully(), is(receivingResult.getReceivingItemResults().size()));
assertThat(receivingResult.getProcessedWithError(), is(0));
for (ReceivingItemResult receivingItemResult : receivingResult.getReceivingItemResults()) {
assertThat(receivingItemResult.getPieceId(), not(is(emptyString())));
assertThat(receivingItemResult.getProcessingStatus(), not(nullValue()));
assertThat(receivingItemResult.getProcessingStatus().getType(), is(SUCCESS));
assertThat(receivingItemResult.getProcessingStatus().getError(), nullValue());
pieceIdsByPol.computeIfAbsent(receivingResult.getPoLineId(), k -> new HashSet<>()).add(receivingItemResult.getPieceId());
}
}
return pieceIdsByPol;
}
Aggregations