Made loan collateral optional while creating loan account-FINERACT-1405 (#1889)
This commit is contained in:
+29
-27
@@ -918,39 +918,41 @@ 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();
|
||||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
if (array.size() > 0) {
|
||||||
for (int i = 1; i <= array.size(); i++) {
|
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||||
final JsonObject collateralItemElement = array.get(i - 1).getAsJsonObject();
|
for (int i = 1; i <= array.size(); i++) {
|
||||||
|
final JsonObject collateralItemElement = array.get(i - 1).getAsJsonObject();
|
||||||
|
|
||||||
final String collateralJson = this.fromApiJsonHelper.toJson(collateralItemElement);
|
final String collateralJson = this.fromApiJsonHelper.toJson(collateralItemElement);
|
||||||
this.fromApiJsonHelper.checkForUnsupportedParameters(collateralParameterTypeOfMap, collateralJson,
|
this.fromApiJsonHelper.checkForUnsupportedParameters(collateralParameterTypeOfMap, collateralJson,
|
||||||
supportedParameters);
|
supportedParameters);
|
||||||
|
|
||||||
final Long id = this.fromApiJsonHelper.extractLongNamed("id", collateralItemElement);
|
final Long id = this.fromApiJsonHelper.extractLongNamed("id", collateralItemElement);
|
||||||
baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("id", i).value(id).ignoreIfNull();
|
baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("id", i).value(id).ignoreIfNull();
|
||||||
|
|
||||||
final Long clientCollateralId = this.fromApiJsonHelper.extractLongNamed("clientCollateralId",
|
final Long clientCollateralId = this.fromApiJsonHelper.extractLongNamed("clientCollateralId",
|
||||||
collateralItemElement);
|
collateralItemElement);
|
||||||
baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("clientCollateralId", i)
|
baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("clientCollateralId", i)
|
||||||
.value(clientCollateralId).notNull().integerGreaterThanZero();
|
.value(clientCollateralId).notNull().integerGreaterThanZero();
|
||||||
|
|
||||||
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) {
|
||||||
if (principal.compareTo(totalAmount) > 0 || array.size() == 0) {
|
throw new InvalidAmountOfCollaterals(totalAmount);
|
||||||
throw new InvalidAmountOfCollaterals(totalAmount);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+12
-14
@@ -227,21 +227,19 @@ 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;
|
||||||
}
|
for (LoanCollateralManagement collateralManagement : collateral) {
|
||||||
|
final CollateralManagementDomain collateralManagementDomain = collateralManagement.getClientCollateralManagement()
|
||||||
|
.getCollaterals();
|
||||||
|
BigDecimal totalCollateral = collateralManagement.getQuantity().multiply(collateralManagementDomain.getBasePrice())
|
||||||
|
.multiply(collateralManagementDomain.getPctToBase()).divide(BigDecimal.valueOf(100));
|
||||||
|
totalValue = totalValue.add(totalCollateral);
|
||||||
|
}
|
||||||
|
|
||||||
BigDecimal totalValue = BigDecimal.ZERO;
|
if (amount.compareTo(totalValue) > 0) {
|
||||||
for (LoanCollateralManagement collateralManagement : collateral) {
|
throw new InvalidAmountOfCollaterals(totalValue);
|
||||||
final CollateralManagementDomain collateralManagementDomain = collateralManagement.getClientCollateralManagement()
|
}
|
||||||
.getCollaterals();
|
|
||||||
BigDecimal totalCollateral = collateralManagement.getQuantity().multiply(collateralManagementDomain.getBasePrice())
|
|
||||||
.multiply(collateralManagementDomain.getPctToBase()).divide(BigDecimal.valueOf(100));
|
|
||||||
totalValue = totalValue.add(totalCollateral);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (amount.compareTo(totalValue) > 0) {
|
|
||||||
throw new InvalidAmountOfCollaterals(totalValue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user