use of org.folio.rest.acq.model.Piece 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.Piece in project mod-orders by folio-org.
the class ReceiptStatusConsistencyTest method testSuccessFullyReceivedStatusWhenAllPiecesSuccessfullyReceived.
@Test
void testSuccessFullyReceivedStatusWhenAllPiecesSuccessfullyReceived(VertxTestContext context) throws Throwable {
logger.info("=== Test case to verify fully received status when all pieces successfully received ===");
CompositePoLine compositePoLine = getMockAsJson(PO_LINES_MOCK_DATA_PATH, POLINE_UUID_TIED_TO_PIECE_FULLY_RECEIVED).mapTo(CompositePoLine.class);
MockServer.addMockTitles(Collections.singletonList(compositePoLine));
sendEvent(createBody(POLINE_UUID_TIED_TO_PIECE_FULLY_RECEIVED), context.succeeding(result -> {
logger.info("getPoLineSearches()--->" + getPoLineSearches());
logger.info("getPoLineUpdates()--->" + getPoLineUpdates());
logger.info("getPieceSearches()--->" + getPieceSearches());
assertEquals(5, getPieceSearches().get(0).getJsonArray("pieces").size());
Piece piece0 = getPieceSearches().get(0).getJsonArray("pieces").getJsonObject(0).mapTo(Piece.class);
Piece piece1 = getPieceSearches().get(0).getJsonArray("pieces").getJsonObject(1).mapTo(Piece.class);
Piece piece2 = getPieceSearches().get(0).getJsonArray("pieces").getJsonObject(2).mapTo(Piece.class);
Piece piece3 = getPieceSearches().get(0).getJsonArray("pieces").getJsonObject(3).mapTo(Piece.class);
Piece piece4 = getPieceSearches().get(0).getJsonArray("pieces").getJsonObject(4).mapTo(Piece.class);
assertEquals(ReceivingStatus.RECEIVED, piece0.getReceivingStatus());
assertEquals(ReceivingStatus.RECEIVED, piece1.getReceivingStatus());
assertEquals(ReceivingStatus.RECEIVED, piece2.getReceivingStatus());
assertEquals(ReceivingStatus.RECEIVED, piece3.getReceivingStatus());
assertEquals(ReceivingStatus.RECEIVED, piece4.getReceivingStatus());
PoLine poLine = getPoLineUpdates().get(0).mapTo(PoLine.class);
assertEquals(ReceiptStatus.FULLY_RECEIVED, poLine.getReceiptStatus());
assertEquals(result.body(), Response.Status.OK.getReasonPhrase());
context.completeNow();
}));
checkVertxContextCompletion(context);
}
use of org.folio.rest.acq.model.Piece in project mod-orders by folio-org.
the class ReceiptStatusConsistencyTest method testSuccessPartiallyReceivedStatusWhenAtleastOneSuccessfullyReceivedPiece.
@Test
void testSuccessPartiallyReceivedStatusWhenAtleastOneSuccessfullyReceivedPiece(VertxTestContext context) throws Throwable {
logger.info("=== Test case to verify partially received status when at least one successfully received piece ===");
CompositePoLine compositePoLine = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(5).mapTo(CompositePoLine.class);
MockServer.addMockTitles(Collections.singletonList(compositePoLine));
sendEvent(createBody(POLINE_UUID_TIED_TO_PIECE_PARTIALLY_RECEIVED), context.succeeding(result -> {
logger.info("getPoLineSearches()--->" + getPoLineSearches());
logger.info("getPoLineUpdates()--->" + getPoLineUpdates());
logger.info("getPieceSearches()--->" + getPieceSearches());
assertEquals(5, getPieceSearches().get(0).getJsonArray("pieces").size());
Piece piece0 = getPieceSearches().get(0).getJsonArray("pieces").getJsonObject(0).mapTo(Piece.class);
Piece piece1 = getPieceSearches().get(0).getJsonArray("pieces").getJsonObject(1).mapTo(Piece.class);
Piece piece2 = getPieceSearches().get(0).getJsonArray("pieces").getJsonObject(2).mapTo(Piece.class);
Piece piece3 = getPieceSearches().get(0).getJsonArray("pieces").getJsonObject(3).mapTo(Piece.class);
Piece piece4 = getPieceSearches().get(0).getJsonArray("pieces").getJsonObject(4).mapTo(Piece.class);
assertEquals(ReceivingStatus.RECEIVED, piece0.getReceivingStatus());
assertEquals(ReceivingStatus.EXPECTED, piece1.getReceivingStatus());
assertEquals(ReceivingStatus.EXPECTED, piece2.getReceivingStatus());
assertEquals(ReceivingStatus.EXPECTED, piece3.getReceivingStatus());
assertEquals(ReceivingStatus.EXPECTED, piece4.getReceivingStatus());
PoLine poLine = getPoLineUpdates().get(0).mapTo(PoLine.class);
assertEquals(ReceiptStatus.PARTIALLY_RECEIVED, poLine.getReceiptStatus());
assertEquals(result.body(), Response.Status.OK.getReasonPhrase());
context.completeNow();
}));
checkVertxContextCompletion(context);
}
Aggregations