null checks for fixing failing test cases in RD
This commit is contained in:
+11
-12
@@ -49,7 +49,7 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable<Long> {
|
|||||||
@Temporal(TemporalType.DATE)
|
@Temporal(TemporalType.DATE)
|
||||||
@Column(name = "maturity_date", nullable = true)
|
@Column(name = "maturity_date", nullable = true)
|
||||||
private Date maturityDate;
|
private Date maturityDate;
|
||||||
|
|
||||||
@Temporal(TemporalType.DATE)
|
@Temporal(TemporalType.DATE)
|
||||||
@Column(name = "expected_firstdepositon_date")
|
@Column(name = "expected_firstdepositon_date")
|
||||||
private Date expectedFirstDepositOnDate;
|
private Date expectedFirstDepositOnDate;
|
||||||
@@ -179,14 +179,14 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable<Long> {
|
|||||||
}
|
}
|
||||||
return maturityLocalDate;
|
return maturityLocalDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDate getExpectedFirstDepositOnDate() {
|
public LocalDate getExpectedFirstDepositOnDate() {
|
||||||
LocalDate expectedFirstDepositOnLocalDate = null;
|
LocalDate expectedFirstDepositOnLocalDate = null;
|
||||||
if (this.expectedFirstDepositOnDate != null) {
|
if (this.expectedFirstDepositOnDate != null) {
|
||||||
expectedFirstDepositOnLocalDate = new LocalDate(this.expectedFirstDepositOnDate);
|
expectedFirstDepositOnLocalDate = new LocalDate(this.expectedFirstDepositOnDate);
|
||||||
}
|
}
|
||||||
return expectedFirstDepositOnLocalDate;
|
return expectedFirstDepositOnLocalDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPreClosurePenalApplicable() {
|
public boolean isPreClosurePenalApplicable() {
|
||||||
if (this.preClosureDetail != null) { return this.preClosureDetail.preClosurePenalApplicable(); }
|
if (this.preClosureDetail != null) { return this.preClosureDetail.preClosurePenalApplicable(); }
|
||||||
@@ -195,10 +195,9 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable<Long> {
|
|||||||
|
|
||||||
public Integer getActualDepositPeriod(final LocalDate interestPostingUpToDate, final SavingsPeriodFrequencyType periodFrequencyType) {
|
public Integer getActualDepositPeriod(final LocalDate interestPostingUpToDate, final SavingsPeriodFrequencyType periodFrequencyType) {
|
||||||
LocalDate depositFromDate = getExpectedFirstDepositOnDate();
|
LocalDate depositFromDate = getExpectedFirstDepositOnDate();
|
||||||
|
|
||||||
if(depositFromDate == null)
|
if (depositFromDate == null) depositFromDate = this.account.accountSubmittedOrActivationDate();
|
||||||
depositFromDate = this.account.accountSubmittedOrActivationDate();
|
|
||||||
|
|
||||||
Integer actualDepositPeriod = this.depositPeriod;
|
Integer actualDepositPeriod = this.depositPeriod;
|
||||||
if (depositFromDate == null || getMaturityLocalDate() == null || interestPostingUpToDate.isEqual(getMaturityLocalDate())) { return actualDepositPeriod; }
|
if (depositFromDate == null || getMaturityLocalDate() == null || interestPostingUpToDate.isEqual(getMaturityLocalDate())) { return actualDepositPeriod; }
|
||||||
|
|
||||||
@@ -234,7 +233,7 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable<Long> {
|
|||||||
public boolean isReinvestOnClosure() {
|
public boolean isReinvestOnClosure() {
|
||||||
return DepositAccountOnClosureType.fromInt(this.onAccountClosureType).isReinvest();
|
return DepositAccountOnClosureType.fromInt(this.onAccountClosureType).isReinvest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTransferToSavingsOnClosure() {
|
public boolean isTransferToSavingsOnClosure() {
|
||||||
return DepositAccountOnClosureType.fromInt(this.onAccountClosureType).isTransferToSavings();
|
return DepositAccountOnClosureType.fromInt(this.onAccountClosureType).isTransferToSavings();
|
||||||
}
|
}
|
||||||
@@ -249,12 +248,12 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable<Long> {
|
|||||||
final DepositPreClosureDetail preClosureDetail = this.preClosureDetail.copy();
|
final DepositPreClosureDetail preClosureDetail = this.preClosureDetail.copy();
|
||||||
final DepositTermDetail depositTermDetail = this.depositTermDetail.copy();
|
final DepositTermDetail depositTermDetail = this.depositTermDetail.copy();
|
||||||
final LocalDate expectedFirstDepositOnDate = null;
|
final LocalDate expectedFirstDepositOnDate = null;
|
||||||
|
|
||||||
final DepositAccountOnClosureType accountOnClosureType = null;
|
final DepositAccountOnClosureType accountOnClosureType = null;
|
||||||
return DepositAccountTermAndPreClosure.createNew(preClosureDetail, depositTermDetail, account, actualDepositAmount, maturityAmount,
|
return DepositAccountTermAndPreClosure.createNew(preClosureDetail, depositTermDetail, account, actualDepositAmount, maturityAmount,
|
||||||
maturityDate, depositPeriod, depositPeriodFrequency, expectedFirstDepositOnDate, accountOnClosureType);
|
maturityDate, depositPeriod, depositPeriodFrequency, expectedFirstDepositOnDate, accountOnClosureType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateExpectedFirstDepositDate(final LocalDate expectedFirstDepositOnDate) {
|
public void updateExpectedFirstDepositDate(final LocalDate expectedFirstDepositOnDate) {
|
||||||
this.expectedFirstDepositOnDate = expectedFirstDepositOnDate.toDate();
|
this.expectedFirstDepositOnDate = expectedFirstDepositOnDate.toDate();
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-43
@@ -99,10 +99,10 @@ public class RecurringDepositAccount extends SavingsAccount {
|
|||||||
lockinPeriodFrequencyType, withdrawalFeeApplicableForTransfer, savingsAccountCharges, accountTermAndPreClosure,
|
lockinPeriodFrequencyType, withdrawalFeeApplicableForTransfer, savingsAccountCharges, accountTermAndPreClosure,
|
||||||
recurringDetail, chart, allowOverdraft, overdraftLimit);
|
recurringDetail, chart, allowOverdraft, overdraftLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RecurringDepositAccount createNewActivatedAccount(final Client client, final Group group,
|
public static RecurringDepositAccount createNewActivatedAccount(final Client client, final Group group, final SavingsProduct product,
|
||||||
final SavingsProduct product, final Staff fieldOfficer, final String accountNo, final String externalId,
|
final Staff fieldOfficer, final String accountNo, final String externalId, final AccountType accountType,
|
||||||
final AccountType accountType, final LocalDate submittedOnDate, final AppUser submittedBy, final BigDecimal interestRate,
|
final LocalDate submittedOnDate, final AppUser submittedBy, final BigDecimal interestRate,
|
||||||
final SavingsCompoundingInterestPeriodType interestCompoundingPeriodType,
|
final SavingsCompoundingInterestPeriodType interestCompoundingPeriodType,
|
||||||
final SavingsPostingInterestPeriodType interestPostingPeriodType, final SavingsInterestCalculationType interestCalculationType,
|
final SavingsPostingInterestPeriodType interestPostingPeriodType, final SavingsInterestCalculationType interestCalculationType,
|
||||||
final SavingsInterestCalculationDaysInYearType interestCalculationDaysInYearType, final BigDecimal minRequiredOpeningBalance,
|
final SavingsInterestCalculationDaysInYearType interestCalculationDaysInYearType, final BigDecimal minRequiredOpeningBalance,
|
||||||
@@ -272,8 +272,8 @@ public class RecurringDepositAccount extends SavingsAccount {
|
|||||||
final SavingsInterestCalculationDaysInYearType daysInYearType = SavingsInterestCalculationDaysInYearType
|
final SavingsInterestCalculationDaysInYearType daysInYearType = SavingsInterestCalculationDaysInYearType
|
||||||
.fromInt(this.interestCalculationDaysInYearType);
|
.fromInt(this.interestCalculationDaysInYearType);
|
||||||
|
|
||||||
final List<LocalDateInterval> postingPeriodIntervals = this.savingsHelper.determineInterestPostingPeriods(
|
final List<LocalDateInterval> postingPeriodIntervals = this.savingsHelper.determineInterestPostingPeriods(depositStartDate(),
|
||||||
depositStartDate(), maturityDate, postingPeriodType);
|
maturityDate, postingPeriodType);
|
||||||
|
|
||||||
final List<PostingPeriod> allPostingPeriods = new ArrayList<PostingPeriod>();
|
final List<PostingPeriod> allPostingPeriods = new ArrayList<PostingPeriod>();
|
||||||
|
|
||||||
@@ -380,8 +380,7 @@ public class RecurringDepositAccount extends SavingsAccount {
|
|||||||
// TODO: Support to add deposit start date which can be a date after
|
// TODO: Support to add deposit start date which can be a date after
|
||||||
// account activation date.
|
// account activation date.
|
||||||
final LocalDate depositStartDate = accountTermAndPreClosure.getExpectedFirstDepositOnDate();
|
final LocalDate depositStartDate = accountTermAndPreClosure.getExpectedFirstDepositOnDate();
|
||||||
if(depositStartDate == null)
|
if (depositStartDate == null) return accountSubmittedOrActivationDate();
|
||||||
return accountSubmittedOrActivationDate();
|
|
||||||
return depositStartDate;
|
return depositStartDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,19 +459,19 @@ public class RecurringDepositAccount extends SavingsAccount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processAccountUponActivation(final DateTimeFormatter fmt) {
|
protected void processAccountUponActivation(final DateTimeFormatter fmt) {
|
||||||
final Money minRequiredOpeningBalance = Money.of(this.currency, this.minRequiredOpeningBalance);
|
final Money minRequiredOpeningBalance = Money.of(this.currency, this.minRequiredOpeningBalance);
|
||||||
|
|
||||||
if (minRequiredOpeningBalance.isGreaterThanZero()) {
|
if (minRequiredOpeningBalance.isGreaterThanZero()) {
|
||||||
final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, getActivationLocalDate(),
|
final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, getActivationLocalDate(),
|
||||||
minRequiredOpeningBalance.getAmount(), null, new Date());
|
minRequiredOpeningBalance.getAmount(), null, new Date());
|
||||||
deposit(transactionDTO);
|
deposit(transactionDTO);
|
||||||
|
|
||||||
// update existing transactions so derived balance fields are
|
// update existing transactions so derived balance fields are
|
||||||
// correct.
|
// correct.
|
||||||
recalculateDailyBalances(Money.zero(this.currency), DateUtils.getLocalDateOfTenant());
|
recalculateDailyBalances(Money.zero(this.currency), DateUtils.getLocalDateOfTenant());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavingsAccountTransaction close(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate,
|
public SavingsAccountTransaction close(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate,
|
||||||
@@ -803,23 +802,26 @@ public class RecurringDepositAccount extends SavingsAccount {
|
|||||||
if (!chartInterval.contains(accountSubmittedOrActivationDate())) {
|
if (!chartInterval.contains(accountSubmittedOrActivationDate())) {
|
||||||
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("no.valid.interest.rate.slab.available.for.date.range");
|
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("no.valid.interest.rate.slab.available.for.date.range");
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean firstDepositDateBeforeMaturityAndOnOrAfterActivationDate = firstDepositDateBeforeMaturityAndOnOrAfterActivationDate();
|
final boolean firstDepositDateBeforeMaturityAndOnOrAfterActivationDate = firstDepositDateBeforeMaturityAndOnOrAfterActivationDate();
|
||||||
|
|
||||||
if(!firstDepositDateBeforeMaturityAndOnOrAfterActivationDate) {
|
if (!firstDepositDateBeforeMaturityAndOnOrAfterActivationDate) {
|
||||||
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("expected.first.deposit.date.is.not.between.maturity.date.and.activation.or.submitted.date");
|
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode(
|
||||||
|
"expected.first.deposit.date.is.not.between.maturity.date.and.activation.or.submitted.date");
|
||||||
}
|
}
|
||||||
|
|
||||||
final BigDecimal recurringDepositAmount = recurringDetail.recurringDepositAmount();
|
final BigDecimal recurringDepositAmount = recurringDetail.recurringDepositAmount();
|
||||||
BigDecimal applicableInterestRate = this.chart.getApplicableInterestRate(recurringDepositAmount, depositStartDate(), calculateMaturityDate());
|
BigDecimal applicableInterestRate = this.chart.getApplicableInterestRate(recurringDepositAmount, depositStartDate(),
|
||||||
|
calculateMaturityDate());
|
||||||
if(applicableInterestRate.equals(BigDecimal.ZERO)) {
|
|
||||||
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("no.applicable.interest.rate.is.found.based.on.amount.and.deposit.period");
|
if (applicableInterestRate.equals(BigDecimal.ZERO)) {
|
||||||
|
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode(
|
||||||
|
"no.applicable.interest.rate.is.found.based.on.amount.and.deposit.period");
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean recurringFrequencyBeforeDepositPeriod = recurringFrequencyBeforeDepositPeriod();
|
final boolean recurringFrequencyBeforeDepositPeriod = recurringFrequencyBeforeDepositPeriod();
|
||||||
|
|
||||||
if(!recurringFrequencyBeforeDepositPeriod) {
|
if (!recurringFrequencyBeforeDepositPeriod) {
|
||||||
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("recurring.frequency.not.before.deposit.period");
|
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("recurring.frequency.not.before.deposit.period");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -854,33 +856,35 @@ public class RecurringDepositAccount extends SavingsAccount {
|
|||||||
final SavingsPeriodFrequencyType lockinPeriodFrequencyType = SavingsPeriodFrequencyType.fromInt(this.lockinPeriodFrequencyType);
|
final SavingsPeriodFrequencyType lockinPeriodFrequencyType = SavingsPeriodFrequencyType.fromInt(this.lockinPeriodFrequencyType);
|
||||||
final Integer lockinPeriodFrequency = this.lockinPeriodFrequency;
|
final Integer lockinPeriodFrequency = this.lockinPeriodFrequency;
|
||||||
final boolean withdrawalFeeApplicableForTransfer = false;
|
final boolean withdrawalFeeApplicableForTransfer = false;
|
||||||
|
|
||||||
LocalDate now = LocalDate.now();
|
LocalDate now = LocalDate.now();
|
||||||
|
|
||||||
newAccountTermAndPreClosure.updateExpectedFirstDepositDate(now);
|
newAccountTermAndPreClosure.updateExpectedFirstDepositDate(now);
|
||||||
|
|
||||||
RecurringDepositAccount rdAccount = RecurringDepositAccount.createNewActivatedAccount(client, group, product, fieldOfficer, accountNumber, externalId,
|
RecurringDepositAccount rdAccount = RecurringDepositAccount.createNewActivatedAccount(client, group, product, fieldOfficer,
|
||||||
accountType, getClosedOnDate(), closedBy, interestRate, compoundingPeriodType, postingPeriodType, interestCalculationType,
|
accountNumber, externalId, accountType, getClosedOnDate(), closedBy, interestRate, compoundingPeriodType,
|
||||||
daysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyType,
|
postingPeriodType, interestCalculationType, daysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency,
|
||||||
withdrawalFeeApplicableForTransfer, savingsAccountCharges, newAccountTermAndPreClosure, recurringDetail, newChart);
|
lockinPeriodFrequencyType, withdrawalFeeApplicableForTransfer, savingsAccountCharges, newAccountTermAndPreClosure,
|
||||||
|
recurringDetail, newChart);
|
||||||
rdAccount.setDatesFrom(now);
|
|
||||||
newAccountTermAndPreClosure.updateAccountReference(rdAccount);
|
rdAccount.setDatesFrom(now);
|
||||||
|
newAccountTermAndPreClosure.updateAccountReference(rdAccount);
|
||||||
recurringDetail.updateAccountReference(rdAccount);
|
recurringDetail.updateAccountReference(rdAccount);
|
||||||
|
|
||||||
return rdAccount;
|
return rdAccount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean firstDepositDateBeforeMaturityAndOnOrAfterActivationDate() {
|
private boolean firstDepositDateBeforeMaturityAndOnOrAfterActivationDate() {
|
||||||
LocalDate expectedFirstDepositLocalDate = accountTermAndPreClosure.getExpectedFirstDepositOnDate();
|
LocalDate expectedFirstDepositLocalDate = accountTermAndPreClosure.getExpectedFirstDepositOnDate();
|
||||||
LocalDate maturityLocalDate = calculateMaturityDate();
|
LocalDate maturityLocalDate = calculateMaturityDate();
|
||||||
LocalDate activateOnSubmittedLocalDate = accountSubmittedOrActivationDate();
|
LocalDate activateOnSubmittedLocalDate = accountSubmittedOrActivationDate();
|
||||||
|
if (expectedFirstDepositLocalDate != null) { return expectedFirstDepositLocalDate.isBefore(maturityLocalDate)
|
||||||
return expectedFirstDepositLocalDate.isBefore(maturityLocalDate) &&
|
&& (activateOnSubmittedLocalDate.isEqual(expectedFirstDepositLocalDate) || activateOnSubmittedLocalDate
|
||||||
(activateOnSubmittedLocalDate.isEqual(expectedFirstDepositLocalDate) || activateOnSubmittedLocalDate.isBefore(expectedFirstDepositLocalDate));
|
.isBefore(expectedFirstDepositLocalDate)); }
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDatesFrom(final LocalDate now) {
|
public void setDatesFrom(final LocalDate now) {
|
||||||
this.rejectedOnDate = null;
|
this.rejectedOnDate = null;
|
||||||
this.rejectedBy = null;
|
this.rejectedBy = null;
|
||||||
@@ -888,11 +892,11 @@ public class RecurringDepositAccount extends SavingsAccount {
|
|||||||
this.withdrawnBy = null;
|
this.withdrawnBy = null;
|
||||||
this.closedOnDate = null;
|
this.closedOnDate = null;
|
||||||
this.closedBy = null;
|
this.closedBy = null;
|
||||||
|
|
||||||
this.activatedBy = null;
|
this.activatedBy = null;
|
||||||
this.lockedInUntilDate = null;
|
this.lockedInUntilDate = null;
|
||||||
|
|
||||||
this.activatedOnDate = now.toDate();
|
this.activatedOnDate = now.toDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean recurringFrequencyBeforeDepositPeriod() {
|
private boolean recurringFrequencyBeforeDepositPeriod() {
|
||||||
@@ -921,5 +925,5 @@ public class RecurringDepositAccount extends SavingsAccount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return endDateWithFirstRecurringFrequency != null && endDateWithFirstRecurringFrequency.isBefore(calculateMaturityDate());
|
return endDateWithFirstRecurringFrequency != null && endDateWithFirstRecurringFrequency.isBefore(calculateMaturityDate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user