diff --git a/ramls/acq-models b/ramls/acq-models index 0d8f736a..c6ebedd7 160000 --- a/ramls/acq-models +++ b/ramls/acq-models @@ -1 +1 @@ -Subproject commit 0d8f736a3f2b5401a5cfad20a95bd831843f77a6 +Subproject commit c6ebedd7de52700d73516076bbdd45cdabb0185c diff --git a/ramls/finance-data.raml b/ramls/finance-data.raml index f3eeabe8..69ee58b4 100644 --- a/ramls/finance-data.raml +++ b/ramls/finance-data.raml @@ -25,7 +25,7 @@ resourceTypes: /finance-storage/finance-data: type: collection-get: - exampleCollection: !include acq-models/mod-finance/examples/fy_finance_data_collection.sample + exampleCollection: !include acq-models/mod-finance/examples/fy_finance_data_collection_get.sample schemaCollection: fy-finance-data-collection get: description: Get finance data for a fiscal year @@ -39,7 +39,7 @@ resourceTypes: body: application/json: type: fy-finance-data-collection - example: !include acq-models/mod-finance/examples/fy_finance_data_collection.sample + example: !include acq-models/mod-finance/examples/fy_finance_data_collection_put.sample responses: 204: description: "Items successfully updated" diff --git a/src/main/java/org/folio/service/budget/BudgetService.java b/src/main/java/org/folio/service/budget/BudgetService.java index 5e58c0d6..213cf716 100644 --- a/src/main/java/org/folio/service/budget/BudgetService.java +++ b/src/main/java/org/folio/service/budget/BudgetService.java @@ -56,8 +56,10 @@ public void deleteById(String id, Context vertxContext, Map head }); } - public Future updateBatchBudgets(List budgets, DBConn conn) { - budgets.forEach(this::clearReadOnlyFields); + public Future updateBatchBudgets(List budgets, DBConn conn, boolean clearReadOnlyFields) { + if (Boolean.TRUE.equals(clearReadOnlyFields)) { + budgets.forEach(this::clearReadOnlyFields); + } return budgetDAO.updateBatchBudgets(budgets, conn); } diff --git a/src/main/java/org/folio/service/financedata/FinanceDataService.java b/src/main/java/org/folio/service/financedata/FinanceDataService.java index 66d11a2e..40cdf1c3 100644 --- a/src/main/java/org/folio/service/financedata/FinanceDataService.java +++ b/src/main/java/org/folio/service/financedata/FinanceDataService.java @@ -61,7 +61,7 @@ private Future processBudgetUpdate(FyFinanceDataCollection entity, DBConn .toList(); return budgetService.getBudgetsByIds(budgetIds, conn) .map(budgets -> setNewValuesForBudgets(budgets, entity)) - .compose(budgets -> budgetService.updateBatchBudgets(budgets, conn)); + .compose(budgets -> budgetService.updateBatchBudgets(budgets, conn, false)); } private List setNewValuesForFunds(List funds, FyFinanceDataCollection entity) { diff --git a/src/main/java/org/folio/service/transactions/batch/BatchTransactionService.java b/src/main/java/org/folio/service/transactions/batch/BatchTransactionService.java index 8f2a2f2e..d7e918b4 100644 --- a/src/main/java/org/folio/service/transactions/batch/BatchTransactionService.java +++ b/src/main/java/org/folio/service/transactions/batch/BatchTransactionService.java @@ -182,7 +182,7 @@ private Future updateBudgets(BatchTransactionHolder holder, DBConn conn) { if (budgets.isEmpty()) { return succeededFuture(); } - return budgetService.updateBatchBudgets(budgets, conn) + return budgetService.updateBatchBudgets(budgets, conn, true) .onSuccess(v -> logger.info("Batch transactions: successfully updated {} budgets", budgets.size())) .onFailure(t -> logger.error("Batch transactions: failed to update budgets, budgets = {}", Json.encode(budgets), t)) 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 4c6492a9..341e0726 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 @@ -17,7 +17,6 @@ SELECT 'budgetName', budget.jsonb ->>'name', 'budgetStatus', budget.jsonb ->>'budgetStatus', 'budgetInitialAllocation', budget.jsonb ->>'initialAllocation', - 'budgetCurrentAllocation', budget.jsonb ->>'allocated', 'budgetAllowableExpenditure', budget.jsonb ->>'allowableExpenditure', 'budgetAllowableEncumbrance', budget.jsonb ->>'allowableEncumbrance', 'budgetAcqUnitIds', budget.jsonb ->'acqUnitIds', diff --git a/src/test/java/org/folio/service/fianancedata/FinanceDataServiceTest.java b/src/test/java/org/folio/service/fianancedata/FinanceDataServiceTest.java index 1887ccef..139bab79 100644 --- a/src/test/java/org/folio/service/fianancedata/FinanceDataServiceTest.java +++ b/src/test/java/org/folio/service/fianancedata/FinanceDataServiceTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.never; @@ -14,7 +15,6 @@ import java.util.function.Function; import io.vertx.core.Future; -import io.vertx.core.Vertx; import io.vertx.junit5.VertxExtension; import io.vertx.junit5.VertxTestContext; import org.folio.rest.core.model.RequestContext; @@ -35,7 +35,6 @@ import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @ExtendWith(VertxExtension.class) @@ -53,7 +52,7 @@ public class FinanceDataServiceTest { private DBConn dbConn; @InjectMocks - private FinanceDataService financeDataService2; + private FinanceDataService financeDataService; private AutoCloseable mockitoMocks; @@ -69,7 +68,6 @@ void tearDown() throws Exception { @Test void shouldSuccessfullyUpdateFinanceData(VertxTestContext testContext) { - FinanceDataService financeDataService = Mockito.spy(financeDataService2); var collection = createTestFinanceDataCollection(); var oldFund = new Fund().withId(collection.getFyFinanceData().get(0).getFundId()) .withName("NAME").withCode("CODE").withFundStatus(Fund.FundStatus.ACTIVE) @@ -96,11 +94,11 @@ void shouldFailUpdateWhenFundServiceFails(VertxTestContext testContext) { setupMocksForFailure(expectedError); - financeDataService2.update(collection, requestContext) + financeDataService.update(collection, requestContext) .onComplete(testContext.failing(error -> { testContext.verify(() -> { assertEquals("Fund service error", error.getMessage()); - verify(budgetService, never()).updateBatchBudgets(any(), any()); + verify(budgetService, never()).updateBatchBudgets(any(), any(), anyBoolean()); verify(fundService, never()).updateFunds(any(), any()); }); testContext.completeNow(); @@ -117,7 +115,7 @@ private void setupMocks(Fund oldFund, Budget oldBudget) { when(fundService.getFundsByIds(any(), any())).thenReturn(Future.succeededFuture(List.of(oldFund))); when(fundService.updateFunds(any(), any())).thenReturn(Future.succeededFuture()); when(budgetService.getBudgetsByIds(any(), any())).thenReturn(Future.succeededFuture(List.of(oldBudget))); - when(budgetService.updateBatchBudgets(any(), any())).thenReturn(Future.succeededFuture()); + when(budgetService.updateBatchBudgets(any(), any(), anyBoolean())).thenReturn(Future.succeededFuture()); } private void setupMocksForFailure(RuntimeException expectedError) { @@ -153,7 +151,7 @@ private void verifyBudgetUpdates(FyFinanceDataCollection collection) { assertEquals(collection.getFyFinanceData().get(0).getBudgetId(), budgetIdsCaptor.getValue().get(0)); ArgumentCaptor> budgetCaptor = ArgumentCaptor.forClass(List.class); - verify(budgetService).updateBatchBudgets(budgetCaptor.capture(), eq(dbConn)); + verify(budgetService).updateBatchBudgets(budgetCaptor.capture(), eq(dbConn), anyBoolean()); Budget updatedBudget = budgetCaptor.getValue().get(0); assertNotEquals("NAME CHANGED", updatedBudget.getName()); @@ -181,7 +179,6 @@ private FyFinanceDataCollection createTestFinanceDataCollection() { .withBudgetName("NAME CHANGED") .withBudgetStatus(FyFinanceData.BudgetStatus.INACTIVE) .withBudgetInitialAllocation(1000.0) - .withBudgetCurrentAllocation(900.0) .withBudgetAllowableExpenditure(800.0) .withBudgetAllowableEncumbrance(700.0) .withBudgetAcqUnitIds(List.of("unit1"));