Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MODFIN-381] - removed duplicate field #441

Merged
merged 4 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ramls/finance-data.raml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
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 @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -53,7 +52,7 @@ public class FinanceDataServiceTest {
private DBConn dbConn;

@InjectMocks
private FinanceDataService financeDataService2;
private FinanceDataService financeDataService;

private AutoCloseable mockitoMocks;

Expand All @@ -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)
Expand All @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -153,7 +151,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), anyBoolean());
Budget updatedBudget = budgetCaptor.getValue().get(0);

assertNotEquals("NAME CHANGED", updatedBudget.getName());
Expand Down Expand Up @@ -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"));
Expand Down
Loading