diff --git a/ramls/acq-models b/ramls/acq-models index 1652e69e..c06778a4 160000 --- a/ramls/acq-models +++ b/ramls/acq-models @@ -1 +1 @@ -Subproject commit 1652e69e9e98499b805b698e59efd7d2a51d98b5 +Subproject commit c06778a484802db30023f1e5388a6d2972606ae1 diff --git a/src/main/java/org/folio/rest/impl/FinanceDataApi.java b/src/main/java/org/folio/rest/impl/FinanceDataApi.java index e0c9cd22..44d4ec39 100644 --- a/src/main/java/org/folio/rest/impl/FinanceDataApi.java +++ b/src/main/java/org/folio/rest/impl/FinanceDataApi.java @@ -13,6 +13,7 @@ import org.folio.rest.persist.PgUtil; public class FinanceDataApi implements FinanceStorageFinanceData { + private static final String FINANCE_DATA_VIEW = "finance_data_view"; @Override diff --git a/src/main/resources/templates/db_scripts/all_finance_data_view.sql b/src/main/resources/templates/db_scripts/all_finance_data_view.sql index f40f7954..9c77b4c3 100644 --- a/src/main/resources/templates/db_scripts/all_finance_data_view.sql +++ b/src/main/resources/templates/db_scripts/all_finance_data_view.sql @@ -10,13 +10,15 @@ SELECT 'fundDescription', fund.jsonb ->>'description', 'fundStatus', fund.jsonb ->>'fundStatus', 'fundTags', fund.jsonb ->'tags' -> 'tagList', + 'fundAcqUnitIds', fund.jsonb ->'acqUnitIds', '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' + 'budgetAllowableEncumbrance', budget.jsonb ->>'allowableEncumbrance', + 'budgetAcqUnitIds', budget.jsonb ->'acqUnitIds' ) as jsonb FROM ${myuniversity}_${mymodule}.fiscal_year LEFT OUTER JOIN ${myuniversity}_${mymodule}.ledger diff --git a/src/test/java/org/folio/rest/impl/FinanceDataApiTest.java b/src/test/java/org/folio/rest/impl/FinanceDataApiTest.java index 9491007f..a57733a6 100644 --- a/src/test/java/org/folio/rest/impl/FinanceDataApiTest.java +++ b/src/test/java/org/folio/rest/impl/FinanceDataApiTest.java @@ -4,13 +4,25 @@ 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.folio.rest.utils.TestEntities.BUDGET; +import static org.folio.rest.utils.TestEntities.FISCAL_YEAR; +import static org.folio.rest.utils.TestEntities.FUND; +import static org.folio.rest.utils.TestEntities.LEDGER; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import java.util.List; +import java.util.UUID; + import io.restassured.http.Header; +import io.vertx.core.json.JsonObject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.folio.rest.jaxrs.model.Budget; +import org.folio.rest.jaxrs.model.FiscalYear; +import org.folio.rest.jaxrs.model.Fund; import org.folio.rest.jaxrs.model.FyFinanceDataCollection; +import org.folio.rest.jaxrs.model.Ledger; import org.folio.rest.jaxrs.model.TenantJob; import org.folio.rest.jaxrs.resource.FinanceStorageFinanceData; import org.folio.rest.persist.HelperUtils; @@ -43,26 +55,65 @@ public static void after() { 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); + + var response = getData(FINANCE_DATA_ENDPOINT + "?query=(fiscalYearId==7a4c4d30-3b63-4102-8e2d-3ee5792d7d02)", TENANT_HEADER); + var body = response.getBody().as(FyFinanceDataCollection.class); + var actualFyFinanceData = body.getFyFinanceData().get(0); + + assertEquals("7a4c4d30-3b63-4102-8e2d-3ee5792d7d02", actualFyFinanceData.getFiscalYearId()); + assertNotNull(actualFyFinanceData.getFundId()); + assertNotNull(actualFyFinanceData.getFundCode()); + assertNotNull(actualFyFinanceData.getFundName()); + assertNotNull(actualFyFinanceData.getFundDescription()); + assertNotNull(actualFyFinanceData.getFundStatus()); + assertNotNull(actualFyFinanceData.getFundAcqUnitIds()); + assertNotNull(actualFyFinanceData.getBudgetId()); + assertNotNull(actualFyFinanceData.getBudgetName()); + assertNotNull(actualFyFinanceData.getBudgetStatus()); + assertNotNull(actualFyFinanceData.getBudgetInitialAllocation()); + assertNotNull(actualFyFinanceData.getBudgetAllowableExpenditure()); + assertNotNull(actualFyFinanceData.getBudgetAllowableEncumbrance()); + assertNotNull(actualFyFinanceData.getBudgetAcqUnitIds()); } @Test - public void positive_testResponseOfGet() { - var response = getData(FINANCE_DATA_ENDPOINT + "?query=(fiscalYearId==7a4c4d30-3b63-4102-8e2d-3ee5792d7d02)", TENANT_HEADER); + public void positive_testResponseOfGetWithParamsFiscalYearAndAcqUnitIds() { + var fiscalYearId = UUID.randomUUID().toString(); + var acqUnitId = UUID.randomUUID().toString(); + var fiscalYearAcqUnitEndpoint = String.format("%s?query=(fiscalYearId==%s and fundAcqUnitIds=%s and budgetAcqUnitIds=%s)", + FINANCE_DATA_ENDPOINT, fiscalYearId, acqUnitId, acqUnitId); + createMockData(fiscalYearId, acqUnitId); + + var response = getData(fiscalYearAcqUnitEndpoint, TENANT_HEADER); var body = response.getBody().as(FyFinanceDataCollection.class); + var actualFyFinanceData = body.getFyFinanceData().get(0); + + assertEquals(fiscalYearId, actualFyFinanceData.getFiscalYearId()); + assertEquals(acqUnitId, actualFyFinanceData.getFundAcqUnitIds().get(0)); + assertEquals(acqUnitId, actualFyFinanceData.getBudgetAcqUnitIds().get(0)); + } + + private void createMockData(String fiscalYearId, String acqUnitId) { + var fundId = UUID.randomUUID().toString(); + var ledgerId = UUID.randomUUID().toString(); + var budgetId = UUID.randomUUID().toString(); + + var fiscalYear = new JsonObject(getFile(FISCAL_YEAR.getPathToSampleFile())).mapTo(FiscalYear.class) + .withId(fiscalYearId).withCode("FY2042"); + createEntity(FISCAL_YEAR.getEndpoint(), fiscalYear, TENANT_HEADER); + + var ledger = new JsonObject(getFile(LEDGER.getPathToSampleFile())).mapTo(Ledger.class).withId(ledgerId) + .withCode("first").withName("First Ledger").withFiscalYearOneId(fiscalYearId); + createEntity(LEDGER.getEndpoint(), ledger, TENANT_HEADER); + + var fund = new JsonObject(getFile(FUND.getPathToSampleFile())).mapTo(Fund.class) + .withId(fundId).withCode("first").withName("first").withLedgerId(ledgerId) + .withFundTypeId(null).withAcqUnitIds(List.of(acqUnitId)); + createEntity(FUND.getEndpoint(), fund, TENANT_HEADER); - 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()); + var budget = new JsonObject(getFile(BUDGET.getPathToSampleFile())).mapTo(Budget.class) + .withId(budgetId).withName("first").withFiscalYearId(fiscalYearId).withFundId(fundId) + .withAcqUnitIds(List.of(acqUnitId)); + createEntity(BUDGET.getEndpoint(), budget, TENANT_HEADER); } } diff --git a/src/test/java/org/folio/rest/impl/TestBase.java b/src/test/java/org/folio/rest/impl/TestBase.java index 95150bf5..02a1bd43 100644 --- a/src/test/java/org/folio/rest/impl/TestBase.java +++ b/src/test/java/org/folio/rest/impl/TestBase.java @@ -177,6 +177,14 @@ Response deleteData(String endpoint, String id, Header tenantHeader) { .delete(storageUrl(endpoint)); } + String createEntity(String endpoint, Object entity, Header tenantHeader) { + return postData(endpoint, valueAsString(entity), tenantHeader) + .then().log().all() + .statusCode(201) + .extract() + .path("id"); + } + String createEntity(String endpoint, Object entity) { return postData(endpoint, valueAsString(entity)) .then().log().all()