luckyman20 commented on a change in pull request #1770:
URL: https://github.com/apache/fineract/pull/1770#discussion_r698034395
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java
##########
@@ -414,38 +422,93 @@ public void validateForCreate(final String json, final
boolean isMeetingMandator
}
}
- // collateral
- final String collateralParameterName = "collateral";
- if (element.isJsonObject() &&
this.fromApiJsonHelper.parameterExists(collateralParameterName, element)) {
- final JsonObject topLevelJsonElement = element.getAsJsonObject();
- final Locale locale =
this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
- if (topLevelJsonElement.get("collateral").isJsonArray()) {
-
- final Type collateralParameterTypeOfMap = new
TypeToken<Map<String, Object>>() {}.getType();
- final Set<String> supportedParameters = new
HashSet<>(Arrays.asList("id", "type", "value", "description"));
- final JsonArray array =
topLevelJsonElement.get("collateral").getAsJsonArray();
- for (int i = 1; i <= array.size(); i++) {
- final JsonObject collateralItemElement = array.get(i -
1).getAsJsonObject();
-
- final String collateralJson =
this.fromApiJsonHelper.toJson(collateralItemElement);
-
this.fromApiJsonHelper.checkForUnsupportedParameters(collateralParameterTypeOfMap,
collateralJson, supportedParameters);
-
- final Long collateralTypeId =
this.fromApiJsonHelper.extractLongNamed("type", collateralItemElement);
-
baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("type",
i).value(collateralTypeId).notNull()
- .integerGreaterThanZero();
+ // // collateral
Review comment:
.
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
##########
@@ -3008,6 +3021,14 @@ public void makeRefund(final LoanTransaction
loanTransaction, final LoanLifecycl
final String errorMessage = "Transfer funds is allowed only for
loan accounts with overpaid status ";
throw new InvalidLoanStateTransitionException("transaction",
"is.not.a.overpaid.loan", errorMessage);
}
+
+ // // Update the transaction in loan collateral module.
Review comment:
Please check this.
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java
##########
@@ -144,6 +149,26 @@ public LoanTransaction makeRepayment(final Loan loan,
final CommandProcessingRes
isRecoveryRepayment, isAccountTransfer, holidayDetailDto,
isHolidayValidationDone, false);
}
+ @Transactional
+ @Override
+ public void updateLoanCollateralTransaction(Set<LoanCollateralManagement>
loanCollateralManagementSet) {
+
this.loanCollateralManagementRepository.saveAll(loanCollateralManagementSet);
+ }
+
+ @Transactional
+ @Override
+ public void updateLoanCollateralStatus(Set<LoanCollateralManagement>
loanCollateralManagementSet, Integer isReleased) {
+ for (LoanCollateralManagement loanCollateralManagement :
loanCollateralManagementSet) {
+ loanCollateralManagement.setIsReleased(isReleased);
+ }
+
this.loanCollateralManagementRepository.saveAll(loanCollateralManagementSet);
+ }
+
+ // @Override
+ // public BigDecimal getTotalQuantity(Loan loan) {
Review comment:
.
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
##########
@@ -348,6 +351,31 @@ public CommandProcessingResult disburseLoan(final Long
loanId, final JsonCommand
final Loan loan = this.loanAssembler.assembleFrom(loanId);
+ // Get disbursedAmount
+ final BigDecimal disbursedAmount = loan.getDisbursedAmount();
+
+ /**
+ * TODO: Add condition for collaterals if and only if the loan type is
`INDIVIDUAL`
Review comment:
Check this TODO too.
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainService.java
##########
@@ -48,6 +49,12 @@ LoanTransaction makeDisburseTransaction(Long loanId,
LocalDate transactionDate,
LoanTransaction makeRefundForActiveLoan(Long accountId,
CommandProcessingResultBuilder builderResult, LocalDate transactionDate,
BigDecimal transactionAmount, PaymentDetail paymentDetail, String
noteText, String txnExternalId);
+ void updateLoanCollateralTransaction(Set<LoanCollateralManagement>
loanCollateralManagementList);
+
+ // BigDecimal getTotalQuantity(Loan loan);
Review comment:
this too
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
##########
@@ -892,8 +920,44 @@ public CommandProcessingResult makeLoanRepayment(final
Long loanId, final JsonCo
final HolidayDetailDTO holidayDetailDto = null;
boolean isAccountTransfer = false;
final CommandProcessingResultBuilder commandProcessingResultBuilder =
new CommandProcessingResultBuilder();
- this.loanAccountDomainService.makeRepayment(loan,
commandProcessingResultBuilder, transactionDate, transactionAmount,
paymentDetail,
- noteText, txnExternalId, isRecoveryRepayment,
isAccountTransfer, holidayDetailDto, isHolidayValidationDone);
+ LoanTransaction loanTransaction =
this.loanAccountDomainService.makeRepayment(loan,
commandProcessingResultBuilder, transactionDate,
+ transactionAmount, paymentDetail, noteText, txnExternalId,
isRecoveryRepayment, isAccountTransfer, holidayDetailDto,
+ isHolidayValidationDone);
+
+ // Update loan transaction on repayment.
+ if (AccountType.fromInt(loan.getLoanType()).isIndividualAccount()) {
+ Set<LoanCollateralManagement> loanCollateralManagements =
loan.getLoanCollateralManagements();
+ for (LoanCollateralManagement loanCollateralManagement :
loanCollateralManagements) {
+
loanCollateralManagement.setLoanTransactionData(loanTransaction);
+ ClientCollateralManagement clientCollateralManagement =
loanCollateralManagement.getClientCollateralManagement();
+
+ if (loan.status().isClosed()) {
+ loanCollateralManagement.setIsReleased(Integer.valueOf(1));
+ BigDecimal quantity =
loanCollateralManagement.getQuantity();
+
clientCollateralManagement.updateQuantity(clientCollateralManagement.getQuantity().add(quantity));
+
loanCollateralManagement.setClientCollateralManagement(clientCollateralManagement);
+ }
+ }
+
this.loanAccountDomainService.updateLoanCollateralTransaction(loanCollateralManagements);
+ }
+
+ /**
+ * TODO: Implement repayment with collaterals.
Review comment:
check this TODO
##########
File path:
integration-tests/src/test/java/org/apache/fineract/integrationtests/common/CollateralManagementHelper.java
##########
@@ -0,0 +1,167 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.integrationtests.common;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+import java.math.BigDecimal;
+import java.util.HashMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CollateralManagementHelper {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(CollateralManagementHelper.class);
+ private final RequestSpecification requestSpec;
+ private final ResponseSpecification responseSpec;
+
+ public CollateralManagementHelper(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) {
+ this.requestSpec = requestSpec;
+ this.responseSpec = responseSpec;
+ }
+
+ // public static Integer createClientCollateral(final RequestSpecification
requestSpec, final ResponseSpecification
Review comment:
commented code
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAssembler.java
##########
@@ -209,7 +215,38 @@ private Loan assembleApplication(final JsonElement
element, final Long clientId,
loanProduct.maxTrancheCount(),
disbursementDetails.size());
}
}
- final Set<LoanCollateral> collateral =
this.loanCollateralAssembler.fromParsedJson(element);
+
+ final String loanTypeParameterName = "loanType";
+ final String loanTypeStr =
this.fromApiJsonHelper.extractStringNamed(loanTypeParameterName, element);
+ final EnumOptionData loanType =
AccountEnumerations.loanType(loanTypeStr);
+ Set<LoanCollateralManagement> collateral = new HashSet<>();
+
+ if (!StringUtils.isBlank(loanTypeStr)) {
+ final AccountType loanAccountType =
AccountType.fromName(loanTypeStr);
+
+ if (loanAccountType.isIndividualAccount()) {
+ collateral = this.collateralAssembler.fromParsedJson(element);
+
+ 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);
+ }
+
+ if (amount.compareTo(totalValue) > 0) {
+ throw new InvalidAmountOfCollaterals(totalValue);
+ }
+ }
+ }
+
+ // final Set<LoanCollateral> collateral =
this.loanCollateralAssembler.fromParsedJson(element);
Review comment:
.
##########
File path:
integration-tests/src/test/java/org/apache/fineract/integrationtests/bulkimport/importhandler/loan/LoanImportHandlerTest.java
##########
@@ -213,6 +229,11 @@ public void testLoanImport() throws InterruptedException,
IOException, ParseExce
LOG.info("Output location: {}", location);
LOG.info("Failure reason column: {}",
row.getCell(LoanConstants.FAILURE_REPORT_COL).getStringCellValue());
+ /**
+ * TODO: Add Loan Collaterals into the xls file importing since it's a
mandatory field. For now integration test
Review comment:
Check this TODO
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java
##########
@@ -847,38 +910,67 @@ public void validateForModify(final String json, final
LoanProduct loanProduct,
}
}
- // collateral
- final String collateralParameterName = "collateral";
- if (element.isJsonObject() &&
this.fromApiJsonHelper.parameterExists(collateralParameterName, element)) {
- final JsonObject topLevelJsonElement = element.getAsJsonObject();
- final Locale locale =
this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
- if (topLevelJsonElement.get("collateral").isJsonArray()) {
-
- final Type collateralParameterTypeOfMap = new
TypeToken<Map<String, Object>>() {}.getType();
- final Set<String> supportedParameters = new
HashSet<>(Arrays.asList("id", "type", "value", "description"));
- final JsonArray array =
topLevelJsonElement.get("collateral").getAsJsonArray();
- for (int i = 1; i <= array.size(); i++) {
- final JsonObject collateralItemElement = array.get(i -
1).getAsJsonObject();
-
- final String collateralJson =
this.fromApiJsonHelper.toJson(collateralItemElement);
-
this.fromApiJsonHelper.checkForUnsupportedParameters(collateralParameterTypeOfMap,
collateralJson, supportedParameters);
-
- final Long collateralTypeId =
this.fromApiJsonHelper.extractLongNamed("type", collateralItemElement);
-
baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("type",
i).value(collateralTypeId).notNull()
- .integerGreaterThanZero();
-
- final BigDecimal collateralValue =
this.fromApiJsonHelper.extractBigDecimalNamed("value", collateralItemElement,
- locale);
-
baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("value",
i).value(collateralValue)
- .ignoreIfNull().positiveAmount();
+ final String loanTypeParameterName = "loanType";
+ final String loanTypeStr =
this.fromApiJsonHelper.extractStringNamed(loanTypeParameterName, element);
+
baseDataValidator.reset().parameter(loanTypeParameterName).value(loanTypeStr).notNull();
- final String description =
this.fromApiJsonHelper.extractStringNamed("description", collateralItemElement);
-
baseDataValidator.reset().parameter("collateral").parameterAtIndexArray("description",
i).value(description).notBlank()
- .notExceedingLengthOf(500);
+ if (!StringUtils.isBlank(loanTypeStr)) {
+ final AccountType loanType = AccountType.fromName(loanTypeStr);
+
baseDataValidator.reset().parameter(loanTypeParameterName).value(loanType.getValue()).inMinMaxRange(1,
4);
+ /**
+ * TODO: Allow for other loan account types.
Review comment:
Check this if it is still valid.
##########
File path:
integration-tests/src/test/java/org/apache/fineract/integrationtests/GroupLoanIntegrationTest.java
##########
@@ -205,6 +207,11 @@ private Integer createLoanProduct() {
private Integer applyForLoanApplication(final Integer groupID, final
Integer loanProductID) {
LOG.info("--------------------------------APPLYING FOR LOAN
APPLICATION--------------------------------");
+
+ /**
+ * TODO: Add Collateral Support for Group Loan.
Review comment:
check this TODO too
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java
##########
@@ -892,8 +920,44 @@ public CommandProcessingResult makeLoanRepayment(final
Long loanId, final JsonCo
final HolidayDetailDTO holidayDetailDto = null;
boolean isAccountTransfer = false;
final CommandProcessingResultBuilder commandProcessingResultBuilder =
new CommandProcessingResultBuilder();
- this.loanAccountDomainService.makeRepayment(loan,
commandProcessingResultBuilder, transactionDate, transactionAmount,
paymentDetail,
- noteText, txnExternalId, isRecoveryRepayment,
isAccountTransfer, holidayDetailDto, isHolidayValidationDone);
+ LoanTransaction loanTransaction =
this.loanAccountDomainService.makeRepayment(loan,
commandProcessingResultBuilder, transactionDate,
+ transactionAmount, paymentDetail, noteText, txnExternalId,
isRecoveryRepayment, isAccountTransfer, holidayDetailDto,
+ isHolidayValidationDone);
+
+ // Update loan transaction on repayment.
+ if (AccountType.fromInt(loan.getLoanType()).isIndividualAccount()) {
+ Set<LoanCollateralManagement> loanCollateralManagements =
loan.getLoanCollateralManagements();
+ for (LoanCollateralManagement loanCollateralManagement :
loanCollateralManagements) {
+
loanCollateralManagement.setLoanTransactionData(loanTransaction);
+ ClientCollateralManagement clientCollateralManagement =
loanCollateralManagement.getClientCollateralManagement();
+
+ if (loan.status().isClosed()) {
+ loanCollateralManagement.setIsReleased(Integer.valueOf(1));
+ BigDecimal quantity =
loanCollateralManagement.getQuantity();
+
clientCollateralManagement.updateQuantity(clientCollateralManagement.getQuantity().add(quantity));
+
loanCollateralManagement.setClientCollateralManagement(clientCollateralManagement);
+ }
+ }
+
this.loanAccountDomainService.updateLoanCollateralTransaction(loanCollateralManagements);
+ }
+
+ /**
+ * TODO: Implement repayment with collaterals.
+ */
+
+ // Set<LoanCollateralManagement> loanCollateralManagements =
loan.getLoanCollateralManagements();
Review comment:
Is this required?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]