use of org.folio.service.inventory.InventoryManagerTest.ONLY_NEW_HOLDING_EXIST_ID in project mod-orders by folio-org.
the class MockServer method handleGetHoldingsRecords.
private void handleGetHoldingsRecords(RoutingContext ctx) {
logger.info("handleGetHoldingRecord got: " + ctx.request().path());
String queryParam = ctx.queryParam("query").get(0);
JsonObject holdings;
try {
if ((queryParam.contains(OLD_HOLDING_ID) && queryParam.contains(NEW_HOLDING_ID))) {
holdings = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH));
} else if (queryParam.contains(OLD_LOCATION_ID) && queryParam.contains(NON_EXISTED_NEW_HOLDING_ID)) {
List holdingsList = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH)).getJsonArray("holdingsRecords").stream().map(o -> ((JsonObject) o)).filter(holding -> holding.getString("permanentLocationId").equals(OLD_LOCATION_ID)).collect(toList());
holdings = new JsonObject().put("holdingsRecords", new JsonArray(holdingsList));
} else if (queryParam.contains(OLD_LOCATION_ID) && !queryParam.contains(NON_EXISTED_NEW_HOLDING_ID)) {
List holdingsList = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH)).getJsonArray("holdingsRecords").stream().map(o -> ((JsonObject) o)).filter(holding -> holding.getString("permanentLocationId").equals(OLD_LOCATION_ID) || !holding.getString("permanentLocationId").equals(NON_EXISTED_NEW_HOLDING_ID)).collect(toList());
holdings = new JsonObject().put("holdingsRecords", new JsonArray(holdingsList));
} else {
holdings = new JsonObject().put("holdingsRecords", new JsonArray());
}
if (queryParam.contains(NEW_LOCATION_ID) && queryParam.contains(ONLY_NEW_HOLDING_EXIST_ID)) {
List holdingsList = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH)).getJsonArray("holdingsRecords").stream().map(o -> ((JsonObject) o)).filter(holding -> holding.getString("permanentLocationId").equals(NEW_LOCATION_ID)).collect(toList());
holdings = new JsonObject().put("holdingsRecords", new JsonArray(holdingsList));
}
if (queryParam.contains(OLD_LOCATION_ID) && queryParam.contains(HOLDING_INSTANCE_ID_2_HOLDING)) {
List holdingsList = new JsonObject(getMockData(HOLDINGS_OLD_NEW_PATH)).getJsonArray("holdingsRecords").stream().collect(toList());
List doubleList = new ArrayList(holdingsList);
doubleList.addAll(holdingsList);
holdings = new JsonObject().put("holdingsRecords", new JsonArray(doubleList));
}
} catch (IOException e) {
holdings = new JsonObject().put("holdingsRecords", new JsonArray());
}
addServerRqRsData(HttpMethod.GET, HOLDINGS_RECORD, holdings);
serverResponse(ctx, 200, APPLICATION_JSON, holdings.encodePrettily());
}
Aggregations