Skip to content

Commit f981ffe

Browse files
taskain7adamsaghy
authored andcommitted
FINERACT-1971: Loan transaction processing strategy validation fix
1 parent b9314d0 commit f981ffe

2 files changed

Lines changed: 53 additions & 12 deletions

File tree

fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,14 @@ public void validateForCreate(final String json, final boolean isMeetingMandator
396396
.extractStringNamed(LoanApiConstants.transactionProcessingStrategyCodeParameterName, element);
397397
baseDataValidator.reset().parameter(LoanApiConstants.transactionProcessingStrategyCodeParameterName)
398398
.value(transactionProcessingStrategy).notNull();
399+
400+
if (!AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY
401+
.equals(loanProduct.getTransactionProcessingStrategyCode())
402+
&& AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY.equals(transactionProcessingStrategy)) {
403+
baseDataValidator.reset().parameter(LoanApiConstants.transactionProcessingStrategyCodeParameterName).failWithCode(
404+
"strategy.cannot.be.advanced.payment.allocation.if.not.configured",
405+
"Loan transaction processing strategy cannot be Advanced Payment Allocation Strategy if it's not configured on loan product");
406+
}
399407
// Validating whether the processor is existing
400408
loanRepaymentScheduleTransactionProcessorFactory.determineProcessor(transactionProcessingStrategy);
401409

@@ -670,6 +678,14 @@ public void validateForModify(final String json, final LoanProduct loanProduct,
670678
loanRepaymentScheduleTransactionProcessorFactory.determineProcessor(transactionProcessingStrategy);
671679
}
672680

681+
if (!AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY
682+
.equals(loanProduct.getTransactionProcessingStrategyCode())
683+
&& AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY.equals(transactionProcessingStrategy)) {
684+
baseDataValidator.reset().parameter(LoanApiConstants.transactionProcessingStrategyCodeParameterName).failWithCode(
685+
"strategy.cannot.be.advanced.payment.allocation.if.not.configured",
686+
"Loan transaction processing strategy cannot be Advanced Payment Allocation Strategy if it's not configured on loan product");
687+
}
688+
673689
BigDecimal principal = null;
674690
if (this.fromApiJsonHelper.parameterExists(LoanApiConstants.principalParameterName, element)) {
675691
atLeastOneParameterPassedForUpdate = true;

integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanApplicationApprovalTest.java

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.ArrayList;
3030
import java.util.HashMap;
3131
import java.util.List;
32+
import lombok.extern.slf4j.Slf4j;
3233
import org.apache.fineract.integrationtests.common.ClientHelper;
3334
import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
3435
import org.apache.fineract.integrationtests.common.CommonConstants;
@@ -38,18 +39,18 @@
3839
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
3940
import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
4041
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
42+
import org.apache.fineract.portfolio.loanaccount.domain.transactionprocessor.impl.AdvancedPaymentScheduleTransactionProcessor;
4143
import org.junit.jupiter.api.Assertions;
4244
import org.junit.jupiter.api.BeforeEach;
4345
import org.junit.jupiter.api.Test;
4446
import org.junit.jupiter.api.extension.ExtendWith;
45-
import org.slf4j.Logger;
46-
import org.slf4j.LoggerFactory;
4747

4848
@SuppressWarnings("rawtypes")
4949
@ExtendWith(LoanTestLifecycleExtension.class)
50+
@Slf4j
5051
public class LoanApplicationApprovalTest {
5152

52-
private static final Logger LOG = LoggerFactory.getLogger(LoanApplicationApprovalTest.class);
53+
private static final String DATETIME_PATTERN = "dd MMMM yyyy";
5354
private ResponseSpecification responseSpec;
5455
private ResponseSpecification responseSpecForStatusCode403;
5556
private ResponseSpecification responseSpecForStatusCode400;
@@ -136,16 +137,41 @@ public void loanApplicationApprovalAndValidationForMultiDisburseLoans() {
136137
createTranches.add(createTrancheDetail("23 March 2014", "4000"));
137138

138139
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
139-
LOG.info("---------------------------------CLIENT CREATED WITH ID--------------------------------------------------- {}", clientID);
140+
log.info("---------------------------------CLIENT CREATED WITH ID--------------------------------------------------- {}", clientID);
140141

141142
final Integer loanProductID = this.loanTransactionHelper
142143
.getLoanProductId(new LoanProductTestBuilder().withInterestTypeAsDecliningBalance().withTranches(true)
143144
.withInterestCalculationPeriodTypeAsRepaymentPeriod(true).build(null));
144-
LOG.info("----------------------------------LOAN PRODUCT CREATED WITH ID------------------------------------------- {}",
145+
log.info("----------------------------------LOAN PRODUCT CREATED WITH ID------------------------------------------- {}",
145146
loanProductID);
146147

147148
this.trancheLoansApprovedAmountLesserThanProposedAmount(clientID, loanProductID, createTranches);
148149
this.trancheLoansApprovalValidation(clientID, loanProductID, createTranches);
150+
}
151+
152+
@Test
153+
public void loanApplicationShouldFailIfTransactionProcessingStrategyIsAdvancedPaymentAllocationButItIsNotConfiguredOnProduct() {
154+
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
155+
log.info("---------------------------------CLIENT CREATED WITH ID--------------------------------------------------- {}", clientId);
156+
157+
final Integer loanProductId = this.loanTransactionHelper
158+
.getLoanProductId(new LoanProductTestBuilder().withInterestTypeAsDecliningBalance().withTranches(true)
159+
.withInterestCalculationPeriodTypeAsRepaymentPeriod(true).build(null));
160+
log.info("----------------------------------LOAN PRODUCT CREATED WITH ID------------------------------------------- {}",
161+
loanProductId);
162+
163+
loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode400);
164+
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal("1000").withLoanTermFrequency("1")
165+
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("1").withRepaymentEveryAfter("1")
166+
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("0").withInterestTypeAsFlatBalance()
167+
.withAmortizationTypeAsEqualPrincipalPayments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
168+
.withExpectedDisbursementDate("01 March 2022").withSubmittedOnDate("01 March 2022").withLoanType("individual")
169+
.withRepaymentStrategy(AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY)
170+
.build(clientId.toString(), loanProductId.toString(), null);
171+
List<HashMap> error = (List<HashMap>) loanTransactionHelper.createLoanAccount(loanApplicationJSON, CommonConstants.RESPONSE_ERROR);
172+
assertEquals(
173+
"validation.msg.loan.transactionProcessingStrategyCode.strategy.cannot.be.advanced.payment.allocation.if.not.configured",
174+
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
149175

150176
}
151177

@@ -160,17 +186,17 @@ private void trancheLoansApprovedAmountLesserThanProposedAmount(Integer clientID
160186
approveTranches.add(createTrancheDetail("23 March 2014", "1000"));
161187

162188
final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
163-
LOG.info("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}", loanID);
189+
log.info("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}", loanID);
164190

165191
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
166192
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
167193

168-
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
194+
log.info("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
169195
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate, expectedDisbursementDate, approvalAmount,
170196
loanID, approveTranches);
171197
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
172198
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
173-
LOG.info("-----------------------------------MULTI DISBURSAL LOAN APPROVED SUCCESSFULLY---------------------------------------");
199+
log.info("-----------------------------------MULTI DISBURSAL LOAN APPROVED SUCCESSFULLY---------------------------------------");
174200

175201
}
176202

@@ -205,12 +231,12 @@ private void trancheLoansApprovalValidation(Integer clientID, Integer loanProduc
205231
approveTranche4.add(createTrancheDetail("24 March 2014", "100"));
206232

207233
final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
208-
LOG.info("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}", loanID);
234+
log.info("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}", loanID);
209235

210236
HashMap<String, Object> loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
211237
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
212238

213-
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
239+
log.info("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
214240
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode400);
215241

216242
/* Tranches with same expected disbursement date */
@@ -278,7 +304,7 @@ private HashMap<String, String> collaterals(Integer collateralId, BigDecimal qua
278304

279305
public Integer applyForLoanApplicationWithTranches(final Integer clientID, final Integer loanProductID, String principal,
280306
List<HashMap> tranches) {
281-
LOG.info("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
307+
log.info("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
282308
List<HashMap> collaterals = new ArrayList<>();
283309
final Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec);
284310
Assertions.assertNotNull(collateralId);
@@ -304,5 +330,4 @@ public Integer applyForLoanApplicationWithTranches(final Integer clientID, final
304330

305331
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
306332
}
307-
308333
}

0 commit comments

Comments
 (0)