use of org.folio.rest.impl.InvoicesApiTest.BAD_QUERY in project mod-invoice by folio-org.
the class MockServer method handleGetBudgetExpenseClass.
private void handleGetBudgetExpenseClass(RoutingContext ctx) {
logger.info("handle BudgetExpenseClasses got: {}?{}", ctx.request().path(), ctx.request().query());
String tenant = ctx.request().getHeader(OKAPI_HEADER_TENANT);
String queryParam = StringUtils.trimToEmpty(ctx.request().getParam(QUERY));
addServerRqQuery(BUDGET_EXPENSE_CLASSES, queryParam);
if (queryParam.contains(BAD_QUERY)) {
serverResponse(ctx, 400, APPLICATION_JSON, Response.Status.BAD_REQUEST.getReasonPhrase());
} else if (queryParam.contains(ID_FOR_INTERNAL_SERVER_ERROR)) {
serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
} else {
// By default return 0
BudgetExpenseClassCollection budgetExpenseClasses = new BudgetExpenseClassCollection().withTotalRecords(0);
if (queryParam.contains(EXPENSE_CLASS_ID)) {
String expenseClassId = queryParam.split(EXPENSE_CLASS_ID + "==")[1];
Supplier<BudgetExpenseClassCollection> getFromFile = () -> {
try {
return new JsonObject(getMockData(BUDGET_EXPENSE_CLASS_COLLECTION)).mapTo(BudgetExpenseClassCollection.class);
} catch (IOException e) {
return new BudgetExpenseClassCollection().withTotalRecords(0);
}
};
budgetExpenseClasses.withBudgetExpenseClasses(getFromFile.get().getBudgetExpenseClasses().stream().filter(bec -> bec.getExpenseClassId().equals(expenseClassId)).collect(toList()));
budgetExpenseClasses.withTotalRecords(budgetExpenseClasses.getBudgetExpenseClasses().size());
}
JsonObject budgetExpenseClassesJson = JsonObject.mapFrom(budgetExpenseClasses);
logger.info(budgetExpenseClassesJson.encodePrettily());
addServerRqRsData(HttpMethod.GET, BUDGET_EXPENSE_CLASSES, budgetExpenseClassesJson);
serverResponse(ctx, 200, APPLICATION_JSON, budgetExpenseClassesJson.encodePrettily());
}
}
Aggregations