MIFOSX-1728

This commit is contained in:
Vishwas Babu A J
2014-12-08 17:50:14 -08:00
parent 7c64de0a1c
commit 3d399eba10
2 changed files with 42 additions and 7 deletions
@@ -763,10 +763,43 @@ public final class LoanApplicationCommandFromApiJsonHelper {
}
public void validateLoanTermAndRepaidEveryValues(final Integer loanTermFrequency, final Integer loanTermFrequencyType,
final Integer numberOfRepayments, final Integer repaymentEvery, final Integer repaymentEveryType) {
final Integer numberOfRepayments, final Integer repaymentEvery, final Integer repaymentEveryType, final Loan loan) {
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
this.apiJsonHelper.validateSelectedPeriodFrequencyTypeIsTheSame(dataValidationErrors, loanTermFrequency, loanTermFrequencyType,
numberOfRepayments, repaymentEvery, repaymentEveryType);
/**
* For multi-disbursal loans where schedules are auto-generated based on
* a fixed EMI, ensure the number of repayments is within the
* permissible range defined by the loan product
**/
if (loan.loanProduct().isMultiDisburseLoan() && loan.getFixedEmiAmount() != null) {
Integer minimumNoOfRepayments = loan.loanProduct().getMinNumberOfRepayments();
Integer maximumNoOfRepayments = loan.loanProduct().getMaxNumberOfRepayments();
Integer actualNumberOfRepayments = loan.getRepaymentScheduleInstallments().size();
// validate actual number of repayments is > minimum number of
// repayments
if (minimumNoOfRepayments != null && minimumNoOfRepayments != 0 && actualNumberOfRepayments < minimumNoOfRepayments) {
final ApiParameterError error = ApiParameterError.generalError(
"validation.msg.loan.numberOfRepayments.lesser.than.minimumNumberOfRepayments",
"The total number of calculated repayments for this loan " + actualNumberOfRepayments
+ " is lesser than the allowed minimum of " + minimumNoOfRepayments, actualNumberOfRepayments,
minimumNoOfRepayments);
dataValidationErrors.add(error);
}
// validate actual number of repayments is < maximum number of
// repayments
if (maximumNoOfRepayments != null && maximumNoOfRepayments != 0 && actualNumberOfRepayments > maximumNoOfRepayments) {
final ApiParameterError error = ApiParameterError.generalError(
"validation.msg.loan.numberOfRepayments.greater.than.maximumNumberOfRepayments",
"The total number of calculated repayments for this loan " + actualNumberOfRepayments
+ " is greater than the allowed maximum of " + maximumNoOfRepayments, actualNumberOfRepayments,
maximumNoOfRepayments);
dataValidationErrors.add(error);
}
}
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); }
}
@@ -227,7 +227,8 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
final LoanProductRelatedDetail productRelatedDetail = newLoanApplication.repaymentScheduleDetail();
this.fromApiJsonDeserializer.validateLoanTermAndRepaidEveryValues(newLoanApplication.getTermFrequency(),
newLoanApplication.getTermPeriodFrequencyType(), productRelatedDetail.getNumberOfRepayments(),
productRelatedDetail.getRepayEvery(), productRelatedDetail.getRepaymentPeriodFrequencyType().getValue());
productRelatedDetail.getRepayEvery(), productRelatedDetail.getRepaymentPeriodFrequencyType().getValue(),
newLoanApplication);
this.loanRepository.save(newLoanApplication);
@@ -487,11 +488,6 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
existingLoanApplication.updateIsInterestRecalculationEnabled();
validateSubmittedOnDate(existingLoanApplication);
final LoanProductRelatedDetail productRelatedDetail = existingLoanApplication.repaymentScheduleDetail();
this.fromApiJsonDeserializer.validateLoanTermAndRepaidEveryValues(existingLoanApplication.getTermFrequency(),
existingLoanApplication.getTermPeriodFrequencyType(), productRelatedDetail.getNumberOfRepayments(),
productRelatedDetail.getRepayEvery(), productRelatedDetail.getRepaymentPeriodFrequencyType().getValue());
final String fundIdParamName = "fundId";
if (changes.containsKey(fundIdParamName)) {
final Long fundId = command.longValueOfParameterNamed(fundIdParamName);
@@ -544,6 +540,12 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
existingLoanApplication.updateLoanCharges(possiblyModifedLoanCharges);
}
final LoanProductRelatedDetail productRelatedDetail = existingLoanApplication.repaymentScheduleDetail();
this.fromApiJsonDeserializer.validateLoanTermAndRepaidEveryValues(existingLoanApplication.getTermFrequency(),
existingLoanApplication.getTermPeriodFrequencyType(), productRelatedDetail.getNumberOfRepayments(),
productRelatedDetail.getRepayEvery(), productRelatedDetail.getRepaymentPeriodFrequencyType().getValue(),
existingLoanApplication);
saveAndFlushLoanWithDataIntegrityViolationChecks(existingLoanApplication);
final String submittedOnNote = command.stringValueOfParameterNamed("submittedOnNote");