null checks for fixing failing test cases in RD

This commit is contained in:
Vishwas Babu A J
2014-04-30 17:46:18 +05:30
parent 508fe4b60d
commit b69b071ffe
2 changed files with 58 additions and 55 deletions
@@ -49,7 +49,7 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable<Long> {
@Temporal(TemporalType.DATE)
@Column(name = "maturity_date", nullable = true)
private Date maturityDate;
@Temporal(TemporalType.DATE)
@Column(name = "expected_firstdepositon_date")
private Date expectedFirstDepositOnDate;
@@ -179,14 +179,14 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable<Long> {
}
return maturityLocalDate;
}
public LocalDate getExpectedFirstDepositOnDate() {
LocalDate expectedFirstDepositOnLocalDate = null;
LocalDate expectedFirstDepositOnLocalDate = null;
if (this.expectedFirstDepositOnDate != null) {
expectedFirstDepositOnLocalDate = new LocalDate(this.expectedFirstDepositOnDate);
expectedFirstDepositOnLocalDate = new LocalDate(this.expectedFirstDepositOnDate);
}
return expectedFirstDepositOnLocalDate;
}
}
public boolean isPreClosurePenalApplicable() {
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) {
LocalDate depositFromDate = getExpectedFirstDepositOnDate();
if(depositFromDate == null)
depositFromDate = this.account.accountSubmittedOrActivationDate();
if (depositFromDate == null) depositFromDate = this.account.accountSubmittedOrActivationDate();
Integer actualDepositPeriod = this.depositPeriod;
if (depositFromDate == null || getMaturityLocalDate() == null || interestPostingUpToDate.isEqual(getMaturityLocalDate())) { return actualDepositPeriod; }
@@ -234,7 +233,7 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable<Long> {
public boolean isReinvestOnClosure() {
return DepositAccountOnClosureType.fromInt(this.onAccountClosureType).isReinvest();
}
public boolean isTransferToSavingsOnClosure() {
return DepositAccountOnClosureType.fromInt(this.onAccountClosureType).isTransferToSavings();
}
@@ -249,12 +248,12 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable<Long> {
final DepositPreClosureDetail preClosureDetail = this.preClosureDetail.copy();
final DepositTermDetail depositTermDetail = this.depositTermDetail.copy();
final LocalDate expectedFirstDepositOnDate = null;
final DepositAccountOnClosureType accountOnClosureType = null;
return DepositAccountTermAndPreClosure.createNew(preClosureDetail, depositTermDetail, account, actualDepositAmount, maturityAmount,
maturityDate, depositPeriod, depositPeriodFrequency, expectedFirstDepositOnDate, accountOnClosureType);
}
public void updateExpectedFirstDepositDate(final LocalDate expectedFirstDepositOnDate) {
this.expectedFirstDepositOnDate = expectedFirstDepositOnDate.toDate();
}
@@ -99,10 +99,10 @@ public class RecurringDepositAccount extends SavingsAccount {
lockinPeriodFrequencyType, withdrawalFeeApplicableForTransfer, savingsAccountCharges, accountTermAndPreClosure,
recurringDetail, chart, allowOverdraft, overdraftLimit);
}
public static RecurringDepositAccount createNewActivatedAccount(final Client client, final Group group,
final SavingsProduct product, final Staff fieldOfficer, final String accountNo, final String externalId,
final AccountType accountType, final LocalDate submittedOnDate, final AppUser submittedBy, final BigDecimal interestRate,
public static RecurringDepositAccount createNewActivatedAccount(final Client client, final Group group, final SavingsProduct product,
final Staff fieldOfficer, final String accountNo, final String externalId, final AccountType accountType,
final LocalDate submittedOnDate, final AppUser submittedBy, final BigDecimal interestRate,
final SavingsCompoundingInterestPeriodType interestCompoundingPeriodType,
final SavingsPostingInterestPeriodType interestPostingPeriodType, final SavingsInterestCalculationType interestCalculationType,
final SavingsInterestCalculationDaysInYearType interestCalculationDaysInYearType, final BigDecimal minRequiredOpeningBalance,
@@ -272,8 +272,8 @@ public class RecurringDepositAccount extends SavingsAccount {
final SavingsInterestCalculationDaysInYearType daysInYearType = SavingsInterestCalculationDaysInYearType
.fromInt(this.interestCalculationDaysInYearType);
final List<LocalDateInterval> postingPeriodIntervals = this.savingsHelper.determineInterestPostingPeriods(
depositStartDate(), maturityDate, postingPeriodType);
final List<LocalDateInterval> postingPeriodIntervals = this.savingsHelper.determineInterestPostingPeriods(depositStartDate(),
maturityDate, postingPeriodType);
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
// account activation date.
final LocalDate depositStartDate = accountTermAndPreClosure.getExpectedFirstDepositOnDate();
if(depositStartDate == null)
return accountSubmittedOrActivationDate();
if (depositStartDate == null) return accountSubmittedOrActivationDate();
return depositStartDate;
}
@@ -460,19 +459,19 @@ public class RecurringDepositAccount extends SavingsAccount {
}
@Override
protected void processAccountUponActivation(final DateTimeFormatter fmt) {
protected void processAccountUponActivation(final DateTimeFormatter fmt) {
final Money minRequiredOpeningBalance = Money.of(this.currency, this.minRequiredOpeningBalance);
if (minRequiredOpeningBalance.isGreaterThanZero()) {
final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, getActivationLocalDate(),
minRequiredOpeningBalance.getAmount(), null, new Date());
deposit(transactionDTO);
// update existing transactions so derived balance fields are
// correct.
recalculateDailyBalances(Money.zero(this.currency), DateUtils.getLocalDateOfTenant());
}
}
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())) {
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("no.valid.interest.rate.slab.available.for.date.range");
}
final boolean firstDepositDateBeforeMaturityAndOnOrAfterActivationDate = firstDepositDateBeforeMaturityAndOnOrAfterActivationDate();
if(!firstDepositDateBeforeMaturityAndOnOrAfterActivationDate) {
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("expected.first.deposit.date.is.not.between.maturity.date.and.activation.or.submitted.date");
if (!firstDepositDateBeforeMaturityAndOnOrAfterActivationDate) {
baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode(
"expected.first.deposit.date.is.not.between.maturity.date.and.activation.or.submitted.date");
}
final BigDecimal recurringDepositAmount = recurringDetail.recurringDepositAmount();
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");
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");
}
final boolean recurringFrequencyBeforeDepositPeriod = recurringFrequencyBeforeDepositPeriod();
if(!recurringFrequencyBeforeDepositPeriod) {
if (!recurringFrequencyBeforeDepositPeriod) {
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 Integer lockinPeriodFrequency = this.lockinPeriodFrequency;
final boolean withdrawalFeeApplicableForTransfer = false;
LocalDate now = LocalDate.now();
newAccountTermAndPreClosure.updateExpectedFirstDepositDate(now);
RecurringDepositAccount rdAccount = RecurringDepositAccount.createNewActivatedAccount(client, group, product, fieldOfficer, accountNumber, externalId,
accountType, getClosedOnDate(), closedBy, interestRate, compoundingPeriodType, postingPeriodType, interestCalculationType,
daysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyType,
withdrawalFeeApplicableForTransfer, savingsAccountCharges, newAccountTermAndPreClosure, recurringDetail, newChart);
rdAccount.setDatesFrom(now);
newAccountTermAndPreClosure.updateAccountReference(rdAccount);
RecurringDepositAccount rdAccount = RecurringDepositAccount.createNewActivatedAccount(client, group, product, fieldOfficer,
accountNumber, externalId, accountType, getClosedOnDate(), closedBy, interestRate, compoundingPeriodType,
postingPeriodType, interestCalculationType, daysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency,
lockinPeriodFrequencyType, withdrawalFeeApplicableForTransfer, savingsAccountCharges, newAccountTermAndPreClosure,
recurringDetail, newChart);
rdAccount.setDatesFrom(now);
newAccountTermAndPreClosure.updateAccountReference(rdAccount);
recurringDetail.updateAccountReference(rdAccount);
return rdAccount;
}
private boolean firstDepositDateBeforeMaturityAndOnOrAfterActivationDate() {
LocalDate expectedFirstDepositLocalDate = accountTermAndPreClosure.getExpectedFirstDepositOnDate();
LocalDate maturityLocalDate = calculateMaturityDate();
LocalDate activateOnSubmittedLocalDate = accountSubmittedOrActivationDate();
return expectedFirstDepositLocalDate.isBefore(maturityLocalDate) &&
(activateOnSubmittedLocalDate.isEqual(expectedFirstDepositLocalDate) || activateOnSubmittedLocalDate.isBefore(expectedFirstDepositLocalDate));
if (expectedFirstDepositLocalDate != null) { return expectedFirstDepositLocalDate.isBefore(maturityLocalDate)
&& (activateOnSubmittedLocalDate.isEqual(expectedFirstDepositLocalDate) || activateOnSubmittedLocalDate
.isBefore(expectedFirstDepositLocalDate)); }
return true;
}
public void setDatesFrom(final LocalDate now) {
this.rejectedOnDate = null;
this.rejectedBy = null;
@@ -888,11 +892,11 @@ public class RecurringDepositAccount extends SavingsAccount {
this.withdrawnBy = null;
this.closedOnDate = null;
this.closedBy = null;
this.activatedBy = null;
this.lockedInUntilDate = null;
this.activatedOnDate = now.toDate();
this.activatedOnDate = now.toDate();
}
private boolean recurringFrequencyBeforeDepositPeriod() {
@@ -921,5 +925,5 @@ public class RecurringDepositAccount extends SavingsAccount {
}
return endDateWithFirstRecurringFrequency != null && endDateWithFirstRecurringFrequency.isBefore(calculateMaturityDate());
}
}
}