use of org.folio.rest.acq.model.PieceCollection in project mod-orders by folio-org.
the class MockServer method handleGetPieces.
private void handleGetPieces(RoutingContext ctx) {
logger.info("handleGetPieces got: " + ctx.request().path());
String query = ctx.request().getParam("query");
if (query.contains(ID_FOR_PIECES_INTERNAL_SERVER_ERROR)) {
addServerRqRsData(HttpMethod.GET, PIECES_STORAGE, new JsonObject());
serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
} else {
PieceCollection pieces;
if (getMockEntries(PIECES_STORAGE, Piece.class).isPresent()) {
pieces = new PieceCollection().withPieces(getMockEntries(PIECES_STORAGE, Piece.class).get());
pieces.setTotalRecords(pieces.getPieces().size());
} else {
try {
if (query.contains("poLineId==")) {
List<String> conditions = StreamEx.split(query, " or ").flatMap(s -> StreamEx.split(s, " and ")).toList();
String polId = EMPTY;
String status = EMPTY;
for (String condition : conditions) {
if (condition.startsWith("poLineId")) {
polId = condition.split("poLineId==")[1];
} else if (condition.startsWith("receivingStatus")) {
status = condition.split("receivingStatus==")[1];
}
}
logger.info("poLineId: " + polId);
logger.info("receivingStatus: " + status);
String path = PIECE_RECORDS_MOCK_DATA_PATH + String.format("pieceRecords-%s.json", polId);
pieces = new JsonObject(getMockData(path)).mapTo(PieceCollection.class);
// Filter piece records by receiving status
if (StringUtils.isNotEmpty(status)) {
Piece.ReceivingStatus receivingStatus = Piece.ReceivingStatus.fromValue(status);
pieces.getPieces().removeIf(piece -> receivingStatus != piece.getReceivingStatus());
}
} else if (query.contains("id==")) {
pieces = new JsonObject(getMockData(PIECE_RECORDS_MOCK_DATA_PATH + "pieceRecordsCollection.json")).mapTo(PieceCollection.class);
// if (query.contains("id==")) {
List<String> pieceIds = extractIdsFromQuery(query);
pieces.getPieces().removeIf(piece -> !pieceIds.contains(piece.getId()));
// fix consistency with titles: the piece's title id should be the same as one of the titles ids
// returned for the piece's po line
pieces.getPieces().forEach(piece -> {
String poLineId = piece.getPoLineId();
List<Title> titlesForPoLine = getTitlesByPoLineIds(List.of(poLineId)).mapTo(TitleCollection.class).getTitles();
if (titlesForPoLine.size() > 0 && titlesForPoLine.stream().noneMatch(title -> title.getId().equals(piece.getTitleId())))
piece.setTitleId(titlesForPoLine.get(0).getId());
});
} else {
pieces = new PieceCollection();
}
pieces.setTotalRecords(pieces.getPieces().size());
} catch (Exception e) {
pieces = new PieceCollection();
pieces.setTotalRecords(0);
}
}
JsonObject data = JsonObject.mapFrom(pieces);
addServerRqRsData(HttpMethod.GET, PIECES_STORAGE, data);
ctx.response().setStatusCode(200).putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON).end(data.encodePrettily());
}
}
use of org.folio.rest.acq.model.PieceCollection 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());
}
Aggregations