use of org.folio.rest.acq.model.Title 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.Title in project mod-orders by folio-org.
the class MockServer method handleGetOrderTitleById.
private void handleGetOrderTitleById(RoutingContext ctx) {
logger.info("got: " + ctx.request().path());
String id = ctx.request().getParam(ID);
logger.info("id: " + id);
addServerRqRsData(HttpMethod.GET, TITLES, new JsonObject().put(ID, id));
if (ID_FOR_INTERNAL_SERVER_ERROR.equals(id)) {
serverResponse(ctx, 500, APPLICATION_JSON, INTERNAL_SERVER_ERROR.getReasonPhrase());
} else {
try {
// Attempt to find title in mock server memory
JsonObject existantTitle = getMockEntry(TITLES, id).orElse(null);
// If previous step has no result then attempt to find title in stubs
if (existantTitle == null) {
Title title = new JsonObject(getMockData(String.format("%s%s.json", TITLES_MOCK_DATA_PATH, id))).mapTo(Title.class);
existantTitle = JsonObject.mapFrom(title);
}
serverResponse(ctx, 200, APPLICATION_JSON, existantTitle.encodePrettily());
} catch (IOException e) {
serverResponse(ctx, 404, APPLICATION_JSON, id);
}
}
}
use of org.folio.rest.acq.model.Title in project mod-orders by folio-org.
the class PurchaseOrderLinesApiTest method testPutOrderLineWithNoTags.
@Test
void testPutOrderLineWithNoTags() {
logger.info("=== Test PUT Order Line With No Tags ===");
String lineId = "bb66b269-76ed-4616-8da9-730d9b817247";
CompositePoLine body = getMockAsJson(COMP_PO_LINES_MOCK_DATA_PATH, lineId).mapTo(CompositePoLine.class);
body.setCheckinItems(false);
body.setIsPackage(false);
body.setReceiptStatus(ReceiptStatus.AWAITING_RECEIPT);
body.setReportingCodes(new ArrayList<>());
MockServer.addMockEntry(PO_LINES_STORAGE, body);
MockServer.addMockEntry(PURCHASE_ORDER_STORAGE, new CompositePurchaseOrder().withId(ID_FOR_PRINT_MONOGRAPH_ORDER).withWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN).withOrderType(CompositePurchaseOrder.OrderType.ONE_TIME));
String url = String.format(LINE_BY_ID_PATH, lineId);
addMockEntry(TITLES, new Title().withId(UUID.randomUUID().toString()).withPoLineId(body.getId()).withTitle("Title"));
// edit POLine for new encumbrance
body.setTags(null);
body.setFundDistribution(Collections.singletonList(new FundDistribution().withCode("EUROHIST").withFundId("e9285a1c-1dfc-4380-868c-e74073003f43").withDistributionType(FundDistribution.DistributionType.PERCENTAGE).withValue(100D)));
verifyPut(url, JsonObject.mapFrom(body), "", 204);
Transaction createdEncumbrance = MockServer.getCreatedEncumbrances().get(0);
assertNull(createdEncumbrance.getTags());
// edit POLine for encumbrance update
body.setTags(null);
body.setCost(new Cost().withCurrency("USD").withListUnitPrice(70.0).withQuantityPhysical(1));
body.setFundDistribution(Collections.singletonList(new FundDistribution().withCode("EUROHIST").withFundId("a89eccf0-57a6-495e-898d-32b9b2210f2f").withDistributionType(FundDistribution.DistributionType.PERCENTAGE).withValue(100D)));
verifyPut(url, JsonObject.mapFrom(body), "", 204);
Transaction updatedEncumbrance = MockServer.getUpdatedTransactions().get(0);
assertNull(updatedEncumbrance.getTags());
}
use of org.folio.rest.acq.model.Title in project mod-orders by folio-org.
the class TitlesApiTest method testPutTitlesByNonExistentId.
@Test
void testPutTitlesByNonExistentId() {
logger.info("=== Test update title by id - Id does not exists 404 ===");
Title reqData = titleJsonReqData.mapTo(Title.class);
reqData.setId(ID_DOES_NOT_EXIST);
String jsonBody = JsonObject.mapFrom(reqData).encode();
verifyPut(String.format(TITLES_ID_PATH, ID_DOES_NOT_EXIST), jsonBody, APPLICATION_JSON, 404);
}
use of org.folio.rest.acq.model.Title in project mod-orders by folio-org.
the class TitlesApiTest method testPutTitlesWithError.
@Test
void testPutTitlesWithError() {
logger.info("=== Test update title by id - internal error from storage 500 ===");
Title reqData = titleJsonReqData.mapTo(Title.class);
reqData.setId(ID_FOR_INTERNAL_SERVER_ERROR);
String jsonBody = JsonObject.mapFrom(reqData).encode();
verifyPut(String.format(TITLES_ID_PATH, ID_FOR_INTERNAL_SERVER_ERROR), jsonBody, APPLICATION_JSON, 500);
}
Aggregations