Skip to content

Commit

Permalink
Updated updating of budget field in finance data service with keeping…
Browse files Browse the repository at this point in the history
… readonly fields
  • Loading branch information
azizbekxm committed Dec 6, 2024
1 parent fc514ae commit 626cd35
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/main/java/org/folio/service/budget/BudgetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ public void deleteById(String id, Context vertxContext, Map<String, String> head
});
}

public Future<Void> updateBatchBudgets(List<Budget> budgets, DBConn conn) {
budgets.forEach(this::clearReadOnlyFields);
public Future<Void> updateBatchBudgets(List<Budget> budgets, DBConn conn, boolean clearReadOnlyFields) {
if (Boolean.TRUE.equals(clearReadOnlyFields)) {
budgets.forEach(this::clearReadOnlyFields);
}
return budgetDAO.updateBatchBudgets(budgets, conn);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private Future<Void> 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<Fund> setNewValuesForFunds(List<Fund> funds, FyFinanceDataCollection entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private Future<Void> 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -153,7 +153,7 @@ private void verifyBudgetUpdates(FyFinanceDataCollection collection) {
assertEquals(collection.getFyFinanceData().get(0).getBudgetId(), budgetIdsCaptor.getValue().get(0));

ArgumentCaptor<List<Budget>> 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());
Expand Down

0 comments on commit 626cd35

Please sign in to comment.