use of org.folio.rest.acq.model.orders.CompositePurchaseOrder in project mod-invoice by folio-org.
the class MockServer method handleGetOrderById.
private void handleGetOrderById(RoutingContext ctx) {
logger.info("got: " + ctx.request().path());
String id = ctx.request().getParam(AbstractHelper.ID);
logger.info("id: " + id);
addServerRqRsData(HttpMethod.GET, COMPOSITE_ORDER, new JsonObject().put(AbstractHelper.ID, id));
Supplier<JsonObject> getFromFile = () -> {
String filePath = String.format(MOCK_DATA_PATH_PATTERN, ORDER_MOCK_DATA_PATH, id);
try {
return new JsonObject(getMockData(filePath));
} catch (IOException e) {
return null;
}
};
JsonObject order = getMockEntry(COMPOSITE_ORDER, id).orElseGet(getFromFile);
if (order == null) {
ctx.response().setStatusCode(404).end(id);
} else {
// validate content against schema
CompositePurchaseOrder orderSchema = order.mapTo(CompositePurchaseOrder.class);
orderSchema.setId(id);
order = JsonObject.mapFrom(orderSchema);
serverResponse(ctx, 200, APPLICATION_JSON, order.encodePrettily());
}
}
Aggregations