Search in sources :

Example 1 with BudgetCollection

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

the class MockServer method handleGetBudgetByFinanceId.

private void handleGetBudgetByFinanceId(RoutingContext ctx) {
    logger.info("handleGetInvoiceDocumentById got: GET " + ctx.request().path());
    String fundId = ctx.request().getParam("id");
    JsonObject collection = getBudgetsByFundIds(Collections.singletonList(fundId));
    BudgetCollection budgetCollection = collection.mapTo(BudgetCollection.class);
    if (budgetCollection.getTotalRecords() > 0) {
        Budget budget = budgetCollection.getBudgets().get(0);
        JsonObject budgetJson = JsonObject.mapFrom(budget);
        addServerRqRsData(HttpMethod.GET, CURRENT_BUDGET, budgetJson);
        ctx.response().setStatusCode(200).putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON).end(budgetJson.encodePrettily());
    } else {
        ctx.response().setStatusCode(404).end();
    }
}
Also used : BudgetCollection(org.folio.rest.acq.model.finance.BudgetCollection) JsonObject(io.vertx.core.json.JsonObject) Budget(org.folio.rest.acq.model.finance.Budget)

Example 2 with BudgetCollection

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

the class MockServer method getBudgetsByFundIds.

private JsonObject getBudgetsByFundIds(List<String> budgetByFundIds) {
    Supplier<List<Budget>> getFromFile = () -> {
        try {
            return new JsonObject(getMockData(BUDGETS_PATH)).mapTo(BudgetCollection.class).getBudgets();
        } catch (IOException e) {
            return Collections.emptyList();
        }
    };
    List<Budget> budgets = getMockEntries(BUDGETS, Budget.class).orElseGet(getFromFile);
    if (!budgetByFundIds.isEmpty()) {
        budgets.removeIf(item -> !budgetByFundIds.contains(item.getFundId()));
    }
    Object record = new BudgetCollection().withBudgets(budgets).withTotalRecords(budgets.size());
    return JsonObject.mapFrom(record);
}
Also used : BudgetCollection(org.folio.rest.acq.model.finance.BudgetCollection) JsonObject(io.vertx.core.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Budget(org.folio.rest.acq.model.finance.Budget) JsonObject(io.vertx.core.json.JsonObject) IOException(java.io.IOException)

Example 3 with BudgetCollection

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

the class MockServer method handleGetBudgetByFundId.

private void handleGetBudgetByFundId(RoutingContext ctx) {
    logger.info("handleGetInvoiceDocumentById got: GET " + ctx.request().path());
    String fundId = ctx.request().getParam("id");
    JsonObject collection = getBudgetsByFundIds(Collections.singletonList(fundId));
    BudgetCollection budgetCollection = collection.mapTo(BudgetCollection.class);
    if (fundId.equals(FUND_ID_WITH_NOT_ACTIVE_BUDGET)) {
        ctx.response().setStatusCode(404).end();
    } else if (budgetCollection.getTotalRecords() > 0) {
        Budget budget = budgetCollection.getBudgets().get(0);
        JsonObject budgetJson = JsonObject.mapFrom(budget);
        addServerRqRsData(HttpMethod.GET, CURRENT_BUDGET, budgetJson);
        ctx.response().setStatusCode(200).putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON).end(budgetJson.encodePrettily());
    } else {
        ctx.response().setStatusCode(404).end();
    }
}
Also used : BudgetCollection(org.folio.rest.acq.model.finance.BudgetCollection) JsonObject(io.vertx.core.json.JsonObject) Budget(org.folio.rest.acq.model.finance.Budget)

Example 4 with BudgetCollection

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

the class MockServer method getBudgetsByFundIds.

private JsonObject getBudgetsByFundIds(List<String> budgetByFundIds) {
    Supplier<List<Budget>> getFromFile = () -> {
        try {
            return new JsonObject(getMockData(BUDGETS_PATH)).mapTo(BudgetCollection.class).getBudgets();
        } catch (IOException e) {
            return Collections.emptyList();
        }
    };
    List<Budget> budgets = getMockEntries(BUDGETS, Budget.class).orElseGet(getFromFile);
    if (!budgetByFundIds.isEmpty()) {
        budgets.removeIf(item -> !budgetByFundIds.contains(item.getFundId()));
    }
    Object record = new BudgetCollection().withBudgets(budgets).withTotalRecords(budgets.size());
    return JsonObject.mapFrom(record);
}
Also used : BudgetCollection(org.folio.rest.acq.model.finance.BudgetCollection) JsonObject(io.vertx.core.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Budget(org.folio.rest.acq.model.finance.Budget) JsonObject(io.vertx.core.json.JsonObject) IOException(java.io.IOException)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)4 Budget (org.folio.rest.acq.model.finance.Budget)4 BudgetCollection (org.folio.rest.acq.model.finance.BudgetCollection)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2