Search in sources :

Example 1 with ExpenseClassCollection

use of org.folio.rest.acq.model.finance.ExpenseClassCollection in project mod-orders by folio-org.

the class MockServer method handleGetExpenseClasses.

private void handleGetExpenseClasses(RoutingContext ctx) {
    logger.info("handleGetExpenseClasses: " + ctx.request().path());
    try {
        ExpenseClassCollection expenseClassCollection = new JsonObject(getMockData(EXPENSE_CLASSES_MOCK_DATA_PATH)).mapTo(ExpenseClassCollection.class);
        JsonObject entries = JsonObject.mapFrom(expenseClassCollection);
        serverResponse(ctx, 200, APPLICATION_JSON, entries.encodePrettily());
    } catch (IOException exception) {
        serverResponse(ctx, 500, APPLICATION_JSON, INTERNAL_SERVER_ERROR.getReasonPhrase());
    }
}
Also used : JsonObject(io.vertx.core.json.JsonObject) IOException(java.io.IOException) ExpenseClassCollection(org.folio.rest.acq.model.finance.ExpenseClassCollection) BudgetExpenseClassCollection(org.folio.rest.acq.model.finance.BudgetExpenseClassCollection)

Example 2 with ExpenseClassCollection

use of org.folio.rest.acq.model.finance.ExpenseClassCollection in project mod-invoice by folio-org.

the class MockServer method handleExpenseClasses.

private void handleExpenseClasses(RoutingContext ctx) {
    logger.info("handleExpenseClasses got: {}?{}", ctx.request().path(), ctx.request().query());
    String queryParam = StringUtils.trimToEmpty(ctx.request().getParam(QUERY));
    String tenant = ctx.request().getHeader(OKAPI_HEADER_TENANT);
    if (queryParam.contains(BAD_QUERY)) {
        serverResponse(ctx, 400, APPLICATION_JSON, Response.Status.BAD_REQUEST.getReasonPhrase());
    } else if (queryParam.contains(ID_FOR_INTERNAL_SERVER_ERROR) || GET_VOUCHERS_ERROR_TENANT.equals(tenant)) {
        serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
    } else {
        Supplier<List<ExpenseClass>> getFromFile = () -> {
            try {
                return new JsonObject(getMockData(EXPENSE_CLASSES_LIST_PATH)).mapTo(ExpenseClassCollection.class).getExpenseClasses();
            } catch (IOException e) {
                return Collections.emptyList();
            }
        };
        ExpenseClassCollection expenseClassCollection = new ExpenseClassCollection();
        List<ExpenseClass> expenseClasses = getMockEntries(ResourcePathResolver.resourcesPath(EXPENSE_CLASSES_URL), ExpenseClass.class).orElseGet(getFromFile);
        expenseClassCollection.withExpenseClasses(expenseClasses);
        JsonObject expenseClassesJson = JsonObject.mapFrom(expenseClassCollection);
        logger.info(expenseClassesJson.encodePrettily());
        addServerRqRsData(HttpMethod.GET, BATCH_GROUPS, expenseClassesJson);
        serverResponse(ctx, 200, APPLICATION_JSON, expenseClassesJson.encode());
    }
}
Also used : ExpenseClass(org.folio.rest.acq.model.finance.ExpenseClass) JsonObject(io.vertx.core.json.JsonObject) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) IOException(java.io.IOException) ExpenseClassCollection(org.folio.rest.acq.model.finance.ExpenseClassCollection) BudgetExpenseClassCollection(org.folio.rest.acq.model.finance.BudgetExpenseClassCollection)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)2 IOException (java.io.IOException)2 BudgetExpenseClassCollection (org.folio.rest.acq.model.finance.BudgetExpenseClassCollection)2 ExpenseClassCollection (org.folio.rest.acq.model.finance.ExpenseClassCollection)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Supplier (java.util.function.Supplier)1 Collectors.toList (java.util.stream.Collectors.toList)1 ExpenseClass (org.folio.rest.acq.model.finance.ExpenseClass)1