remove warnings for unused code, formating in savings area.

This commit is contained in:
Keith Woodlock
2013-02-18 10:55:55 +00:00
parent cc27eccd79
commit e20869ad9b
14 changed files with 656 additions and 664 deletions
@@ -24,12 +24,9 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.mifosplatform.commands.domain.CommandWrapper;
import org.mifosplatform.commands.service.CommandWrapperBuilder;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer; import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
@@ -56,7 +53,7 @@ public class GroupsApiResource {
"clientMembers", "allowedClients", "allowedOffices")); "clientMembers", "allowedClients", "allowedOffices"));
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private GroupReadPlatformService groupReadPlatformService; private final GroupReadPlatformService groupReadPlatformService;
private final GroupWritePlatformService groupWritePlatformService; private final GroupWritePlatformService groupWritePlatformService;
private final ClientReadPlatformService clientReadPlatformService; private final ClientReadPlatformService clientReadPlatformService;
private final OfficeReadPlatformService officeReadPlatformService; private final OfficeReadPlatformService officeReadPlatformService;
@@ -240,7 +237,7 @@ public class GroupsApiResource {
// 'g.' preffix because of ERROR 1052 (23000): Column 'column_name' in where // 'g.' preffix because of ERROR 1052 (23000): Column 'column_name' in where
// clause is ambiguous // clause is ambiguous
// caused by the same name of columns in m_office and m_group tables // caused by the same name of columns in m_office and m_group tables
private String getGroupExtraCriteria(String sqlSearch, Long officeId, String externalId, String name, String hierarchy) { private String getGroupExtraCriteria(String sqlSearch, final Long officeId, final String externalId, final String name, final String hierarchy) {
String extraCriteria = ""; String extraCriteria = "";
@@ -272,8 +269,4 @@ public class GroupsApiResource {
return extraCriteria; return extraCriteria;
} }
private boolean is(final String commandParam, final String commandValue) {
return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue);
}
} }
@@ -27,12 +27,10 @@ import org.springframework.data.jpa.domain.AbstractPersistable;
@Table(name = "m_group") @Table(name = "m_group")
public class Group extends AbstractPersistable<Long> { public class Group extends AbstractPersistable<Long> {
@SuppressWarnings("unused")
@ManyToOne @ManyToOne
@JoinColumn(name = "office_id", nullable = false) @JoinColumn(name = "office_id", nullable = false)
private Office office; private Office office;
@SuppressWarnings("unused")
@ManyToOne @ManyToOne
@JoinColumn(name = "loan_officer_id", nullable = true) @JoinColumn(name = "loan_officer_id", nullable = true)
private Staff loanOfficer; private Staff loanOfficer;
@@ -56,11 +54,11 @@ public class Group extends AbstractPersistable<Long> {
this.clientMembers = new HashSet<Client>(); this.clientMembers = new HashSet<Client>();
} }
public static Group newGroup(Office office, Staff loanOfficer , String name, String externalId, Set<Client> clientMembers) { public static Group newGroup(final Office office, final Staff loanOfficer , final String name, final String externalId, final Set<Client> clientMembers) {
return new Group(office, loanOfficer , name, externalId, clientMembers); return new Group(office, loanOfficer , name, externalId, clientMembers);
} }
public Group(Office office, Staff loanOfficer , String name, String externalId, Set<Client> clientMembers) { public Group(final Office office, final Staff loanOfficer , final String name, final String externalId, final Set<Client> clientMembers) {
this.office = office; this.office = office;
this.loanOfficer = loanOfficer; this.loanOfficer = loanOfficer;
if (StringUtils.isNotBlank(name)) { if (StringUtils.isNotBlank(name)) {
@@ -114,7 +112,7 @@ public class Group extends AbstractPersistable<Long> {
} }
} }
public void unassigLoanOfficer(GroupCommand command) { public void unassigLoanOfficer(final GroupCommand command) {
if (command.isLoanOfficerChanged()) { if (command.isLoanOfficerChanged()) {
this.loanOfficer = null; this.loanOfficer = null;
} }
@@ -78,16 +78,18 @@ public class SavingAccountData {
return new SavingAccountData(clientId, clientDisplayName); return new SavingAccountData(clientId, clientDisplayName);
} }
public SavingAccountData(Long id, EnumOptionData status, String externalId, Long clientId, String clientName, Long productId, public SavingAccountData(final Long id, final EnumOptionData status, final String externalId, final Long clientId,
String productName, EnumOptionData productType, CurrencyData currencyData, BigDecimal savingsDepositAmountPerPeriod, final String clientName, final Long productId, final String productName, final EnumOptionData productType,
EnumOptionData savingsFrequencyType, BigDecimal totalDepositAmount, BigDecimal recurringInterestRate, final CurrencyData currencyData, final BigDecimal savingsDepositAmountPerPeriod, final EnumOptionData savingsFrequencyType,
BigDecimal savingInterestRate, EnumOptionData interestType, EnumOptionData interestCalculationMethod, Integer tenure, final BigDecimal totalDepositAmount, final BigDecimal recurringInterestRate, final BigDecimal savingInterestRate,
EnumOptionData tenureType, LocalDate projectedCommencementDate, LocalDate actualCommencementDate, LocalDate maturesOnDate, final EnumOptionData interestType, final EnumOptionData interestCalculationMethod, final Integer tenure,
BigDecimal projectedInterestAccuredOnMaturity, BigDecimal actualInterestAccured, BigDecimal projectedMaturityAmount, final EnumOptionData tenureType, final LocalDate projectedCommencementDate, final LocalDate actualCommencementDate,
BigDecimal actualMaturityAmount, boolean preClosureAllowed, BigDecimal preClosureInterestRate, LocalDate withdrawnonDate, final LocalDate maturesOnDate, final BigDecimal projectedInterestAccuredOnMaturity, final BigDecimal actualInterestAccured,
LocalDate rejectedonDate, LocalDate closedonDate, boolean isLockinPeriodAllowed, Integer lockinPeriod, final BigDecimal projectedMaturityAmount, final BigDecimal actualMaturityAmount, final boolean preClosureAllowed,
EnumOptionData lockinPeriodType, Integer depositEvery, BigDecimal outstandingAmount, Integer interestPostEvery, final BigDecimal preClosureInterestRate, final LocalDate withdrawnonDate, final LocalDate rejectedonDate,
EnumOptionData interestPostFrequency) { final LocalDate closedonDate, final boolean isLockinPeriodAllowed, final Integer lockinPeriod,
final EnumOptionData lockinPeriodType, final Integer depositEvery, final BigDecimal outstandingAmount,
final Integer interestPostEvery, final EnumOptionData interestPostFrequency) {
this.id = id; this.id = id;
this.status = status; this.status = status;
this.externalId = externalId; this.externalId = externalId;
@@ -140,7 +142,7 @@ public class SavingAccountData {
this.interestPostFrequency = interestPostFrequency; this.interestPostFrequency = interestPostFrequency;
} }
public SavingAccountData(Long clientId, String clientName) { public SavingAccountData(final Long clientId, final String clientName) {
this.id = null; this.id = null;
this.status = null; this.status = null;
this.externalId = null; this.externalId = null;
@@ -193,11 +195,11 @@ public class SavingAccountData {
this.interestPostFrequency = null; this.interestPostFrequency = null;
} }
public SavingAccountData(SavingAccountData account, Collection<SavingProductLookup> productOptions, public SavingAccountData(final SavingAccountData account, final Collection<SavingProductLookup> productOptions,
Collection<CurrencyData> currencyOptions, List<EnumOptionData> savingsProductTypeOptions, final Collection<CurrencyData> currencyOptions, final List<EnumOptionData> savingsProductTypeOptions,
List<EnumOptionData> tenureTypeOptions, List<EnumOptionData> savingFrequencyOptions, final List<EnumOptionData> tenureTypeOptions, final List<EnumOptionData> savingFrequencyOptions,
List<EnumOptionData> savingsInterestTypeOptions, List<EnumOptionData> lockinPeriodTypeOptions, final List<EnumOptionData> savingsInterestTypeOptions, final List<EnumOptionData> lockinPeriodTypeOptions,
List<EnumOptionData> interestCalculationOptions, BigDecimal dueAmount) { final List<EnumOptionData> interestCalculationOptions, final BigDecimal dueAmount) {
this.id = account.id; this.id = account.id;
this.status = account.status; this.status = account.status;
this.externalId = account.externalId; this.externalId = account.externalId;
@@ -252,12 +254,11 @@ public class SavingAccountData {
this.interestPostFrequency = account.interestPostFrequency; this.interestPostFrequency = account.interestPostFrequency;
} }
// FIXME - Madhukar - unused variables been passed into construction - why? public SavingAccountData(final Long clientId, final String clientName, final Long productId, final String productName,
public SavingAccountData(Long clientId, String clientName, Long productId, String productName, CurrencyData currency, final CurrencyData currency, final BigDecimal interestRate, final BigDecimal savingsDepositAmountPerPeriod,
BigDecimal interestRate, BigDecimal savingsDepositAmountPerPeriod, EnumOptionData productType, EnumOptionData tenureType, final EnumOptionData productType, final EnumOptionData tenureType, final Integer tenure,
Integer tenure, EnumOptionData savingsFrequencyType, EnumOptionData interestType, EnumOptionData interestCalculationMethod, final EnumOptionData savingsFrequencyType, final EnumOptionData interestType, final EnumOptionData interestCalculationMethod,
BigDecimal minimumBalanceForWithdrawal, boolean partialDepositAllowed, boolean lockinPeriodAllowed, Integer lockinPeriod, final boolean lockinPeriodAllowed, final Integer lockinPeriod, final EnumOptionData lockinPeriodType, final Integer depositEvery) {
EnumOptionData lockinPeriodType, Integer depositEvery) {
this.id = null; this.id = null;
this.status = null; this.status = null;
this.externalId = null; this.externalId = null;
@@ -310,7 +311,7 @@ public class SavingAccountData {
this.interestPostFrequency = savingsFrequencyType; this.interestPostFrequency = savingsFrequencyType;
} }
public SavingAccountData(SavingAccountData account, SavingPermissionData permissions) { public SavingAccountData(final SavingAccountData account, final SavingPermissionData permissions) {
this.id = account.id; this.id = account.id;
this.status = account.status; this.status = account.status;
this.externalId = account.externalId; this.externalId = account.externalId;
@@ -364,7 +365,7 @@ public class SavingAccountData {
this.interestPostFrequency = account.interestPostFrequency; this.interestPostFrequency = account.interestPostFrequency;
} }
public SavingAccountData(SavingAccountData account, SavingScheduleData savingScheduleData) { public SavingAccountData(final SavingAccountData account, final SavingScheduleData savingScheduleData) {
this.id = account.id; this.id = account.id;
this.status = account.status; this.status = account.status;
this.externalId = account.externalId; this.externalId = account.externalId;
@@ -418,7 +419,7 @@ public class SavingAccountData {
this.interestPostFrequency = account.interestPostFrequency; this.interestPostFrequency = account.interestPostFrequency;
} }
public SavingAccountData(SavingAccountData account, Collection<SavingAccountTransactionsData> transactions) { public SavingAccountData(final SavingAccountData account, final Collection<SavingAccountTransactionsData> transactions) {
this.id = account.id; this.id = account.id;
this.status = account.status; this.status = account.status;
this.externalId = account.externalId; this.externalId = account.externalId;
@@ -9,110 +9,110 @@ import java.math.BigDecimal;
import java.math.MathContext; import java.math.MathContext;
import java.math.RoundingMode; import java.math.RoundingMode;
import org.joda.time.LocalDate;
import org.mifosplatform.organisation.monetary.domain.Money; import org.mifosplatform.organisation.monetary.domain.Money;
import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingFrequencyType; import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingFrequencyType;
import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingInterestCalculationMethod; import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingInterestCalculationMethod;
import org.mifosplatform.portfolio.savingsdepositproduct.domain.TenureTypeEnum;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class ReccuringDepositInterestCalculator { public class ReccuringDepositInterestCalculator {
private final Integer monthsInYear = 12; private final Integer monthsInYear = 12;
// FIXME - MADHUKAR - Are the unused field here needed? public Money calculateInterestOnMaturityFor(final Money savingsDepositPerPeriod, final Integer tenure,
public Money calculateInterestOnMaturityFor(Money savingsDepositPerPeriod, Integer tenure, BigDecimal reccuringInterestRate, final BigDecimal reccuringInterestRate, final SavingFrequencyType savingFrequencyType,
LocalDate commencementDate, TenureTypeEnum tenureTypeEnum, SavingFrequencyType savingFrequencyType, final SavingInterestCalculationMethod savingInterestCalculationMethod, Integer depositEvery) {
SavingInterestCalculationMethod savingInterestCalculationMethod, Integer depositEvery) {
BigDecimal finalAmount = BigDecimal.ZERO;
MathContext mc = new MathContext(8, RoundingMode.HALF_EVEN);
BigDecimal finalAmount = BigDecimal.ZERO;
MathContext mc = new MathContext(8, RoundingMode.HALF_EVEN);
BigDecimal interestRateAsFraction = reccuringInterestRate.divide(BigDecimal.valueOf(100), mc); BigDecimal interestRateAsFraction = reccuringInterestRate.divide(BigDecimal.valueOf(100), mc);
Integer noofTimesInterestCompoundPerYear = determineIntValue(savingFrequencyType); Integer noofTimesInterestCompoundPerYear = determineIntValue(savingFrequencyType);
BigDecimal interestRatePerPeriod = BigDecimal.valueOf(interestRateAsFraction.doubleValue() BigDecimal interestRatePerPeriod = BigDecimal.valueOf(interestRateAsFraction.doubleValue()
/ noofTimesInterestCompoundPerYear.doubleValue()); / noofTimesInterestCompoundPerYear.doubleValue());
Integer noOfTimestobeCalculated = tenure/depositEvery; Integer noOfTimestobeCalculated = tenure / depositEvery;
if(savingInterestCalculationMethod.isAverageBalance()){ if (savingInterestCalculationMethod.isAverageBalance()) {
BigDecimal termAmount = BigDecimal.ZERO; BigDecimal termAmount = BigDecimal.ZERO;
BigDecimal totalInterest = BigDecimal.ZERO; BigDecimal totalInterest = BigDecimal.ZERO;
BigDecimal closingBalance = BigDecimal.ZERO; BigDecimal closingBalance = BigDecimal.ZERO;
BigDecimal amountPerPeriod = savingsDepositPerPeriod.getAmount(); BigDecimal amountPerPeriod = savingsDepositPerPeriod.getAmount();
Integer depositEveryOriginalValue = depositEvery; Integer depositEveryOriginalValue = depositEvery;
BigDecimal amountPermonth = BigDecimal.valueOf(amountPerPeriod.doubleValue()/depositEvery.doubleValue()); BigDecimal amountPermonth = BigDecimal.valueOf(amountPerPeriod.doubleValue() / depositEvery.doubleValue());
while (noOfTimestobeCalculated > 0) { while (noOfTimestobeCalculated > 0) {
while (depositEvery > 0) { while (depositEvery > 0) {
closingBalance = closingBalance.add(amountPermonth); closingBalance = closingBalance.add(amountPermonth);
termAmount = termAmount.add(closingBalance); termAmount = termAmount.add(closingBalance);
depositEvery--; depositEvery--;
} }
BigDecimal averageAmount = BigDecimal.valueOf(termAmount.doubleValue()/depositEveryOriginalValue.doubleValue()); BigDecimal averageAmount = BigDecimal.valueOf(termAmount.doubleValue() / depositEveryOriginalValue.doubleValue());
BigDecimal interestRatePerTerm = BigDecimal.valueOf(interestRateAsFraction.doubleValue()/monthsInYear.doubleValue()*depositEveryOriginalValue.doubleValue()); BigDecimal interestRatePerTerm = BigDecimal.valueOf(interestRateAsFraction.doubleValue() / monthsInYear.doubleValue()
BigDecimal interestperTerm = averageAmount.multiply(interestRatePerTerm); * depositEveryOriginalValue.doubleValue());
totalInterest = totalInterest.add(interestperTerm); BigDecimal interestperTerm = averageAmount.multiply(interestRatePerTerm);
depositEvery = depositEveryOriginalValue; totalInterest = totalInterest.add(interestperTerm);
termAmount = BigDecimal.ZERO; depositEvery = depositEveryOriginalValue;
noOfTimestobeCalculated--; termAmount = BigDecimal.ZERO;
} noOfTimestobeCalculated--;
finalAmount = closingBalance.add(totalInterest); }
finalAmount = closingBalance.add(totalInterest);
} else if(savingInterestCalculationMethod.isMonthlyCollection()){ } else if (savingInterestCalculationMethod.isMonthlyCollection()) {
/* /*
* // Assuming tenure in months // see * // Assuming tenure in months // see
* http://www.onemint.com/2012/04/03/ * http://www.onemint.com/2012/04/03/
* how-to-calculate-interest-on-recurring-deposits/ * how-to-calculate-interest-on-recurring-deposits/
* *
* A=P(1+r/n)^nt * A=P(1+r/n)^nt
* *
* A = final amount P = principal amount (initial investment) r = annual * A = final amount P = principal amount (initial investment) r =
* nominal interest rate (as a decimal, not in percentage) n = number of * annual nominal interest rate (as a decimal, not in percentage) n
* times the interest is compounded per year t = number of years * = number of times the interest is compounded per year t = number
*/ * of years
*/
BigDecimal onePlusInterestRatePerPeriod = BigDecimal.ONE.add(interestRatePerPeriod); BigDecimal onePlusInterestRatePerPeriod = BigDecimal.ONE.add(interestRatePerPeriod);
BigDecimal monthsExpressedInYears; BigDecimal monthsExpressedInYears;
BigDecimal timeforOneCalculationPeriod; BigDecimal timeforOneCalculationPeriod;
BigDecimal amountPerPeriod; BigDecimal amountPerPeriod;
Integer tempTenure = tenure; Integer tempTenure = tenure;
while (noOfTimestobeCalculated > 0) { while (noOfTimestobeCalculated > 0) {
monthsExpressedInYears = BigDecimal.valueOf(tempTenure.doubleValue() / monthsInYear.doubleValue()); monthsExpressedInYears = BigDecimal.valueOf(tempTenure.doubleValue() / monthsInYear.doubleValue());
timeforOneCalculationPeriod = BigDecimal.valueOf(noofTimesInterestCompoundPerYear * monthsExpressedInYears.doubleValue()); timeforOneCalculationPeriod = BigDecimal.valueOf(noofTimesInterestCompoundPerYear * monthsExpressedInYears.doubleValue());
amountPerPeriod = savingsDepositPerPeriod.getAmount().multiply( amountPerPeriod = savingsDepositPerPeriod.getAmount()
BigDecimal.valueOf(Math.pow(onePlusInterestRatePerPeriod.doubleValue(), timeforOneCalculationPeriod.doubleValue()))); .multiply(
finalAmount = finalAmount.add(amountPerPeriod); BigDecimal.valueOf(Math.pow(onePlusInterestRatePerPeriod.doubleValue(),
noOfTimestobeCalculated--; timeforOneCalculationPeriod.doubleValue())));
tempTenure = tempTenure-depositEvery; finalAmount = finalAmount.add(amountPerPeriod);
} noOfTimestobeCalculated--;
} tempTenure = tempTenure - depositEvery;
return Money.of(savingsDepositPerPeriod.getCurrency(), finalAmount); }
}
return Money.of(savingsDepositPerPeriod.getCurrency(), finalAmount);
} }
private Integer determineIntValue(SavingFrequencyType frequencyType){ private Integer determineIntValue(final SavingFrequencyType frequencyType) {
Integer noofTimesInterestCompoundPerYear = Integer.valueOf(0); Integer noofTimesInterestCompoundPerYear = Integer.valueOf(0);
switch (frequencyType) { switch (frequencyType) {
case MONTHLY: case MONTHLY:
noofTimesInterestCompoundPerYear = monthsInYear; noofTimesInterestCompoundPerYear = monthsInYear;
break; break;
case QUATERLY: case QUATERLY:
noofTimesInterestCompoundPerYear = monthsInYear / 3; noofTimesInterestCompoundPerYear = monthsInYear / 3;
break; break;
case HALFYEARLY: case HALFYEARLY:
noofTimesInterestCompoundPerYear = monthsInYear / 6; noofTimesInterestCompoundPerYear = monthsInYear / 6;
break; break;
case YEARLY: case YEARLY:
noofTimesInterestCompoundPerYear = monthsInYear / 12; noofTimesInterestCompoundPerYear = monthsInYear / 12;
break; break;
default: default:
throw new RuntimeException("The specified frequency not supported"); throw new RuntimeException("The specified frequency not supported");
} }
return noofTimesInterestCompoundPerYear; return noofTimesInterestCompoundPerYear;
} }
} }
@@ -131,7 +131,7 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
private BigDecimal outstandingAmount; private BigDecimal outstandingAmount;
@Column(name = "is_preclosure_allowed", nullable = false) @Column(name = "is_preclosure_allowed", nullable = false)
private boolean preClosureAllowed = false; private final boolean preClosureAllowed = false;
@Column(name = "is_deleted", nullable = false) @Column(name = "is_deleted", nullable = false)
private boolean deleted = false; private boolean deleted = false;
@@ -197,20 +197,20 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
// //
} }
public static SavingAccount openNew(Client client, SavingProduct product, String externalId, Money savingsDeposit, public static SavingAccount openNew(final Client client, final SavingProduct product, final String externalId,
BigDecimal reccuringInterestRate, BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate, final Money savingsDeposit, final BigDecimal reccuringInterestRate, final BigDecimal savingInterestRate, final Integer tenure,
TenureTypeEnum tenureTypeEnum, SavingProductType savingProductType, SavingFrequencyType savingFrequencyType, final LocalDate commencementDate, final TenureTypeEnum tenureTypeEnum, final SavingProductType savingProductType,
SavingsInterestType interestType, SavingInterestCalculationMethod savingInterestCalculationMethod, final SavingFrequencyType savingFrequencyType, final SavingsInterestType interestType,
boolean isLockinPeriodAllowed, Integer lockinPeriod, PeriodFrequencyType lockinPeriodType, final SavingInterestCalculationMethod savingInterestCalculationMethod, final boolean isLockinPeriodAllowed,
ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType,
final DepositLifecycleStateMachine lifecycleStateMachine, Integer depositEvery, Integer interestPostEvery, final ReccuringDepositInterestCalculator reccuringDepositInterestCalculator,
Integer interestPostFrequency) { final DepositLifecycleStateMachine lifecycleStateMachine, final Integer depositEvery, final Integer interestPostEvery,
final Integer interestPostFrequency) {
Money futureValueOnMaturity = null; Money futureValueOnMaturity = null;
if (savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod()) { if (savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod()) {
futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure, futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure,
reccuringInterestRate, commencementDate, tenureTypeEnum, savingFrequencyType, savingInterestCalculationMethod, reccuringInterestRate, savingFrequencyType, savingInterestCalculationMethod, depositEvery);
depositEvery);
} else if (savingProductType.isReccuring() && tenureTypeEnum.isPerpetual()) { } else if (savingProductType.isReccuring() && tenureTypeEnum.isPerpetual()) {
futureValueOnMaturity = savingsDeposit; futureValueOnMaturity = savingsDeposit;
} else { } else {
@@ -223,12 +223,14 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
interestPostEvery, interestPostFrequency); interestPostEvery, interestPostFrequency);
} }
public SavingAccount(Client client, String externalId, SavingProduct product, Money savingsDeposit, BigDecimal reccuringInterestRate, public SavingAccount(final Client client, final String externalId, final SavingProduct product, final Money savingsDeposit,
BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate, TenureTypeEnum tenureTypeEnum, final BigDecimal reccuringInterestRate, final BigDecimal savingInterestRate, final Integer tenure,
SavingProductType savingProductType, SavingFrequencyType savingFrequencyType, SavingsInterestType interestType, final LocalDate commencementDate, final TenureTypeEnum tenureTypeEnum, final SavingProductType savingProductType,
SavingInterestCalculationMethod savingInterestCalculationMethod, boolean isLockinPeriodAllowed, Integer lockinPeriod, final SavingFrequencyType savingFrequencyType, final SavingsInterestType interestType,
PeriodFrequencyType lockinPeriodType, Money futureValueOnMaturity, final DepositLifecycleStateMachine lifecycleStateMachine, final SavingInterestCalculationMethod savingInterestCalculationMethod, final boolean isLockinPeriodAllowed,
Integer payEvery, Integer interestPostEvery, Integer interestPostFrequency) { final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType, final Money futureValueOnMaturity,
final DepositLifecycleStateMachine lifecycleStateMachine, final Integer payEvery, final Integer interestPostEvery,
final Integer interestPostFrequency) {
DepositAccountStatus from = null; DepositAccountStatus from = null;
if (accountStatus != null) { if (accountStatus != null) {
@@ -274,18 +276,18 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
this.interestPostFrequency = interestPostFrequency; this.interestPostFrequency = interestPostFrequency;
} }
public void modifyAccount(SavingProduct product, String externalId, Money savingsDeposit, BigDecimal reccuringInterestRate, public void modifyAccount(final SavingProduct product, final String externalId, final Money savingsDeposit,
BigDecimal savingInterestRate, Integer tenure, LocalDate commencementDate, TenureTypeEnum tenureTypeEnum, final BigDecimal reccuringInterestRate, final BigDecimal savingInterestRate, final Integer tenure,
SavingProductType savingProductType, SavingFrequencyType savingFrequencyType, final LocalDate commencementDate, final TenureTypeEnum tenureTypeEnum, final SavingProductType savingProductType,
SavingInterestCalculationMethod savingInterestCalculationMethod, boolean isLockinPeriodAllowed, Integer lockinPeriod, final SavingFrequencyType savingFrequencyType, final SavingInterestCalculationMethod savingInterestCalculationMethod,
PeriodFrequencyType lockinPeriodType, ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, Integer payEvery, final boolean isLockinPeriodAllowed, final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType,
SavingsInterestType interestType, Integer interestPostEvery, Integer interestPostFrequency) { final ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, final Integer payEvery,
final SavingsInterestType interestType, final Integer interestPostEvery, final Integer interestPostFrequency) {
Money futureValueOnMaturity = null; Money futureValueOnMaturity = null;
if (savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod()) { if (savingProductType.isReccuring() && tenureTypeEnum.isFixedPeriod()) {
futureValueOnMaturity = reccuringDepositInterestCalculator futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsDeposit, tenure,
.calculateInterestOnMaturityFor(savingsDeposit, tenure, reccuringInterestRate, commencementDate, tenureTypeEnum, reccuringInterestRate, savingFrequencyType, savingInterestCalculationMethod, payEvery);
savingFrequencyType, savingInterestCalculationMethod, payEvery);
} else if (savingProductType.isReccuring() && tenureTypeEnum.isPerpetual()) { } else if (savingProductType.isReccuring() && tenureTypeEnum.isPerpetual()) {
futureValueOnMaturity = savingsDeposit; futureValueOnMaturity = savingsDeposit;
} else { } else {
@@ -432,7 +434,7 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
this.savingScheduleInstallments.add(installment); this.savingScheduleInstallments.add(installment);
} }
public void reject(LocalDate rejectedOn, DepositLifecycleStateMachine depositLifecycleStateMachine) { public void reject(final LocalDate rejectedOn, final DepositLifecycleStateMachine depositLifecycleStateMachine) {
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_REJECTED, DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_REJECTED,
DepositAccountStatus.fromInt(this.accountStatus)); DepositAccountStatus.fromInt(this.accountStatus));
@@ -467,7 +469,7 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
return date; return date;
} }
public void withdrawnByApplicant(LocalDate withdrawnOn, DepositLifecycleStateMachine depositLifecycleStateMachine) { public void withdrawnByApplicant(final LocalDate withdrawnOn, final DepositLifecycleStateMachine depositLifecycleStateMachine) {
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_WITHDRAWN, DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_WITHDRAWN,
DepositAccountStatus.fromInt(this.accountStatus)); DepositAccountStatus.fromInt(this.accountStatus));
@@ -493,7 +495,7 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
} }
} }
public void undoSavingAccountApproval(DepositLifecycleStateMachine depositLifecycleStateMachine) { public void undoSavingAccountApproval(final DepositLifecycleStateMachine depositLifecycleStateMachine) {
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVAL_UNDO, DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVAL_UNDO,
DepositAccountStatus.fromInt(this.accountStatus)); DepositAccountStatus.fromInt(this.accountStatus));
this.accountStatus = statusEnum.getValue(); this.accountStatus = statusEnum.getValue();
@@ -501,10 +503,12 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
this.closedOnDate = new Date(); this.closedOnDate = new Date();
} }
public void approveSavingAccount(LocalDate approvalDate, BigDecimal savingsDepositAmountPerPeriod, BigDecimal recurringInterestRate, public void approveSavingAccount(final LocalDate approvalDate, final BigDecimal savingsDepositAmountPerPeriod,
BigDecimal savingInterestRate, Integer interestType, Integer tenure, Integer tenureType, Integer frequency, Integer payEvery, final BigDecimal recurringInterestRate, final BigDecimal savingInterestRate, final Integer interestType, final Integer tenure,
DepositLifecycleStateMachine depositLifecycleStateMachine, final Integer tenureType, final Integer frequency, final Integer payEvery,
ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, Integer interestPostEvery, Integer interestPostFrequency) { final DepositLifecycleStateMachine depositLifecycleStateMachine,
final ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, final Integer interestPostEvery,
final Integer interestPostFrequency) {
DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVED, DepositAccountStatus statusEnum = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_APPROVED,
DepositAccountStatus.fromInt(this.accountStatus)); DepositAccountStatus.fromInt(this.accountStatus));
@@ -518,7 +522,7 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
Money futureValueOnMaturity = null; Money futureValueOnMaturity = null;
if (SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isFixedPeriod()) { if (SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isFixedPeriod()) {
futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsAmountPerPeriod, tenure, futureValueOnMaturity = reccuringDepositInterestCalculator.calculateInterestOnMaturityFor(savingsAmountPerPeriod, tenure,
recurringInterestRate, approvalDate, tenureTypeEnum, savingFrequencyType, interestCalculationMethod, payEvery); recurringInterestRate, savingFrequencyType, interestCalculationMethod, payEvery);
} else if (SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isPerpetual()) { } else if (SavingProductType.fromInt(this.savingProductType).isReccuring() && tenureTypeEnum.isPerpetual()) {
futureValueOnMaturity = savingsAmountPerPeriod; futureValueOnMaturity = savingsAmountPerPeriod;
} else { } else {
@@ -552,7 +556,7 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
this.interestPostedAmount = BigDecimal.ZERO; this.interestPostedAmount = BigDecimal.ZERO;
} }
public void depositMoney(SavingAccountDepositCommand command) { public void depositMoney(final SavingAccountDepositCommand command) {
BigDecimal depositAmount = BigDecimal.ZERO; BigDecimal depositAmount = BigDecimal.ZERO;
BigDecimal remainAmountToBePaid = BigDecimal.ZERO; BigDecimal remainAmountToBePaid = BigDecimal.ZERO;
@@ -600,7 +604,7 @@ public class SavingAccount extends AbstractAuditableCustom<AppUser, Long> {
return DepositAccountStatus.fromInt(this.accountStatus).isActive(); return DepositAccountStatus.fromInt(this.accountStatus).isActive();
} }
public void withdrawAmount(BigDecimal amount, LocalDate transactionDate) { public void withdrawAmount(final BigDecimal amount, final LocalDate transactionDate) {
this.outstandingAmount = this.outstandingAmount.subtract(amount); this.outstandingAmount = this.outstandingAmount.subtract(amount);
SavingAccountTransaction savingAccountTransaction = SavingAccountTransaction.withdraw(amount, transactionDate); SavingAccountTransaction savingAccountTransaction = SavingAccountTransaction.withdraw(amount, transactionDate);
savingAccountTransaction.updateAccount(this); savingAccountTransaction.updateAccount(this);
@@ -27,11 +27,11 @@ import org.mifosplatform.useradministration.domain.AppUser;
@Table(name = "m_saving_account_transaction") @Table(name = "m_saving_account_transaction")
public class SavingAccountTransaction extends AbstractAuditableCustom<AppUser, Long> { public class SavingAccountTransaction extends AbstractAuditableCustom<AppUser, Long> {
@SuppressWarnings("unused")
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "saving_account_id", nullable = false) @JoinColumn(name = "saving_account_id", nullable = false)
private SavingAccount savingAccount; private SavingAccount savingAccount;
// @Enumerated(EnumType.ORDINAL)
@Column(name = "transaction_type_enum", nullable = false) @Column(name = "transaction_type_enum", nullable = false)
private Integer typeOf; private Integer typeOf;
@@ -48,47 +48,49 @@ public class SavingAccountTransaction extends AbstractAuditableCustom<AppUser, L
private final BigDecimal amount; private final BigDecimal amount;
public SavingAccountTransaction() { public SavingAccountTransaction() {
this.transactionDate = null; this.transactionDate = null;
this.amount = BigDecimal.ZERO; this.amount = BigDecimal.ZERO;
} }
public SavingAccountTransaction(DepositAccountTransactionType transactionType, BigDecimal amount, LocalDate paymentDate) { public SavingAccountTransaction(final DepositAccountTransactionType transactionType, final BigDecimal amount,
this.typeOf = transactionType.getValue(); final LocalDate paymentDate) {
this.amount = amount; this.typeOf = transactionType.getValue();
this.transactionDate =paymentDate.toDate(); this.amount = amount;
} this.transactionDate = paymentDate.toDate();
}
public static SavingAccountTransaction deposit(BigDecimal amount, LocalDate paymentDate) { public static SavingAccountTransaction deposit(final BigDecimal amount, final LocalDate paymentDate) {
return new SavingAccountTransaction(DepositAccountTransactionType.DEPOSIT, amount == null ? new BigDecimal(0) : amount, paymentDate); return new SavingAccountTransaction(DepositAccountTransactionType.DEPOSIT, amount == null ? new BigDecimal(0) : amount, paymentDate);
} }
public static SavingAccountTransaction withdraw(BigDecimal amount, LocalDate paymentDate) { public static SavingAccountTransaction withdraw(final BigDecimal amount, final LocalDate paymentDate) {
return new SavingAccountTransaction(DepositAccountTransactionType.WITHDRAW, amount == null ? new BigDecimal(0) : amount, paymentDate); return new SavingAccountTransaction(DepositAccountTransactionType.WITHDRAW, amount == null ? new BigDecimal(0) : amount,
} paymentDate);
}
public static SavingAccountTransaction postInterest(BigDecimal amount, LocalDate paymentDate) { public static SavingAccountTransaction postInterest(final BigDecimal amount, final LocalDate paymentDate) {
return new SavingAccountTransaction(DepositAccountTransactionType.INTEREST_POSTING, amount == null ? new BigDecimal(0) : amount, paymentDate); return new SavingAccountTransaction(DepositAccountTransactionType.INTEREST_POSTING, amount == null ? new BigDecimal(0) : amount,
} paymentDate);
}
public void updateAccount(SavingAccount savingAccount) { public void updateAccount(final SavingAccount savingAccount) {
this.savingAccount = savingAccount; this.savingAccount = savingAccount;
} }
public DepositAccountTransactionType getTypeOf() { public DepositAccountTransactionType getTypeOf() {
return DepositAccountTransactionType.fromInt(this.typeOf); return DepositAccountTransactionType.fromInt(this.typeOf);
} }
public BigDecimal getAmount() { public BigDecimal getAmount() {
return this.amount; return this.amount;
} }
public LocalDate getTransactionDate() {
LocalDate transactionDate = null;
if(this.transactionDate != null){
transactionDate = new LocalDate(this.transactionDate);
}
return transactionDate;
}
public LocalDate getTransactionDate() {
LocalDate transactionDate = null;
if (this.transactionDate != null) {
transactionDate = new LocalDate(this.transactionDate);
}
return transactionDate;
}
} }
@@ -48,7 +48,8 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
@Autowired @Autowired
public SavingAccountReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource, public SavingAccountReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource,
ClientReadPlatformService clientReadPlatformService, SavingProductReadPlatformService savingProductReadPlatformService) { final ClientReadPlatformService clientReadPlatformService,
final SavingProductReadPlatformService savingProductReadPlatformService) {
this.context = context; this.context = context;
this.jdbcTemplate = new JdbcTemplate(dataSource); this.jdbcTemplate = new JdbcTemplate(dataSource);
this.clientReadPlatformService = clientReadPlatformService; this.clientReadPlatformService = clientReadPlatformService;
@@ -66,7 +67,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
} }
@Override @Override
public SavingAccountData retrieveSavingsAccount(Long accountId) { public SavingAccountData retrieveSavingsAccount(final Long accountId) {
this.context.authenticatedUser(); this.context.authenticatedUser();
SavingAccountMapper mapper = new SavingAccountMapper(); SavingAccountMapper mapper = new SavingAccountMapper();
@@ -100,7 +101,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
} }
@Override @Override
public SavingAccountData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException { public SavingAccountData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
Long id = rs.getLong("id"); Long id = rs.getLong("id");
String externalId = rs.getString("externalId"); String externalId = rs.getString("externalId");
@@ -174,7 +175,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
} }
@Override @Override
public SavingAccountData retrieveNewSavingsAccountDetails(Long clientId, Long productId) { public SavingAccountData retrieveNewSavingsAccountDetails(final Long clientId, final Long productId) {
context.authenticatedUser(); context.authenticatedUser();
ClientData clientAccount = this.clientReadPlatformService.retrieveIndividualClient(clientId); ClientData clientAccount = this.clientReadPlatformService.retrieveIndividualClient(clientId);
@@ -190,9 +191,8 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
selectedProduct.getName(), currency, selectedProduct.getInterestRate(), selectedProduct.getSavingsDepositAmount(), selectedProduct.getName(), currency, selectedProduct.getInterestRate(), selectedProduct.getSavingsDepositAmount(),
selectedProduct.getSavingProductType(), selectedProduct.getTenureType(), selectedProduct.getTenure(), selectedProduct.getSavingProductType(), selectedProduct.getTenureType(), selectedProduct.getTenure(),
selectedProduct.getSavingFrequencyType(), selectedProduct.getInterestType(), selectedProduct.getSavingFrequencyType(), selectedProduct.getInterestType(),
selectedProduct.getInterestCalculationMethod(), selectedProduct.getMinimumBalanceForWithdrawal(), selectedProduct.getInterestCalculationMethod(), selectedProduct.isLockinPeriodAllowed(),
selectedProduct.isPartialDepositAllowed(), selectedProduct.isLockinPeriodAllowed(), selectedProduct.getLockinPeriod(), selectedProduct.getLockinPeriod(), selectedProduct.getLockinPeriodType(), selectedProduct.getDepositEvery());
selectedProduct.getLockinPeriodType(), selectedProduct.getDepositEvery());
} else { } else {
accountData = SavingAccountData.createFrom(clientAccount.id(), clientAccount.displayName()); accountData = SavingAccountData.createFrom(clientAccount.id(), clientAccount.displayName());
@@ -200,7 +200,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
return accountData; return accountData;
} }
private SavingProductData findSavingProductById(Collection<SavingProductLookup> savingProducts, Long productId) { private SavingProductData findSavingProductById(final Collection<SavingProductLookup> savingProducts, final Long productId) {
SavingProductData match = this.savingProductReadPlatformService.retrieveNewSavingProductDetails(); SavingProductData match = this.savingProductReadPlatformService.retrieveNewSavingProductDetails();
for (SavingProductLookup savingProductLookup : savingProducts) { for (SavingProductLookup savingProductLookup : savingProducts) {
if (savingProductLookup.hasId(productId)) { if (savingProductLookup.hasId(productId)) {
@@ -212,7 +212,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
} }
@Override @Override
public SavingPermissionData retrieveSavingAccountPermissions(SavingAccountData savingAccountData) { public SavingPermissionData retrieveSavingAccountPermissions(final SavingAccountData savingAccountData) {
boolean pendingApproval = (savingAccountData.getStatus().getId().equals(100L)); boolean pendingApproval = (savingAccountData.getStatus().getId().equals(100L));
boolean undoApprovalAllowed = (savingAccountData.getStatus().getId().equals(300L)); boolean undoApprovalAllowed = (savingAccountData.getStatus().getId().equals(300L));
boolean renewelAllowed = false; boolean renewelAllowed = false;
@@ -230,7 +230,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Override @Override
public BigDecimal deriveSavingDueAmount(SavingAccountData account) { public BigDecimal deriveSavingDueAmount(final SavingAccountData account) {
BigDecimal dueAmount = BigDecimal.ZERO; BigDecimal dueAmount = BigDecimal.ZERO;
EnumOptionData status = account.getStatus(); EnumOptionData status = account.getStatus();
@@ -254,7 +254,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
} }
@Override @Override
public SavingScheduleData retrieveSavingsAccountSchedule(Long accountId, CurrencyData currency) { public SavingScheduleData retrieveSavingsAccountSchedule(final Long accountId, final CurrencyData currency) {
this.context.authenticatedUser(); this.context.authenticatedUser();
SavingAccountScheduleMapper mapper = new SavingAccountScheduleMapper(); SavingAccountScheduleMapper mapper = new SavingAccountScheduleMapper();
String sql = "Select " + mapper.savingScheduleSchema() + " where ss.saving_account_id =? order by ss.installment"; String sql = "Select " + mapper.savingScheduleSchema() + " where ss.saving_account_id =? order by ss.installment";
@@ -281,7 +281,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
} }
@Override @Override
public SavingSchedulePeriodData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException { public SavingSchedulePeriodData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
LocalDate dueDate = JdbcSupport.getLocalDate(rs, "dueDate"); LocalDate dueDate = JdbcSupport.getLocalDate(rs, "dueDate");
Integer installment = JdbcSupport.getInteger(rs, "installment"); Integer installment = JdbcSupport.getInteger(rs, "installment");
@@ -308,7 +308,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
} }
@Override @Override
public SavingAccountForLookup mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException { public SavingAccountForLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
Long id = rs.getLong("id"); Long id = rs.getLong("id");
return new SavingAccountForLookup(id); return new SavingAccountForLookup(id);
} }
@@ -316,7 +316,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
} }
@Override @Override
public Collection<SavingAccountTransactionsData> retrieveSavingsAccountTransactions(Long accountId) { public Collection<SavingAccountTransactionsData> retrieveSavingsAccountTransactions(final Long accountId) {
this.context.authenticatedUser(); this.context.authenticatedUser();
SavingAccountTransactionMapper savingAccountTransactionMapper = new SavingAccountTransactionMapper(); SavingAccountTransactionMapper savingAccountTransactionMapper = new SavingAccountTransactionMapper();
String sql = "select " + savingAccountTransactionMapper.schema() + " where stxn.saving_account_id = ? "; String sql = "select " + savingAccountTransactionMapper.schema() + " where stxn.saving_account_id = ? ";
@@ -330,7 +330,7 @@ public class SavingAccountReadPlatformServiceImpl implements SavingAccountReadPl
} }
@Override @Override
public SavingAccountTransactionsData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException { public SavingAccountTransactionsData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
Long id = rs.getLong("id"); Long id = rs.getLong("id");
LocalDate transactionDate = JdbcSupport.getLocalDate(rs, "transactionDate"); LocalDate transactionDate = JdbcSupport.getLocalDate(rs, "transactionDate");
Integer transactionTypeValue = JdbcSupport.getInteger(rs, "type"); Integer transactionTypeValue = JdbcSupport.getInteger(rs, "type");
@@ -562,14 +562,14 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
return date; return date;
} }
public void updateAccount(DepositAccount account) { public void updateAccount(final DepositAccount account) {
this.renewdAccount = account; this.renewdAccount = account;
} }
public void withdrawDepositAccountMoney(DepositLifecycleStateMachine depositLifecycleStateMachine, public void withdrawDepositAccountMoney(final DepositLifecycleStateMachine depositLifecycleStateMachine,
FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, LocalDate eventDate) { final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, final LocalDate eventDate) {
if (eventDate.isBefore(getLastInterestPostedDate())) { if (eventDate.isBefore(getLastInterestPostedDate())) {
final String errorMessage = "Deposit Account Preclosed date \"" + eventDate + "\"cannot before last interest posted date \"" final String errorMessage = "Deposit Account Preclosed date \"" + eventDate + "\"cannot before last interest posted date \""
@@ -647,7 +647,7 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
* } * }
*/ */
public void withdrawInterest(Money interest) { public void withdrawInterest(final Money interest) {
@SuppressWarnings("unused") @SuppressWarnings("unused")
boolean statustest = isActive(); boolean statustest = isActive();
if (isActive()) { if (isActive()) {
@@ -662,7 +662,7 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
} }
public void closeDepositAccount(DepositLifecycleStateMachine depositLifecycleStateMachine) { public void closeDepositAccount(final DepositLifecycleStateMachine depositLifecycleStateMachine) {
DepositAccountStatus statusEnumForClose = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_CLOSED, DepositAccountStatus statusEnumForClose = depositLifecycleStateMachine.transition(DepositAccountEvent.DEPOSIT_CLOSED,
DepositAccountStatus.fromInt(this.depositStatus)); DepositAccountStatus.fromInt(this.depositStatus));
this.depositStatus = statusEnumForClose.getValue(); this.depositStatus = statusEnumForClose.getValue();
@@ -732,7 +732,7 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
return DepositAccountStatus.fromInt(this.depositStatus).isActive(); return DepositAccountStatus.fromInt(this.depositStatus).isActive();
} }
public void postInterestForDepositAccount(DepositAccount account, FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator) { public void postInterestForDepositAccount(final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator) {
LocalDate lastInterestPostedDate = getLastInterestPostedDate(); LocalDate lastInterestPostedDate = getLastInterestPostedDate();
LocalDate nextInterestPostingDate = getNextInterestPostedDate(); LocalDate nextInterestPostingDate = getNextInterestPostedDate();
@@ -57,25 +57,30 @@ public class DepositAccountAssembler {
} }
public DepositAccount assembleFrom(final JsonCommand command) { public DepositAccount assembleFrom(final JsonCommand command) {
final JsonElement element = command.parsedJson(); final JsonElement element = command.parsedJson();
final Long clientId = fromApiJsonHelper.extractLongNamed("clientId", element); final Long clientId = fromApiJsonHelper.extractLongNamed("clientId", element);
final Long productId = fromApiJsonHelper.extractLongNamed("productId", element); final Long productId = fromApiJsonHelper.extractLongNamed("productId", element);
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element); final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element);
final Boolean isInterestWithdrawable = fromApiJsonHelper.extractBooleanNamed("isInterestWithdrawable", element); final Boolean isInterestWithdrawable = fromApiJsonHelper.extractBooleanNamed("isInterestWithdrawable", element);
final BigDecimal depositValue = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("deposit", element); final BigDecimal depositValue = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("deposit", element);
final Integer tenureInMonthsCommandValue = fromApiJsonHelper.extractIntegerNamed("tenureInMonths", element, Locale.getDefault()); final Integer tenureInMonthsCommandValue = fromApiJsonHelper.extractIntegerNamed("tenureInMonths", element, Locale.getDefault());
final BigDecimal maturityInterestRateCommandValue = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityInterestRate", element); final BigDecimal maturityInterestRateCommandValue = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maturityInterestRate",
final BigDecimal preClosureInterestRateCommandValue = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("preClosureInterestRate", element); element);
final Integer interestCompoundedEveryCommandValue = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEvery", element, Locale.getDefault()); final BigDecimal preClosureInterestRateCommandValue = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("preClosureInterestRate",
final Integer interestCompoundedEveryPeriodTypeCommandValue = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEveryPeriodType", element, Locale.getDefault()); element);
final Boolean renewalAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("renewalAllowed", element); final Integer interestCompoundedEveryCommandValue = fromApiJsonHelper.extractIntegerNamed("interestCompoundedEvery", element,
final Boolean preClosureAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("preClosureAllowed", element); Locale.getDefault());
final Boolean interestCompoundingAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("interestCompoundingAllowed", element); final Integer interestCompoundedEveryPeriodTypeCommandValue = fromApiJsonHelper.extractIntegerNamed(
final Boolean isLockinPeriodAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element); "interestCompoundedEveryPeriodType", element, Locale.getDefault());
final Integer lockinPeriodCommandValue = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault()); final Boolean renewalAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("renewalAllowed", element);
final Integer lockinPeriodTypeCommandValue = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault()); final Boolean preClosureAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("preClosureAllowed", element);
final LocalDate commencementDate = fromApiJsonHelper.extractLocalDateNamed("commencementDate", element); final Boolean interestCompoundingAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("interestCompoundingAllowed", element);
final Boolean isLockinPeriodAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element);
final Integer lockinPeriodCommandValue = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault());
final Integer lockinPeriodTypeCommandValue = fromApiJsonHelper
.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault());
final LocalDate commencementDate = fromApiJsonHelper.extractLocalDateNamed("commencementDate", element);
Client client = this.clientRepository.findOne(clientId); Client client = this.clientRepository.findOne(clientId);
if (client == null || client.isDeleted()) { throw new ClientNotFoundException(clientId); } if (client == null || client.isDeleted()) { throw new ClientNotFoundException(clientId); }
@@ -147,10 +152,9 @@ public class DepositAccountAssembler {
// end of details allowed to be overriden from product // end of details allowed to be overriden from product
DepositAccount account = new DepositAccount().openNew(client, product, externalId, deposit, maturityInterestRate, DepositAccount account = new DepositAccount().openNew(client, product, externalId, deposit, maturityInterestRate,
preClosureInterestRate, tenureInMonths, compoundingInterestEvery, compoundingInterestFrequency, preClosureInterestRate, tenureInMonths, compoundingInterestEvery, compoundingInterestFrequency, commencementDate,
commencementDate, renewalAllowed, preClosureAllowed, this.fixedTermDepositInterestCalculator, renewalAllowed, preClosureAllowed, this.fixedTermDepositInterestCalculator, defaultDepositLifecycleStateMachine(),
defaultDepositLifecycleStateMachine(), isInterestWithdrawable, interestCompoundingAllowed, isLockinPeriodAllowed, isInterestWithdrawable, interestCompoundingAllowed, isLockinPeriodAllowed, lockinPeriod, lockinPeriodType);
lockinPeriod, lockinPeriodType);
return account; return account;
} }
@@ -160,10 +164,10 @@ public class DepositAccountAssembler {
return new DepositLifecycleStateMachineImpl(allowedDepositStatuses); return new DepositLifecycleStateMachineImpl(allowedDepositStatuses);
} }
public DepositAccount assembleFrom(DepositAccount account, JsonCommand command) { public DepositAccount assembleFrom(final DepositAccount account, final JsonCommand command) {
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20); final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20);
final String localeAsInput = command.locale(); final String localeAsInput = command.locale();
Client client = account.client(); Client client = account.client();
@@ -229,7 +233,8 @@ public class DepositAccountAssembler {
PeriodFrequencyType interestCompoundedEveryPeriodType = account.getInterestCompoundedFrequencyType(); PeriodFrequencyType interestCompoundedEveryPeriodType = account.getInterestCompoundedFrequencyType();
final String interestCompoundedEveryPeriodTypeParamName = "interestCompoundedEveryPeriodType"; final String interestCompoundedEveryPeriodTypeParamName = "interestCompoundedEveryPeriodType";
if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryPeriodTypeParamName, interestCompoundedEveryPeriodType.getValue())) { if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryPeriodTypeParamName,
interestCompoundedEveryPeriodType.getValue())) {
final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryPeriodTypeParamName); final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryPeriodTypeParamName);
actualChanges.put(interestCompoundedEveryPeriodTypeParamName, newValue); actualChanges.put(interestCompoundedEveryPeriodTypeParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
@@ -239,7 +244,7 @@ public class DepositAccountAssembler {
Boolean renewalAllowed = account.isRenewalAllowed(); Boolean renewalAllowed = account.isRenewalAllowed();
final String renewalAllowedParamName = "renewalAllowed"; final String renewalAllowedParamName = "renewalAllowed";
if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, renewalAllowed)) { if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, renewalAllowed)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName);
actualChanges.put(renewalAllowedParamName, newValue); actualChanges.put(renewalAllowedParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
renewalAllowed = newValue; renewalAllowed = newValue;
@@ -248,7 +253,7 @@ public class DepositAccountAssembler {
Boolean preClosureAllowed = account.isPreClosureAllowed(); Boolean preClosureAllowed = account.isPreClosureAllowed();
final String preClosureAllowedParamName = "preClosureAllowed"; final String preClosureAllowedParamName = "preClosureAllowed";
if (command.isChangeInBooleanParameterNamed(preClosureAllowedParamName, preClosureAllowed)) { if (command.isChangeInBooleanParameterNamed(preClosureAllowedParamName, preClosureAllowed)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName);
actualChanges.put(preClosureAllowedParamName, newValue); actualChanges.put(preClosureAllowedParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
preClosureAllowed = newValue; preClosureAllowed = newValue;
@@ -257,7 +262,7 @@ public class DepositAccountAssembler {
Boolean isInterestWithdrawable = account.isInterestWithdrawable(); Boolean isInterestWithdrawable = account.isInterestWithdrawable();
final String isInterestWithdrawableParamName = "isInterestWithdrawable"; final String isInterestWithdrawableParamName = "isInterestWithdrawable";
if (command.isChangeInBooleanParameterNamed(isInterestWithdrawableParamName, isInterestWithdrawable)) { if (command.isChangeInBooleanParameterNamed(isInterestWithdrawableParamName, isInterestWithdrawable)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName);
actualChanges.put(isInterestWithdrawableParamName, newValue); actualChanges.put(isInterestWithdrawableParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
isInterestWithdrawable = newValue; isInterestWithdrawable = newValue;
@@ -266,7 +271,7 @@ public class DepositAccountAssembler {
Boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed(); Boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed();
final String isInterestCompoundingAllowedParamName = "interestCompoundingAllowed"; final String isInterestCompoundingAllowedParamName = "interestCompoundingAllowed";
if (command.isChangeInBooleanParameterNamed(isInterestCompoundingAllowedParamName, isInterestCompoundingAllowed)) { if (command.isChangeInBooleanParameterNamed(isInterestCompoundingAllowedParamName, isInterestCompoundingAllowed)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestCompoundingAllowedParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestCompoundingAllowedParamName);
actualChanges.put(isInterestCompoundingAllowedParamName, newValue); actualChanges.put(isInterestCompoundingAllowedParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
isInterestCompoundingAllowed = newValue; isInterestCompoundingAllowed = newValue;
@@ -275,14 +280,14 @@ public class DepositAccountAssembler {
Boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed(); Boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed();
final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed"; final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed";
if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, isLockinPeriodAllowed)) { if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, isLockinPeriodAllowed)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName);
actualChanges.put(isLockinPeriodAllowedParamName, newValue); actualChanges.put(isLockinPeriodAllowedParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
isLockinPeriodAllowed = newValue; isLockinPeriodAllowed = newValue;
} }
Integer lockinPeriod = account.getLockinPeriod(); Integer lockinPeriod = account.getLockinPeriod();
final String lockinPeriodParamName = "lockinPeriod"; final String lockinPeriodParamName = "lockinPeriod";
if (command.isChangeInIntegerParameterNamed(lockinPeriodParamName, lockinPeriod)) { if (command.isChangeInIntegerParameterNamed(lockinPeriodParamName, lockinPeriod)) {
final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodParamName); final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodParamName);
actualChanges.put(lockinPeriodParamName, newValue); actualChanges.put(lockinPeriodParamName, newValue);
@@ -291,7 +296,7 @@ public class DepositAccountAssembler {
} }
PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType(); PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType();
final String lockinPeriodTypeParamName = "lockinPeriodType"; final String lockinPeriodTypeParamName = "lockinPeriodType";
if (command.isChangeInIntegerParameterNamed(lockinPeriodTypeParamName, lockinPeriodType.getValue())) { if (command.isChangeInIntegerParameterNamed(lockinPeriodTypeParamName, lockinPeriodType.getValue())) {
final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodTypeParamName); final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodTypeParamName);
actualChanges.put(lockinPeriodTypeParamName, newValue); actualChanges.put(lockinPeriodTypeParamName, newValue);
@@ -310,13 +315,13 @@ public class DepositAccountAssembler {
return newAccount; return newAccount;
} }
public Map<String, Object> assembleUpdatedDepositAccount(DepositAccount account, JsonCommand command) { public Map<String, Object> assembleUpdatedDepositAccount(final DepositAccount account, final JsonCommand command) {
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20); final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20);
final String localeAsInput = command.locale(); final String localeAsInput = command.locale();
DepositProduct product = account.product(); DepositProduct product = account.product();
final String productIdParamName = "productId"; final String productIdParamName = "productId";
if (command.isChangeInLongParameterNamed(productIdParamName, account.product().getId())) { if (command.isChangeInLongParameterNamed(productIdParamName, account.product().getId())) {
final Long newValue = command.longValueOfParameterNamed(productIdParamName); final Long newValue = command.longValueOfParameterNamed(productIdParamName);
if (newValue != null) { if (newValue != null) {
@@ -338,10 +343,10 @@ public class DepositAccountAssembler {
LocalDate commencementDate = account.getProjectedCommencementDate(); LocalDate commencementDate = account.getProjectedCommencementDate();
final String commencementDateParamName = "commencementDate"; final String commencementDateParamName = "commencementDate";
if (command.isChangeInLocalDateParameterNamed("commencementDate", commencementDate)) { if (command.isChangeInLocalDateParameterNamed("commencementDate", commencementDate)) {
final LocalDate newValue = command.localDateValueOfParameterNamed(commencementDateParamName); final LocalDate newValue = command.localDateValueOfParameterNamed(commencementDateParamName);
actualChanges.put(commencementDateParamName, newValue); actualChanges.put(commencementDateParamName, newValue);
commencementDate = newValue; commencementDate = newValue;
} }
Money deposit = account.getDeposit(); Money deposit = account.getDeposit();
final String depositParamName = "deposit"; final String depositParamName = "deposit";
@@ -393,7 +398,8 @@ public class DepositAccountAssembler {
PeriodFrequencyType interestCompoundedEveryPeriodType = account.getInterestCompoundedFrequencyType(); PeriodFrequencyType interestCompoundedEveryPeriodType = account.getInterestCompoundedFrequencyType();
final String interestCompoundedEveryPeriodTypeParamName = "interestCompoundedEveryPeriodType"; final String interestCompoundedEveryPeriodTypeParamName = "interestCompoundedEveryPeriodType";
if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryPeriodTypeParamName, interestCompoundedEveryPeriodType.getValue())) { if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryPeriodTypeParamName,
interestCompoundedEveryPeriodType.getValue())) {
final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryPeriodTypeParamName); final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryPeriodTypeParamName);
actualChanges.put(interestCompoundedEveryPeriodTypeParamName, newValue); actualChanges.put(interestCompoundedEveryPeriodTypeParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
@@ -403,7 +409,7 @@ public class DepositAccountAssembler {
Boolean renewalAllowed = account.isRenewalAllowed(); Boolean renewalAllowed = account.isRenewalAllowed();
final String renewalAllowedParamName = "renewalAllowed"; final String renewalAllowedParamName = "renewalAllowed";
if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, renewalAllowed)) { if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, renewalAllowed)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName);
actualChanges.put(renewalAllowedParamName, newValue); actualChanges.put(renewalAllowedParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
renewalAllowed = newValue; renewalAllowed = newValue;
@@ -412,7 +418,7 @@ public class DepositAccountAssembler {
Boolean preClosureAllowed = account.isPreClosureAllowed(); Boolean preClosureAllowed = account.isPreClosureAllowed();
final String preClosureAllowedParamName = "preClosureAllowed"; final String preClosureAllowedParamName = "preClosureAllowed";
if (command.isChangeInBooleanParameterNamed(preClosureAllowedParamName, preClosureAllowed)) { if (command.isChangeInBooleanParameterNamed(preClosureAllowedParamName, preClosureAllowed)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName);
actualChanges.put(preClosureAllowedParamName, newValue); actualChanges.put(preClosureAllowedParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
preClosureAllowed = newValue; preClosureAllowed = newValue;
@@ -421,7 +427,7 @@ public class DepositAccountAssembler {
Boolean isInterestWithdrawable = account.isInterestWithdrawable(); Boolean isInterestWithdrawable = account.isInterestWithdrawable();
final String isInterestWithdrawableParamName = "isInterestWithdrawable"; final String isInterestWithdrawableParamName = "isInterestWithdrawable";
if (command.isChangeInBooleanParameterNamed(isInterestWithdrawableParamName, isInterestWithdrawable)) { if (command.isChangeInBooleanParameterNamed(isInterestWithdrawableParamName, isInterestWithdrawable)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName);
actualChanges.put(isInterestWithdrawableParamName, newValue); actualChanges.put(isInterestWithdrawableParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
isInterestWithdrawable = newValue; isInterestWithdrawable = newValue;
@@ -430,7 +436,7 @@ public class DepositAccountAssembler {
Boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed(); Boolean isInterestCompoundingAllowed = account.isInterestCompoundingAllowed();
final String isInterestCompoundingAllowedParamName = "interestCompoundingAllowed"; final String isInterestCompoundingAllowedParamName = "interestCompoundingAllowed";
if (command.isChangeInBooleanParameterNamed(isInterestCompoundingAllowedParamName, isInterestCompoundingAllowed)) { if (command.isChangeInBooleanParameterNamed(isInterestCompoundingAllowedParamName, isInterestCompoundingAllowed)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestCompoundingAllowedParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestCompoundingAllowedParamName);
actualChanges.put(isInterestCompoundingAllowedParamName, newValue); actualChanges.put(isInterestCompoundingAllowedParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
isInterestCompoundingAllowed = newValue; isInterestCompoundingAllowed = newValue;
@@ -439,14 +445,14 @@ public class DepositAccountAssembler {
Boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed(); Boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed();
final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed"; final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed";
if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, isLockinPeriodAllowed)) { if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, isLockinPeriodAllowed)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName);
actualChanges.put(isLockinPeriodAllowedParamName, newValue); actualChanges.put(isLockinPeriodAllowedParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
isLockinPeriodAllowed = newValue; isLockinPeriodAllowed = newValue;
} }
Integer lockinPeriod = account.getLockinPeriod(); Integer lockinPeriod = account.getLockinPeriod();
final String lockinPeriodParamName = "lockinPeriod"; final String lockinPeriodParamName = "lockinPeriod";
if (command.isChangeInIntegerParameterNamed(lockinPeriodParamName, lockinPeriod)) { if (command.isChangeInIntegerParameterNamed(lockinPeriodParamName, lockinPeriod)) {
final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodParamName); final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodParamName);
actualChanges.put(lockinPeriodParamName, newValue); actualChanges.put(lockinPeriodParamName, newValue);
@@ -455,7 +461,7 @@ public class DepositAccountAssembler {
} }
PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType(); PeriodFrequencyType lockinPeriodType = account.getLockinPeriodType();
final String lockinPeriodTypeParamName = "lockinPeriodType"; final String lockinPeriodTypeParamName = "lockinPeriodType";
if (command.isChangeInIntegerParameterNamed(lockinPeriodTypeParamName, lockinPeriodType.getValue())) { if (command.isChangeInIntegerParameterNamed(lockinPeriodTypeParamName, lockinPeriodType.getValue())) {
final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodTypeParamName); final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodTypeParamName);
actualChanges.put(lockinPeriodTypeParamName, newValue); actualChanges.put(lockinPeriodTypeParamName, newValue);
@@ -464,22 +470,22 @@ public class DepositAccountAssembler {
} }
account.update(product, externalId, commencementDate, deposit, tenureInMonths, maturityInterestRate, preClosureInterestRate, account.update(product, externalId, commencementDate, deposit, tenureInMonths, maturityInterestRate, preClosureInterestRate,
interestCompoundedEvery, interestCompoundedEveryPeriodType, renewalAllowed, preClosureAllowed, isInterestWithdrawable, interestCompoundedEvery, interestCompoundedEveryPeriodType, renewalAllowed, preClosureAllowed, isInterestWithdrawable,
isInterestCompoundingAllowed, this.fixedTermDepositInterestCalculator, isLockinPeriodAllowed, lockinPeriod, isInterestCompoundingAllowed, this.fixedTermDepositInterestCalculator, isLockinPeriodAllowed, lockinPeriod,
lockinPeriodType); lockinPeriodType);
return actualChanges; return actualChanges;
} }
public Map<String, Object> updateApprovedDepositAccount(DepositAccount account, JsonCommand command) { public Map<String, Object> updateApprovedDepositAccount(final DepositAccount account, final JsonCommand command) {
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20); final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20);
final String localeAsInput = command.locale(); final String localeAsInput = command.locale();
Boolean renewalAllowed = account.isRenewalAllowed(); Boolean renewalAllowed = account.isRenewalAllowed();
final String renewalAllowedParamName = "renewalAllowed"; final String renewalAllowedParamName = "renewalAllowed";
if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, renewalAllowed)) { if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, renewalAllowed)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName);
actualChanges.put(renewalAllowedParamName, newValue); actualChanges.put(renewalAllowedParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
renewalAllowed = newValue; renewalAllowed = newValue;
@@ -488,7 +494,7 @@ public class DepositAccountAssembler {
Boolean isInterestWithdrawable = account.isInterestWithdrawable(); Boolean isInterestWithdrawable = account.isInterestWithdrawable();
final String isInterestWithdrawableParamName = "isInterestWithdrawable"; final String isInterestWithdrawableParamName = "isInterestWithdrawable";
if (command.isChangeInBooleanParameterNamed(isInterestWithdrawableParamName, isInterestWithdrawable)) { if (command.isChangeInBooleanParameterNamed(isInterestWithdrawableParamName, isInterestWithdrawable)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(isInterestWithdrawableParamName);
actualChanges.put(isInterestWithdrawableParamName, newValue); actualChanges.put(isInterestWithdrawableParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
isInterestWithdrawable = newValue; isInterestWithdrawable = newValue;
@@ -500,16 +506,16 @@ public class DepositAccountAssembler {
} }
public void postInterest(DepositAccount account) { public void postInterest(final DepositAccount account) {
account.postInterestForDepositAccount(account, this.fixedTermDepositInterestCalculator); account.postInterestForDepositAccount(this.fixedTermDepositInterestCalculator);
} }
private Boolean isBooleanValueUpdated(Boolean actualValue) { private Boolean isBooleanValueUpdated(final Boolean actualValue) {
Boolean isUpdated = false; Boolean isUpdated = false;
if(actualValue != null){ if (actualValue != null) {
isUpdated = true; isUpdated = true;
} }
return isUpdated; return isUpdated;
} }
} }
@@ -24,193 +24,214 @@ import org.mifosplatform.portfolio.savingsdepositproduct.exception.DepositProduc
import org.mifosplatform.useradministration.domain.AppUser; import org.mifosplatform.useradministration.domain.AppUser;
@Entity @Entity
@Table(name = "m_product_deposit", uniqueConstraints={ @Table(name = "m_product_deposit", uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }, name = "name_deposit_product"),
@UniqueConstraint(columnNames = {"name"}, name="name_deposit_product"), @UniqueConstraint(columnNames = { "external_id" }, name = "externalid_deposit_product") })
@UniqueConstraint(columnNames = {"external_id"}, name="externalid_deposit_product")
})
public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> { public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
@Column(name = "name", nullable = false) @Column(name = "name", nullable = false)
private String name; private String name;
@Column(name = "external_id", length=100) @Column(name = "external_id", length = 100)
private String externalId; private String externalId;
@SuppressWarnings("unused") @Column(name = "description")
@Column(name = "description") private String description;
private String description;
@Column(name = "is_deleted", nullable=false) @Column(name = "is_deleted", nullable = false)
private boolean deleted = false; private boolean deleted = false;
@Embedded @Embedded
private MonetaryCurrency currency; private MonetaryCurrency currency;
@Column(name = "minimum_balance", scale = 6, precision = 19, nullable = false) @Column(name = "minimum_balance", scale = 6, precision = 19, nullable = false)
private BigDecimal minimumBalance; private BigDecimal minimumBalance;
@Column(name = "maximum_balance", scale = 6, precision = 19, nullable = false) @Column(name = "maximum_balance", scale = 6, precision = 19, nullable = false)
private BigDecimal maximumBalance; private BigDecimal maximumBalance;
@Column(name = "interest_compounded_every", nullable=false) @Column(name = "interest_compounded_every", nullable = false)
private Integer interestCompoundedEvery; private Integer interestCompoundedEvery;
@Column(name = "interest_compounded_every_period_enum", nullable=false) @Column(name = "interest_compounded_every_period_enum", nullable = false)
private PeriodFrequencyType interestCompoundedEveryPeriodType; private PeriodFrequencyType interestCompoundedEveryPeriodType;
@Column(name = "maturity_default_interest_rate", scale = 6, precision = 19, nullable = false) @Column(name = "maturity_default_interest_rate", scale = 6, precision = 19, nullable = false)
private BigDecimal maturityDefaultInterestRate; private BigDecimal maturityDefaultInterestRate;
@Column(name = "maturity_min_interest_rate", scale = 6, precision = 19, nullable = false) @Column(name = "maturity_min_interest_rate", scale = 6, precision = 19, nullable = false)
private BigDecimal maturityMinInterestRate; private BigDecimal maturityMinInterestRate;
@Column(name = "maturity_max_interest_rate", scale = 6, precision = 19, nullable = false) @Column(name = "maturity_max_interest_rate", scale = 6, precision = 19, nullable = false)
private BigDecimal maturityMaxInterestRate; private BigDecimal maturityMaxInterestRate;
@Column(name = "tenure_months", nullable=false) @Column(name = "tenure_months", nullable = false)
private Integer tenureInMonths; private Integer tenureInMonths;
@Column(name = "is_renewal_allowed", nullable=false) @Column(name = "is_renewal_allowed", nullable = false)
private boolean renewalAllowed = false; private boolean renewalAllowed = false;
@Column(name = "is_preclosure_allowed", nullable=false) @Column(name = "is_preclosure_allowed", nullable = false)
private boolean preClosureAllowed = false; private boolean preClosureAllowed = false;
@Column(name = "is_compounding_interest_allowed", nullable=false) @Column(name = "is_compounding_interest_allowed", nullable = false)
private boolean interestCompoundingAllowed = false; private boolean interestCompoundingAllowed = false;
@Column(name = "pre_closure_interest_rate", scale = 6, precision = 19, nullable = false) @Column(name = "pre_closure_interest_rate", scale = 6, precision = 19, nullable = false)
private BigDecimal preClosureInterestRate; private BigDecimal preClosureInterestRate;
@Column(name = "is_lock_in_period_allowed", nullable=false) @Column(name = "is_lock_in_period_allowed", nullable = false)
private boolean isLockinPeriodAllowed = false; private boolean isLockinPeriodAllowed = false;
@Column(name = "lock_in_period", nullable=false) @Column(name = "lock_in_period", nullable = false)
private Integer lockinPeriod; private Integer lockinPeriod;
@Column(name = "lock_in_period_type", nullable=false) @Column(name = "lock_in_period_type", nullable = false)
private PeriodFrequencyType lockinPeriodType; private PeriodFrequencyType lockinPeriodType;
protected DepositProduct() { public static DepositProduct assembleFromJson(final JsonCommand command, final PeriodFrequencyType interestCompoundingPeriodType,
// final PeriodFrequencyType lockinPeriodType) {
}
public DepositProduct(final String name, final String externalId, final String name = command.stringValueOfParameterNamed("name");
final String description, final String externalId = command.stringValueOfParameterNamed("externalId");
final MonetaryCurrency currency, final BigDecimal minimumBalance, final String description = command.stringValueOfParameterNamed("description");
final BigDecimal maximumBalance, final Integer tenureMonths, final String currencyCode = command.stringValueOfParameterNamed("currencyCode");
final BigDecimal maturityDefaultInterestRate, final Integer digitsAfterDecimal = command.integerValueOfParameterNamed("digitsAfterDecimal");
final BigDecimal maturityMinInterestRate,
final BigDecimal maturityMaxInterestRate,
final Integer interestCompoundedEvery,
final PeriodFrequencyType interestCompoundedEveryPeriodType,
final boolean canRenew,
final boolean canPreClose,
final BigDecimal preClosureInterestRate,
final boolean isInterestCompoundingAllowed,
final boolean isLockinPeriodAllowed,
final Integer lockinPeriod,
final PeriodFrequencyType lockinPeriodType) {
this.name = name.trim();
if (StringUtils.isNotBlank(description)) {
this.description = description.trim();
} else {
this.description = null;
}
if (StringUtils.isNotBlank(externalId)) {
this.externalId = externalId.trim();
} else {
this.externalId = null;
}
this.currency = currency; final MonetaryCurrency currency = new MonetaryCurrency(currencyCode, digitsAfterDecimal);
this.minimumBalance = minimumBalance; final BigDecimal minimumBalance = command.bigDecimalValueOfParameterNamed("minimumBalance");
this.maximumBalance = maximumBalance; final BigDecimal maximumBalance = command.bigDecimalValueOfParameterNamed("maximumBalance");
this.tenureInMonths = tenureMonths;
this.maturityDefaultInterestRate = maturityDefaultInterestRate;
this.maturityMinInterestRate = maturityMinInterestRate;
this.maturityMaxInterestRate = maturityMaxInterestRate;
this.interestCompoundedEvery = interestCompoundedEvery;
this.interestCompoundedEveryPeriodType = interestCompoundedEveryPeriodType;
this.renewalAllowed = canRenew;
this.preClosureAllowed = canPreClose;
this.preClosureInterestRate = preClosureInterestRate;
this.interestCompoundingAllowed = isInterestCompoundingAllowed;
this.isLockinPeriodAllowed = isLockinPeriodAllowed;
this.lockinPeriod = lockinPeriod;
this.lockinPeriodType = lockinPeriodType;
}
public MonetaryCurrency getCurrency() { final Integer tenureMonths = command.integerValueOfParameterNamed("tenureInMonths");
return currency; final BigDecimal maturityDefaultInterestRate = command.bigDecimalValueOfParameterNamed("maturityDefaultInterestRate");
} final BigDecimal maturityMinInterestRate = command.bigDecimalValueOfParameterNamed("maturityMinInterestRate");
final BigDecimal maturityMaxInterestRate = command.bigDecimalValueOfParameterNamed("maturityMaxInterestRate");
final Integer interestCompoundedEvery = command.integerValueOfParameterNamed("interestCompoundedEvery");
public Integer getInterestCompoundedEvery() { final boolean canRenew = command.booleanPrimitiveValueOfParameterNamed("canRenew");
return interestCompoundedEvery; final boolean canPreClose = command.booleanPrimitiveValueOfParameterNamed("canPreClose");
} final BigDecimal preClosureInterestRate = command.bigDecimalValueOfParameterNamed("preClosureInterestRate");
final boolean isInterestCompoundingAllowed = command.booleanPrimitiveValueOfParameterNamed("isInterestCompoundingAllowed");
final boolean isLockinPeriodAllowed = command.booleanPrimitiveValueOfParameterNamed("isLockinPeriodAllowed");
final Integer lockinPeriod = command.integerValueOfParameterNamed("lockinPeriod");
public PeriodFrequencyType getInterestCompoundedEveryPeriodType() { return new DepositProduct(name, externalId, description, currency, minimumBalance, maximumBalance, tenureMonths,
return interestCompoundedEveryPeriodType; maturityDefaultInterestRate, maturityMinInterestRate, maturityMaxInterestRate, interestCompoundedEvery,
} interestCompoundingPeriodType, canRenew, canPreClose, preClosureInterestRate, isInterestCompoundingAllowed,
isLockinPeriodAllowed, lockinPeriod, lockinPeriodType);
}
public Integer getTenureInMonths() { protected DepositProduct() {
return tenureInMonths; //
} }
public BigDecimal getMaturityDefaultInterestRate() { private DepositProduct(final String name, final String externalId, final String description, final MonetaryCurrency currency,
return maturityDefaultInterestRate; final BigDecimal minimumBalance, final BigDecimal maximumBalance, final Integer tenureMonths,
} final BigDecimal maturityDefaultInterestRate, final BigDecimal maturityMinInterestRate,
final BigDecimal maturityMaxInterestRate, final Integer interestCompoundedEvery,
final PeriodFrequencyType interestCompoundedEveryPeriodType, final boolean canRenew, final boolean canPreClose,
final BigDecimal preClosureInterestRate, final boolean isInterestCompoundingAllowed, final boolean isLockinPeriodAllowed,
final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType) {
this.name = name.trim();
if (StringUtils.isNotBlank(description)) {
this.description = description.trim();
} else {
this.description = null;
}
if (StringUtils.isNotBlank(externalId)) {
this.externalId = externalId.trim();
} else {
this.externalId = null;
}
public BigDecimal getMaturityMinInterestRate() { this.currency = currency;
return maturityMinInterestRate; this.minimumBalance = minimumBalance;
} this.maximumBalance = maximumBalance;
this.tenureInMonths = tenureMonths;
this.maturityDefaultInterestRate = maturityDefaultInterestRate;
this.maturityMinInterestRate = maturityMinInterestRate;
this.maturityMaxInterestRate = maturityMaxInterestRate;
this.interestCompoundedEvery = interestCompoundedEvery;
this.interestCompoundedEveryPeriodType = interestCompoundedEveryPeriodType;
this.renewalAllowed = canRenew;
this.preClosureAllowed = canPreClose;
this.preClosureInterestRate = preClosureInterestRate;
this.interestCompoundingAllowed = isInterestCompoundingAllowed;
this.isLockinPeriodAllowed = isLockinPeriodAllowed;
this.lockinPeriod = lockinPeriod;
this.lockinPeriodType = lockinPeriodType;
}
public BigDecimal getPreClosureInterestRate() { public MonetaryCurrency getCurrency() {
return preClosureInterestRate; return currency;
} }
public boolean isRenewalAllowed() { public Integer getInterestCompoundedEvery() {
return this.renewalAllowed; return interestCompoundedEvery;
} }
public boolean isPreClosureAllowed() { public PeriodFrequencyType getInterestCompoundedEveryPeriodType() {
return this.preClosureAllowed; return interestCompoundedEveryPeriodType;
} }
public boolean isInterestCompoundingAllowed() { public Integer getTenureInMonths() {
return interestCompoundingAllowed; return tenureInMonths;
} }
public boolean isLockinPeriodAllowed() { public BigDecimal getMaturityDefaultInterestRate() {
return isLockinPeriodAllowed; return maturityDefaultInterestRate;
} }
public Integer getLockinPeriod() { public BigDecimal getMaturityMinInterestRate() {
return lockinPeriod; return maturityMinInterestRate;
} }
public PeriodFrequencyType getLockinPeriodType() { public BigDecimal getPreClosureInterestRate() {
return lockinPeriodType; return preClosureInterestRate;
} }
public boolean isDeleted() { public boolean isRenewalAllowed() {
return deleted; return this.renewalAllowed;
} }
/** public boolean isPreClosureAllowed() {
* Delete is a <i>soft delete</i>. Updates flag on product so it wont appear in query/report results. return this.preClosureAllowed;
* }
* Any fields with unique constraints and prepended with id of record.
*/
public void delete() {
this.deleted = true;
this.name = this.getId() + "_DELETED_" + this.name;
this.externalId = this.getId() + "_DELETED_" + this.externalId;
}
public Map<String, Object> update(final JsonCommand command){ public boolean isInterestCompoundingAllowed() {
return interestCompoundingAllowed;
}
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20); public boolean isLockinPeriodAllowed() {
return isLockinPeriodAllowed;
}
public Integer getLockinPeriod() {
return lockinPeriod;
}
public PeriodFrequencyType getLockinPeriodType() {
return lockinPeriodType;
}
public boolean isDeleted() {
return deleted;
}
/**
* Delete is a <i>soft delete</i>. Updates flag on product so it wont appear
* in query/report results.
*
* Any fields with unique constraints and prepended with id of record.
*/
public void delete() {
this.deleted = true;
this.name = this.getId() + "_DELETED_" + this.name;
this.externalId = this.getId() + "_DELETED_" + this.externalId;
}
public Map<String, Object> update(final JsonCommand command) {
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20);
final String localeAsInput = command.locale(); final String localeAsInput = command.locale();
@@ -312,7 +333,8 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
} }
final String interestCompoundedEveryPeriodTypeParamName = "interestCompoundedEveryPeriodType"; final String interestCompoundedEveryPeriodTypeParamName = "interestCompoundedEveryPeriodType";
if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryPeriodTypeParamName, this.interestCompoundedEveryPeriodType.getValue())) { if (command.isChangeInIntegerParameterNamed(interestCompoundedEveryPeriodTypeParamName,
this.interestCompoundedEveryPeriodType.getValue())) {
final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryPeriodTypeParamName); final Integer newValue = command.integerValueOfParameterNamed(interestCompoundedEveryPeriodTypeParamName);
actualChanges.put(interestCompoundedEveryPeriodTypeParamName, newValue); actualChanges.put(interestCompoundedEveryPeriodTypeParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
@@ -321,7 +343,7 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
final String renewalAllowedParamName = "renewalAllowed"; final String renewalAllowedParamName = "renewalAllowed";
if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, this.renewalAllowed)) { if (command.isChangeInBooleanParameterNamed(renewalAllowedParamName, this.renewalAllowed)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(renewalAllowedParamName);
actualChanges.put(renewalAllowedParamName, newValue); actualChanges.put(renewalAllowedParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
this.renewalAllowed = newValue; this.renewalAllowed = newValue;
@@ -329,7 +351,7 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
final String preClosureAllowedParamName = "preClosureAllowed"; final String preClosureAllowedParamName = "preClosureAllowed";
if (command.isChangeInBooleanParameterNamed(preClosureAllowedParamName, this.preClosureAllowed)) { if (command.isChangeInBooleanParameterNamed(preClosureAllowedParamName, this.preClosureAllowed)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(preClosureAllowedParamName);
actualChanges.put(preClosureAllowedParamName, newValue); actualChanges.put(preClosureAllowedParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
this.preClosureAllowed = newValue; this.preClosureAllowed = newValue;
@@ -343,9 +365,9 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
this.preClosureInterestRate = newValue; this.preClosureInterestRate = newValue;
} }
final String interestCompoundingAllowedParamName = "interestCompoundingAllowed"; final String interestCompoundingAllowedParamName = "interestCompoundingAllowed";
if (command.isChangeInBooleanParameterNamed(interestCompoundingAllowedParamName, this.interestCompoundingAllowed)) { if (command.isChangeInBooleanParameterNamed(interestCompoundingAllowedParamName, this.interestCompoundingAllowed)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(interestCompoundingAllowedParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(interestCompoundingAllowedParamName);
actualChanges.put(interestCompoundingAllowedParamName, newValue); actualChanges.put(interestCompoundingAllowedParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
this.interestCompoundingAllowed = newValue; this.interestCompoundingAllowed = newValue;
@@ -353,13 +375,13 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed"; final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed";
if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, this.isLockinPeriodAllowed)) { if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, this.isLockinPeriodAllowed)) {
final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName); final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName);
actualChanges.put(isLockinPeriodAllowedParamName, newValue); actualChanges.put(isLockinPeriodAllowedParamName, newValue);
actualChanges.put("locale", localeAsInput); actualChanges.put("locale", localeAsInput);
this.isLockinPeriodAllowed = newValue; this.isLockinPeriodAllowed = newValue;
} }
final String lockinPeriodParamName = "lockinPeriod"; final String lockinPeriodParamName = "lockinPeriod";
if (command.isChangeInIntegerParameterNamed(lockinPeriodParamName, this.lockinPeriod)) { if (command.isChangeInIntegerParameterNamed(lockinPeriodParamName, this.lockinPeriod)) {
final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodParamName); final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodParamName);
actualChanges.put(lockinPeriodParamName, newValue); actualChanges.put(lockinPeriodParamName, newValue);
@@ -367,8 +389,7 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
this.lockinPeriod = newValue; this.lockinPeriod = newValue;
} }
final String lockinPeriodTypeParamName = "lockinPeriodType";
final String lockinPeriodTypeParamName = "lockinPeriodType";
if (command.isChangeInIntegerParameterNamed(lockinPeriodTypeParamName, this.lockinPeriodType.getValue())) { if (command.isChangeInIntegerParameterNamed(lockinPeriodTypeParamName, this.lockinPeriodType.getValue())) {
final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodTypeParamName); final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodTypeParamName);
actualChanges.put(lockinPeriodTypeParamName, newValue); actualChanges.put(lockinPeriodTypeParamName, newValue);
@@ -377,72 +398,41 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
} }
return actualChanges; return actualChanges;
} }
public void validateInterestRateInRange(final BigDecimal interestRate) { public void validateInterestRateInRange(final BigDecimal interestRate) {
boolean inRange = true; boolean inRange = true;
if (interestRate.compareTo(this.maturityMinInterestRate) < 0) { if (interestRate.compareTo(this.maturityMinInterestRate) < 0) {
inRange = false; inRange = false;
} }
if (this.maturityMaxInterestRate.compareTo(interestRate) < 0) { if (this.maturityMaxInterestRate.compareTo(interestRate) < 0) {
inRange = false; inRange = false;
} }
if (!inRange) { if (!inRange) {
final String actualValue = interestRate.toPlainString(); final String actualValue = interestRate.toPlainString();
final String minValue = (this.maturityMinInterestRate == null) ? "" : this.maturityMinInterestRate.toPlainString(); final String minValue = (this.maturityMinInterestRate == null) ? "" : this.maturityMinInterestRate.toPlainString();
final String maxValue = (this.maturityMaxInterestRate == null) ? "" : this.maturityMaxInterestRate.toPlainString(); final String maxValue = (this.maturityMaxInterestRate == null) ? "" : this.maturityMaxInterestRate.toPlainString();
throw new DepositProductValueOutsideRangeException(actualValue, minValue, maxValue, "deposit.account.maturityInterestRate"); throw new DepositProductValueOutsideRangeException(actualValue, minValue, maxValue, "deposit.account.maturityInterestRate");
} }
} }
public void validateDepositInRange(final BigDecimal depositAmount) { public void validateDepositInRange(final BigDecimal depositAmount) {
boolean inRange = true; boolean inRange = true;
if (depositAmount.compareTo(this.minimumBalance) < 0) { if (depositAmount.compareTo(this.minimumBalance) < 0) {
inRange = false; inRange = false;
} }
if (this.maximumBalance != null && this.maximumBalance.compareTo(depositAmount) < 0) { if (this.maximumBalance != null && this.maximumBalance.compareTo(depositAmount) < 0) {
inRange = false; inRange = false;
} }
if (!inRange) { if (!inRange) {
final String actualValue = depositAmount.toPlainString(); final String actualValue = depositAmount.toPlainString();
final String minValue = (this.minimumBalance == null) ? "" : this.minimumBalance.toPlainString(); final String minValue = (this.minimumBalance == null) ? "" : this.minimumBalance.toPlainString();
final String maxValue = (this.maximumBalance == null) ? "" : this.maximumBalance.toPlainString(); final String maxValue = (this.maximumBalance == null) ? "" : this.maximumBalance.toPlainString();
throw new DepositProductValueOutsideRangeException(actualValue, minValue, maxValue, "deposit.account.deposit.amount"); throw new DepositProductValueOutsideRangeException(actualValue, minValue, maxValue, "deposit.account.deposit.amount");
} }
} }
public static DepositProduct assembleFromJson(JsonCommand command, PeriodFrequencyType interestCompoundingPeriodType,
PeriodFrequencyType lockinPeriodType) {
final String name = command.stringValueOfParameterNamed("name");
final String externalId = command.stringValueOfParameterNamed("externalId");
final String description = command.stringValueOfParameterNamed("description");
final String currencyCode = command.stringValueOfParameterNamed("currencyCode");
final Integer digitsAfterDecimal = command.integerValueOfParameterNamed("digitsAfterDecimal");
final MonetaryCurrency currency = new MonetaryCurrency(currencyCode, digitsAfterDecimal);
final BigDecimal minimumBalance = command.bigDecimalValueOfParameterNamed("minimumBalance");
final BigDecimal maximumBalance = command.bigDecimalValueOfParameterNamed("maximumBalance");
final Integer tenureMonths = command.integerValueOfParameterNamed("tenureInMonths");
final BigDecimal maturityDefaultInterestRate = command.bigDecimalValueOfParameterNamed("maturityDefaultInterestRate");
final BigDecimal maturityMinInterestRate = command.bigDecimalValueOfParameterNamed("maturityMinInterestRate");
final BigDecimal maturityMaxInterestRate = command.bigDecimalValueOfParameterNamed("maturityMaxInterestRate");
final Integer interestCompoundedEvery = command.integerValueOfParameterNamed("interestCompoundedEvery");
final boolean canRenew = command.booleanPrimitiveValueOfParameterNamed("canRenew");
final boolean canPreClose = command.booleanPrimitiveValueOfParameterNamed("canPreClose");
final BigDecimal preClosureInterestRate = command.bigDecimalValueOfParameterNamed("preClosureInterestRate");
final boolean isInterestCompoundingAllowed = command.booleanPrimitiveValueOfParameterNamed("isInterestCompoundingAllowed");
final boolean isLockinPeriodAllowed = command.booleanPrimitiveValueOfParameterNamed("isLockinPeriodAllowed");
final Integer lockinPeriod = command.integerValueOfParameterNamed("lockinPeriod");
return new DepositProduct(name, externalId, description, currency, minimumBalance, maximumBalance, tenureMonths, maturityDefaultInterestRate,
maturityMinInterestRate, maturityMaxInterestRate, interestCompoundedEvery, interestCompoundingPeriodType, canRenew, canPreClose,
preClosureInterestRate, isInterestCompoundingAllowed, isLockinPeriodAllowed, lockinPeriod, lockinPeriodType);
}
} }
@@ -12,7 +12,8 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRul
*/ */
public class DepositProductValueOutsideRangeException extends AbstractPlatformDomainRuleException { public class DepositProductValueOutsideRangeException extends AbstractPlatformDomainRuleException {
public DepositProductValueOutsideRangeException(final String actualValue, final String rangeMin, final String rangeMax, final String fieldCode) { public DepositProductValueOutsideRangeException(final String actualValue, final String rangeMin, final String rangeMax,
final String fieldCode) {
super("error.msg." + fieldCode + ".outside.of.allowed.range", actualValue + " is outside of allowed range of [" + rangeMin + ", " super("error.msg." + fieldCode + ".outside.of.allowed.range", actualValue + " is outside of allowed range of [" + rangeMin + ", "
+ rangeMax + "].", actualValue, rangeMin, rangeMax); + rangeMax + "].", actualValue, rangeMin, rangeMax);
} }
@@ -10,16 +10,15 @@ import org.springframework.stereotype.Service;
@Service @Service
public class CreateDepositProductCommandHandler implements NewCommandSourceHandler { public class CreateDepositProductCommandHandler implements NewCommandSourceHandler {
private final DepositProductWritePlatformService depositProductWritePlatformService; private final DepositProductWritePlatformService depositProductWritePlatformService;
@Autowired @Autowired
public CreateDepositProductCommandHandler(final DepositProductWritePlatformService depositProductWritePlatformService) { public CreateDepositProductCommandHandler(final DepositProductWritePlatformService depositProductWritePlatformService) {
this.depositProductWritePlatformService = depositProductWritePlatformService; this.depositProductWritePlatformService = depositProductWritePlatformService;
} }
@Override
public CommandProcessingResult processCommand(JsonCommand command) {
return this.depositProductWritePlatformService.createDepositProduct(command);
}
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.depositProductWritePlatformService.createDepositProduct(command);
}
} }
@@ -15,9 +15,8 @@ public interface DepositProductWritePlatformService {
CommandProcessingResult createDepositProduct(JsonCommand command); CommandProcessingResult createDepositProduct(JsonCommand command);
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'UPDATE_DEPOSITPRODUCT')") @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'UPDATE_DEPOSITPRODUCT')")
CommandProcessingResult updateDepositProduct(Long productId,JsonCommand command); CommandProcessingResult updateDepositProduct(Long productId, JsonCommand command);
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'DELETE_DEPOSITPRODUCT')") @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'DELETE_DEPOSITPRODUCT')")
CommandProcessingResult deleteDepositProduct(Long productId); CommandProcessingResult deleteDepositProduct(Long productId);
} }
@@ -50,76 +50,76 @@ public class DepositProductWritePlatformServiceJpaRepositoryImpl implements Depo
Throwable realCause = dve.getMostSpecificCause(); Throwable realCause = dve.getMostSpecificCause();
if (realCause.getMessage().contains("name_deposit_product")) { if (realCause.getMessage().contains("name_deposit_product")) {
final String name = command.stringValueOfParameterNamed("name"); final String name = command.stringValueOfParameterNamed("name");
throw new PlatformDataIntegrityException( throw new PlatformDataIntegrityException("error.msg.desposit.product.duplicate.name", "Deposit product with name: " + name
"error.msg.desposit.product.duplicate.name", "Deposit product with name: " + name + " already exists", "name", + " already exists", "name", name);
name); } }
if (realCause.getMessage().contains("externalid_deposit_product")) { if (realCause.getMessage().contains("externalid_deposit_product")) {
final String externalId = command.stringValueOfParameterNamed("externalId"); final String externalId = command.stringValueOfParameterNamed("externalId");
throw new PlatformDataIntegrityException( throw new PlatformDataIntegrityException("error.msg.desposit.product.duplicate.externalId", "Deposit product with externalId "
"error.msg.desposit.product.duplicate.externalId", "Deposit product with externalId " + externalId + externalId + " already exists", "externalId", externalId);
+ " already exists", "externalId", externalId); } }
logger.error(dve.getMessage(), dve); logger.error(dve.getMessage(), dve);
throw new PlatformDataIntegrityException("error.msg.deposit.product.unknown.data.integrity.issue", throw new PlatformDataIntegrityException("error.msg.deposit.product.unknown.data.integrity.issue",
"Unknown data integrity issue with resource."); "Unknown data integrity issue with resource.");
} }
@Transactional @Transactional
@Override @Override
public CommandProcessingResult createDepositProduct(JsonCommand command) { public CommandProcessingResult createDepositProduct(final JsonCommand command) {
try { try {
this.context.authenticatedUser(); this.context.authenticatedUser();
this.fromApiJsonDeserializer.validateForCreate(command.json()); this.fromApiJsonDeserializer.validateForCreate(command.json());
final Integer interestCompoundingPeriodTypeIntValue = command.integerValueOfParameterNamed("interestCompoundedEveryPeriodType"); final Integer interestCompoundingPeriodTypeIntValue = command.integerValueOfParameterNamed("interestCompoundedEveryPeriodType");
PeriodFrequencyType interestCompoundingPeriodType = PeriodFrequencyType.fromInt(interestCompoundingPeriodTypeIntValue); PeriodFrequencyType interestCompoundingPeriodType = PeriodFrequencyType.fromInt(interestCompoundingPeriodTypeIntValue);
final Integer lockinPeriodTypeIntValue = command.integerValueOfParameterNamed("lockinPeriodType"); final Integer lockinPeriodTypeIntValue = command.integerValueOfParameterNamed("lockinPeriodType");
PeriodFrequencyType lockinPeriodType = PeriodFrequencyType.fromInt(lockinPeriodTypeIntValue); PeriodFrequencyType lockinPeriodType = PeriodFrequencyType.fromInt(lockinPeriodTypeIntValue);
DepositProduct product = DepositProduct.assembleFromJson(command,interestCompoundingPeriodType,lockinPeriodType); DepositProduct product = DepositProduct.assembleFromJson(command, interestCompoundingPeriodType, lockinPeriodType);
this.depositProductRepository.save(product); this.depositProductRepository.save(product);
return new CommandProcessingResultBuilder() // return new CommandProcessingResultBuilder() //
.withEntityId(product.getId()) // .withEntityId(product.getId()) //
.build(); .build();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
handleDataIntegrityIssues(command, dve); handleDataIntegrityIssues(command, dve);
return new CommandProcessingResult(Long.valueOf(-1)); return new CommandProcessingResult(Long.valueOf(-1));
} }
} }
@Transactional @Transactional
@Override @Override
public CommandProcessingResult updateDepositProduct(final Long productId, final JsonCommand command) { public CommandProcessingResult updateDepositProduct(final Long productId, final JsonCommand command) {
try { try {
this.context.authenticatedUser(); this.context.authenticatedUser();
this.fromApiJsonDeserializer.validateForUpdate(command.json()); this.fromApiJsonDeserializer.validateForUpdate(command.json());
DepositProduct product = this.depositProductRepository.findOne(productId); DepositProduct product = this.depositProductRepository.findOne(productId);
if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(productId); } if (product == null || product.isDeleted()) { throw new DepositProductNotFoundException(productId); }
final Map<String, Object> changes = product.update(command); final Map<String, Object> changes = product.update(command);
if (!changes.isEmpty()) { if (!changes.isEmpty()) {
this.depositProductRepository.saveAndFlush(product); this.depositProductRepository.saveAndFlush(product);
} }
return new CommandProcessingResultBuilder() // return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) // .withCommandId(command.commandId()) //
.withEntityId(productId) // .withEntityId(productId) //
.with(changes) // .with(changes) //
.build(); .build();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
handleDataIntegrityIssues(command, dve); handleDataIntegrityIssues(command, dve);
return new CommandProcessingResult(Long.valueOf(-1)); return new CommandProcessingResult(Long.valueOf(-1));
} }
} }
@Transactional @Transactional
@Override @Override
@@ -136,5 +136,4 @@ public class DepositProductWritePlatformServiceJpaRepositoryImpl implements Depo
.withEntityId(product.getId()) // .withEntityId(product.getId()) //
.build(); .build();
} }
} }