From 626cd356ddb2a4e2faa24db01895b914ea7336a3 Mon Sep 17 00:00:00 2001 From: Azizbek Khushvakov Date: Fri, 6 Dec 2024 19:01:23 +0500 Subject: [PATCH] Updated updating of budget field in finance data service with keeping readonly fields --- src/main/java/org/folio/service/budget/BudgetService.java | 6 ++++-- .../org/folio/service/financedata/FinanceDataService.java | 2 +- .../service/transactions/batch/BatchTransactionService.java | 2 +- .../folio/service/fianancedata/FinanceDataServiceTest.java | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) 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/test/java/org/folio/service/fianancedata/FinanceDataServiceTest.java b/src/test/java/org/folio/service/fianancedata/FinanceDataServiceTest.java index 26d829f0..5aa5c1ff 100644 --- a/src/test/java/org/folio/service/fianancedata/FinanceDataServiceTest.java +++ b/src/test/java/org/folio/service/fianancedata/FinanceDataServiceTest.java @@ -100,7 +100,7 @@ void shouldFailUpdateWhenFundServiceFails(VertxTestContext testContext) { .onComplete(testContext.failing(error -> { testContext.verify(() -> { assertEquals("Fund service error", error.getMessage()); - verify(budgetService, never()).updateBatchBudgets(any(), any()); + verify(budgetService, never()).updateBatchBudgets(any(), any(), any()); verify(fundService, never()).updateFunds(any(), any()); }); testContext.completeNow(); @@ -117,7 +117,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(), any())).thenReturn(Future.succeededFuture()); } private void setupMocksForFailure(RuntimeException expectedError) { @@ -153,7 +153,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), any()); Budget updatedBudget = budgetCaptor.getValue().get(0); assertNotEquals("NAME CHANGED", updatedBudget.getName());