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] - Implement endpoint to process FY finance bulk update #264

Merged
merged 17 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.compile.nullAnalysis.mode": "disabled"
}
Saba-Zedginidze-EPAM marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
import java.util.UUID;

import io.vertx.core.Future;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.rest.core.RestClient;
import org.folio.rest.core.models.RequestContext;
import org.folio.rest.core.models.RequestEntry;
Expand All @@ -35,8 +34,8 @@
import org.folio.services.protection.AcqUnitsService;
import org.folio.services.transactions.TransactionApiService;

@Log4j2
public class FinanceDataService {
private static final Logger log = LogManager.getLogger();

private final RestClient restClient;
private final AcqUnitsService acqUnitsService;
Expand Down Expand Up @@ -73,7 +72,7 @@ private Future<FyFinanceDataCollection> getFinanceData(String query, int offset,
public Future<Void> putFinanceData(FyFinanceDataCollection financeDataCollection, RequestContext requestContext) {
log.debug("Trying to update finance data collection with size: {}", financeDataCollection.getTotalRecords());
if (CollectionUtils.isEmpty(financeDataCollection.getFyFinanceData())) {
log.info("Finance data collection is empty, nothing to update");
log.info("putFinanceData:: Finance data collection is empty, nothing to update");
return succeededFuture();
}

Expand All @@ -90,10 +89,10 @@ private void validateFinanceDataCollection(FyFinanceDataCollection financeDataCo
var financeData = financeDataCollection.getFyFinanceData().get(i);
validateFinanceDataFields(financeData, i, fiscalYearId);

var allocationChange = BigDecimal.valueOf(financeData.getBudgetAllocationChange());
var initialAllocation = BigDecimal.valueOf(financeData.getBudgetInitialAllocation());
var allocationChange = financeData.getBudgetAllocationChange();
var initialAllocation = financeData.getBudgetInitialAllocation();

if (allocationChange.doubleValue() < 0 && allocationChange.abs().doubleValue() > initialAllocation.doubleValue()) {
if (allocationChange < 0 && Math.abs(allocationChange) > initialAllocation) {
var error = createError("Allocation change cannot be greater than initial allocation",
String.format("financeData[%s].budgetAllocationChange", i), String.valueOf(financeData.getBudgetAllocationChange()));
throw new HttpException(422, new Errors().withErrors(List.of(error)));
Expand All @@ -120,7 +119,7 @@ private List<Transaction> createAllocationTransactions(FyFinanceDataCollection f

private Transaction createAllocationTransaction(FyFinanceData financeData, String currency) {
var allocation = calculateAllocation(financeData);
log.info("Creating allocation transaction for fund '{}' and budget '{}' with allocation '{}'",
log.info("createAllocationTransaction:: Creating allocation transaction for fund '{}' and budget '{}' with allocation '{}'",
financeData.getFundId(), financeData.getBudgetId(), allocation);

return new Transaction()
Expand Down
Loading