Made loan collateral optional while creating loan account-FINERACT-1405 (#1889)

This commit is contained in:
Shreyas S Kumar
2021-10-11 19:38:07 +05:30
committed by GitHub
parent 72640bac6a
commit 8f444bed5c
2 changed files with 41 additions and 41 deletions
@@ -918,6 +918,7 @@ public final class LoanApplicationCommandFromApiJsonHelper {
final Type collateralParameterTypeOfMap = new TypeToken<Map<String, Object>>() {}.getType(); final Type collateralParameterTypeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
final Set<String> supportedParameters = new HashSet<>(Arrays.asList("id", "clientCollateralId", "quantity")); final Set<String> supportedParameters = new HashSet<>(Arrays.asList("id", "clientCollateralId", "quantity"));
final JsonArray array = topLevelJsonElement.get("collateral").getAsJsonArray(); final JsonArray array = topLevelJsonElement.get("collateral").getAsJsonArray();
if (array.size() > 0) {
BigDecimal totalAmount = BigDecimal.ZERO; BigDecimal totalAmount = BigDecimal.ZERO;
for (int i = 1; i <= array.size(); i++) { for (int i = 1; i <= array.size(); i++) {
final JsonObject collateralItemElement = array.get(i - 1).getAsJsonObject(); final JsonObject collateralItemElement = array.get(i - 1).getAsJsonObject();
@@ -936,23 +937,24 @@ public final class LoanApplicationCommandFromApiJsonHelper {
final BigDecimal quantity = this.fromApiJsonHelper.extractBigDecimalNamed("quantity", collateralItemElement, final BigDecimal quantity = this.fromApiJsonHelper.extractBigDecimalNamed("quantity", collateralItemElement,
locale); locale);
baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("quantity", i).value(quantity).notNull() baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("quantity", i).value(quantity)
.positiveAmount(); .notNull().positiveAmount();
if (clientCollateralId != null || quantity != null) { if (clientCollateralId != null || quantity != null) {
BigDecimal baseAmount = this.clientCollateralManagementRepositoryWrapper.getCollateral(clientCollateralId) BigDecimal baseAmount = this.clientCollateralManagementRepositoryWrapper
.getCollaterals().getBasePrice(); .getCollateral(clientCollateralId).getCollaterals().getBasePrice();
BigDecimal pctToBase = this.clientCollateralManagementRepositoryWrapper.getCollateral(clientCollateralId) BigDecimal pctToBase = this.clientCollateralManagementRepositoryWrapper
.getCollaterals().getPctToBase(); .getCollateral(clientCollateralId).getCollaterals().getPctToBase();
BigDecimal total = baseAmount.multiply(pctToBase).multiply(quantity); BigDecimal total = baseAmount.multiply(pctToBase).multiply(quantity);
totalAmount = totalAmount.add(total); totalAmount = totalAmount.add(total);
} }
} }
if (principal != null) { if (principal != null) {
if (principal.compareTo(totalAmount) > 0 || array.size() == 0) { if (principal.compareTo(totalAmount) > 0) {
throw new InvalidAmountOfCollaterals(totalAmount); throw new InvalidAmountOfCollaterals(totalAmount);
} }
} }
}
} else { } else {
baseDataValidator.reset().parameter(collateralParameterName).expectedArrayButIsNot(); baseDataValidator.reset().parameter(collateralParameterName).expectedArrayButIsNot();
} }
@@ -227,10 +227,7 @@ public class LoanAssembler {
if (loanAccountType.isIndividualAccount()) { if (loanAccountType.isIndividualAccount()) {
collateral = this.collateralAssembler.fromParsedJson(element); collateral = this.collateralAssembler.fromParsedJson(element);
if (collateral.size() == 0) { if (collateral.size() > 0) {
throw new InvalidAmountOfCollaterals(BigDecimal.ZERO);
}
BigDecimal totalValue = BigDecimal.ZERO; BigDecimal totalValue = BigDecimal.ZERO;
for (LoanCollateralManagement collateralManagement : collateral) { for (LoanCollateralManagement collateralManagement : collateral) {
final CollateralManagementDomain collateralManagementDomain = collateralManagement.getClientCollateralManagement() final CollateralManagementDomain collateralManagementDomain = collateralManagement.getClientCollateralManagement()
@@ -245,6 +242,7 @@ public class LoanAssembler {
} }
} }
} }
}
final Set<LoanCharge> loanCharges = this.loanChargeAssembler.fromParsedJson(element, disbursementDetails); final Set<LoanCharge> loanCharges = this.loanChargeAssembler.fromParsedJson(element, disbursementDetails);
for (final LoanCharge loanCharge : loanCharges) { for (final LoanCharge loanCharge : loanCharges) {