-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MODFISTO-500] - Implement endpoint to return all finance data for FY (…
…#432) * [MODFISTO-500] - Implement endpoint to return all finance data for FY * [MODFISTO-500] - Implement endpoint to return all finance data for FY * Removed unnecessary tests from TestEntities * Minor improvements * added to StorageTestSuite * remove drop part * Update acq-model to master branch
- Loading branch information
Showing
9 changed files
with
193 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule acq-models
updated
14 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#%RAML 1.0 | ||
title: "mod-finance-storage" | ||
baseUri: https://github.com/folio-org/mod-finance-storage | ||
version: v1 | ||
|
||
documentation: | ||
- title: mod-finance-storage (Funds) | ||
content: <b>CRUD APIs used to retrieve finance data for a fiscal year</b> | ||
|
||
types: | ||
errors: !include raml-util/schemas/errors.schema | ||
fy-finance-data-collection: !include acq-models/mod-finance/schemas/fy_finance_data_collection.json | ||
UUID: | ||
type: string | ||
pattern: ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$ | ||
|
||
traits: | ||
pageable: !include raml-util/traits/pageable.raml | ||
searchable: !include raml-util/traits/searchable.raml | ||
validate: !include raml-util/traits/validation.raml | ||
|
||
resourceTypes: | ||
collection-get: !include raml-util/rtypes/collection-get.raml | ||
|
||
/finance-storage/finance-data: | ||
type: | ||
collection-get: | ||
exampleCollection: !include acq-models/mod-finance/examples/fy_finance_data_collection.sample | ||
schemaCollection: fy-finance-data-collection | ||
get: | ||
description: Get finance data for a fiscal year | ||
is: [ | ||
searchable: { description: "with valid searchable fields: for example fiscalYearId", example: "[\"fiscalYearId\", \"7a4c4d30-3b63-4102-8e2d-3ee5792d7d02\", \"=\"]" }, | ||
pageable | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.folio.rest.impl; | ||
|
||
|
||
import javax.ws.rs.core.Response; | ||
import java.util.Map; | ||
|
||
import io.vertx.core.AsyncResult; | ||
import io.vertx.core.Context; | ||
import io.vertx.core.Handler; | ||
import org.folio.rest.jaxrs.model.FyFinanceData; | ||
import org.folio.rest.jaxrs.model.FyFinanceDataCollection; | ||
import org.folio.rest.jaxrs.resource.FinanceStorageFinanceData; | ||
import org.folio.rest.persist.PgUtil; | ||
|
||
public class FinanceDataApi implements FinanceStorageFinanceData { | ||
private static final String FINANCE_DATA_VIEW = "finance_data_view"; | ||
|
||
@Override | ||
public void getFinanceStorageFinanceData(String query, String totalRecords, int offset, int limit, Map<String, String> okapiHeaders, | ||
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) { | ||
PgUtil.get(FINANCE_DATA_VIEW, FyFinanceData.class, FyFinanceDataCollection.class, query, offset, limit, | ||
okapiHeaders, vertxContext, GetFinanceStorageFinanceDataResponse.class, asyncResultHandler); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/resources/templates/db_scripts/all_finance_data_view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CREATE OR REPLACE VIEW ${myuniversity}_${mymodule}.finance_data_view AS | ||
SELECT | ||
fiscal_year.id as id, | ||
jsonb_build_object( | ||
'fiscalYearId', fiscal_year.id, | ||
'fiscalYearCode', fiscal_year.jsonb ->>'code', | ||
'fundId', fund.id, | ||
'fundCode', fund.jsonb ->>'code', | ||
'fundName', fund.jsonb ->>'name', | ||
'fundDescription', fund.jsonb ->>'description', | ||
'fundStatus', fund.jsonb ->>'fundStatus', | ||
'fundTags', fund.jsonb ->'tags' -> 'tagList', | ||
'budgetId', budget.id, | ||
'budgetName', budget.jsonb ->>'name', | ||
'budgetStatus', budget.jsonb ->>'budgetStatus', | ||
'budgetInitialAllocation', budget.jsonb ->>'initialAllocation', | ||
'budgetCurrentAllocation', budget.jsonb ->>'allocated', | ||
'budgetAllowableExpenditure', budget.jsonb ->>'allowableExpenditure', | ||
'budgetAllowableEncumbrance', budget.jsonb ->>'allowableEncumbrance' | ||
) as jsonb | ||
FROM ${myuniversity}_${mymodule}.fiscal_year | ||
LEFT OUTER JOIN ${myuniversity}_${mymodule}.ledger | ||
ON ledger.fiscalyearoneid = fiscal_year.id | ||
LEFT OUTER JOIN ${myuniversity}_${mymodule}.fund | ||
ON fund.ledgerid = ledger.id | ||
LEFT OUTER JOIN ${myuniversity}_${mymodule}.budget | ||
ON fund.id = budget.fundid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.folio.rest.impl; | ||
|
||
import static org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT; | ||
import static org.folio.rest.utils.TenantApiTestUtil.deleteTenant; | ||
import static org.folio.rest.utils.TenantApiTestUtil.prepareTenant; | ||
import static org.folio.rest.utils.TenantApiTestUtil.purge; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import io.restassured.http.Header; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.folio.rest.jaxrs.model.FyFinanceDataCollection; | ||
import org.folio.rest.jaxrs.model.TenantJob; | ||
import org.folio.rest.jaxrs.resource.FinanceStorageFinanceData; | ||
import org.folio.rest.persist.HelperUtils; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
public class FinanceDataApiTest extends TestBase { | ||
private static final String TENANT_NAME = "fyfinancedata"; | ||
private static final Header TENANT_HEADER = new Header(OKAPI_HEADER_TENANT, TENANT_NAME); | ||
private static final Logger logger = LogManager.getLogger(); | ||
private static final String FINANCE_DATA_ENDPOINT = HelperUtils.getEndpoint(FinanceStorageFinanceData.class); | ||
private static TenantJob tenantJob; | ||
|
||
@BeforeAll | ||
public static void before() { | ||
logger.info("Create a new tenant loading the sample data"); | ||
tenantJob = prepareTenant(TENANT_HEADER, true, true); | ||
} | ||
|
||
@AfterAll | ||
public static void after() { | ||
logger.info("Delete the created \"fyfinancedata\" tenant"); | ||
purge(TENANT_HEADER); | ||
deleteTenant(tenantJob, TENANT_HEADER); | ||
} | ||
|
||
@Test | ||
public void positive_testGetQuery() { | ||
verifyCollectionQuantity(FINANCE_DATA_ENDPOINT + "?query=(fiscalYearId==7a4c4d30-3b63-4102-8e2d-3ee5792d7d02)", 21, TENANT_HEADER); | ||
verifyCollectionQuantity(FINANCE_DATA_ENDPOINT + "?query=(fiscalYearId==9b1d00d1-1f3d-4f1c-8e4b-0f1e3b7b1b1b)", 0, TENANT_HEADER); | ||
} | ||
|
||
@Test | ||
public void positive_testResponseOfGet() { | ||
var response = getData(FINANCE_DATA_ENDPOINT + "?query=(fiscalYearId==7a4c4d30-3b63-4102-8e2d-3ee5792d7d02)", TENANT_HEADER); | ||
var body = response.getBody().as(FyFinanceDataCollection.class); | ||
|
||
var fyFinanceDataExample = body.getFyFinanceData().get(0); | ||
assertEquals("7a4c4d30-3b63-4102-8e2d-3ee5792d7d02", fyFinanceDataExample.getFiscalYearId()); | ||
assertNotNull(fyFinanceDataExample.getFundId()); | ||
assertNotNull(fyFinanceDataExample.getFundCode()); | ||
assertNotNull(fyFinanceDataExample.getFundName()); | ||
assertNotNull(fyFinanceDataExample.getFundDescription()); | ||
assertNotNull(fyFinanceDataExample.getFundStatus()); | ||
assertNotNull(fyFinanceDataExample.getBudgetId()); | ||
assertNotNull(fyFinanceDataExample.getBudgetName()); | ||
assertNotNull(fyFinanceDataExample.getBudgetStatus()); | ||
assertNotNull(fyFinanceDataExample.getBudgetInitialAllocation()); | ||
assertNotNull(fyFinanceDataExample.getBudgetCurrentAllocation()); | ||
assertNotNull(fyFinanceDataExample.getBudgetAllowableExpenditure()); | ||
assertNotNull(fyFinanceDataExample.getBudgetAllowableEncumbrance()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters