diff --git a/ramls/acq-models b/ramls/acq-models index d6dac0a6..0d8f736a 160000 --- a/ramls/acq-models +++ b/ramls/acq-models @@ -1 +1 @@ -Subproject commit d6dac0a62d1dc2c95a74c6463976147965b1e9d2 +Subproject commit 0d8f736a3f2b5401a5cfad20a95bd831843f77a6 diff --git a/src/main/java/org/folio/dao/fund/FundPostgresDAO.java b/src/main/java/org/folio/dao/fund/FundPostgresDAO.java index d4616778..1a13360d 100644 --- a/src/main/java/org/folio/dao/fund/FundPostgresDAO.java +++ b/src/main/java/org/folio/dao/fund/FundPostgresDAO.java @@ -26,6 +26,12 @@ public class FundPostgresDAO implements FundDAO { private static final Logger logger = LogManager.getLogger(); private static final String FUND_NOT_FOUND = "Fund not found, id=%s"; + private static final String QUERY_UPDATE_CURRENT_FY_BUDGET = + "UPDATE %s SET jsonb = jsonb_set(jsonb,'{budgetStatus}', $1) " + + "WHERE((fundId=$2) " + + "AND (budget.fiscalYearId IN " + + "(SELECT id FROM %s WHERE current_date between (jsonb->>'periodStart')::timestamp " + + "AND (jsonb->>'periodEnd')::timestamp)));"; @Override public Future getFundById(String id, DBConn conn) { @@ -64,14 +70,9 @@ public Future isFundStatusChanged(Fund fund, DBConn conn) { public Future updateRelatedCurrentFYBudgets(Fund fund, DBConn conn) { String fullBudgetTableName = getFullTableName(conn.getTenantId(), BUDGET_TABLE); String fullFYTableName = getFullTableName(conn.getTenantId(), FISCAL_YEAR_TABLE); + String updateQuery = String.format(QUERY_UPDATE_CURRENT_FY_BUDGET, fullBudgetTableName, fullFYTableName); - String sql = "UPDATE " + fullBudgetTableName + " SET jsonb = jsonb_set(jsonb,'{budgetStatus}', $1) " + - "WHERE((fundId=$2) " + - "AND (budget.fiscalYearId IN " + - "(SELECT id FROM " + fullFYTableName + " WHERE current_date between (jsonb->>'periodStart')::timestamp " + - "AND (jsonb->>'periodEnd')::timestamp)));"; - - return conn.execute(sql, Tuple.of(fund.getFundStatus().value(), UUID.fromString(fund.getId()))) + return conn.execute(updateQuery, Tuple.of(fund.getFundStatus().value(), UUID.fromString(fund.getId()))) .mapEmpty(); } diff --git a/src/main/java/org/folio/rest/impl/FundAPI.java b/src/main/java/org/folio/rest/impl/FundAPI.java index a73f5c2e..56f4fa31 100644 --- a/src/main/java/org/folio/rest/impl/FundAPI.java +++ b/src/main/java/org/folio/rest/impl/FundAPI.java @@ -14,12 +14,11 @@ import org.apache.logging.log4j.Logger; import org.folio.rest.annotations.Validate; import org.folio.rest.core.model.RequestContext; -import org.folio.rest.exception.HttpException; import org.folio.rest.jaxrs.model.Fund; import org.folio.rest.jaxrs.model.FundCollection; import org.folio.rest.jaxrs.resource.FinanceStorageFunds; -import org.folio.rest.persist.HelperUtils; import org.folio.rest.persist.PgUtil; +import org.folio.rest.util.ResponseUtils; import org.folio.service.fund.FundService; import org.folio.spring.SpringContextUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -68,14 +67,7 @@ public void putFinanceStorageFundsById(String id, Fund fund, Map logger.debug("Trying to update finance storage fund by id {}", id); fund.setId(id); fundService.updateFund(fund, new RequestContext(vertxContext, okapiHeaders)) - .onComplete(result -> { - if (result.failed()) { - HttpException cause = (HttpException) result.cause(); - logger.error("Failed to update the finance storage fund with Id {}", fund.getId(), cause); - HelperUtils.replyWithErrorResponse(asyncResultHandler, cause); - } else { - asyncResultHandler.handle(succeededFuture(respond204())); - } - }); + .onSuccess(result -> asyncResultHandler.handle(succeededFuture(respond204()))) + .onFailure(ResponseUtils::handleFailure); } } diff --git a/src/main/java/org/folio/service/financedata/FinanceDataService.java b/src/main/java/org/folio/service/financedata/FinanceDataService.java index 82521c20..551ebdd7 100644 --- a/src/main/java/org/folio/service/financedata/FinanceDataService.java +++ b/src/main/java/org/folio/service/financedata/FinanceDataService.java @@ -96,7 +96,6 @@ private Budget setNewValues(Budget budget, FyFinanceDataCollection entity) { .orElseThrow(); return budget.withBudgetStatus(Budget.BudgetStatus.fromValue(budgetFinanceData.getBudgetStatus().value())) - .withInitialAllocation(budgetFinanceData.getBudgetInitialAllocation()) .withAllowableExpenditure(budgetFinanceData.getBudgetAllowableExpenditure()) .withAllowableEncumbrance(budgetFinanceData.getBudgetAllowableEncumbrance()); } diff --git a/src/test/java/org/folio/rest/impl/FinanceDataApiTest.java b/src/test/java/org/folio/rest/impl/FinanceDataApiTest.java index 67b75ca9..8745e889 100644 --- a/src/test/java/org/folio/rest/impl/FinanceDataApiTest.java +++ b/src/test/java/org/folio/rest/impl/FinanceDataApiTest.java @@ -113,7 +113,6 @@ public void positive_testUpdateFinanceData() { fyFinanceData.setFundDescription(expectedDescription); fyFinanceData.setFundTags(new FundTags().withTagList(expectedTags)); fyFinanceData.setBudgetStatus(expectedBudgetStatus); - fyFinanceData.setBudgetInitialAllocation(expectedNumber); fyFinanceData.setBudgetAllowableExpenditure(expectedNumber); fyFinanceData.setBudgetAllowableEncumbrance(expectedNumber); @@ -130,7 +129,6 @@ public void positive_testUpdateFinanceData() { assertEquals(expectedDescription, updatedFyFinanceData.getFundDescription()); assertEquals(expectedTags, updatedFyFinanceData.getFundTags().getTagList()); - assertEquals(expectedNumber, updatedFyFinanceData.getBudgetInitialAllocation()); assertEquals(expectedNumber, updatedFyFinanceData.getBudgetAllowableEncumbrance()); assertEquals(expectedNumber, updatedFyFinanceData.getBudgetAllowableExpenditure()); } diff --git a/src/test/java/org/folio/rest/impl/TestBase.java b/src/test/java/org/folio/rest/impl/TestBase.java index 50b909b8..f67ab4a4 100644 --- a/src/test/java/org/folio/rest/impl/TestBase.java +++ b/src/test/java/org/folio/rest/impl/TestBase.java @@ -7,7 +7,6 @@ import static org.hamcrest.Matchers.either; import static org.hamcrest.Matchers.hasEntry; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; import java.io.InputStream; import java.util.Set; diff --git a/src/test/java/org/folio/service/fianancedata/FinanceDataServiceTest.java b/src/test/java/org/folio/service/fianancedata/FinanceDataServiceTest.java index 0e733775..da8e2b6a 100644 --- a/src/test/java/org/folio/service/fianancedata/FinanceDataServiceTest.java +++ b/src/test/java/org/folio/service/fianancedata/FinanceDataServiceTest.java @@ -157,9 +157,9 @@ private void verifyBudgetUpdates(FyFinanceDataCollection collection) { Budget updatedBudget = budgetCaptor.getValue().get(0); assertNotEquals("NAME CHANGED", updatedBudget.getName()); + assertNotEquals(1000.0, updatedBudget.getInitialAllocation()); assertEquals(FyFinanceData.BudgetStatus.INACTIVE.value(), updatedBudget.getBudgetStatus().value()); - assertEquals(1000.0, updatedBudget.getInitialAllocation()); assertEquals(800.0, updatedBudget.getAllowableExpenditure()); assertEquals(700.0, updatedBudget.getAllowableEncumbrance()); }