integrate deposit account with deposit product concept.

This commit is contained in:
Keith Woodlock
2012-08-10 12:43:45 +01:00
parent e67df9e3bf
commit 43a40ab14c
10 changed files with 78 additions and 30 deletions
@@ -82,7 +82,7 @@ public class DepositAccountsApiResource {
Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("createdOn", "lastModifedOn",
"id", "clientId", "clientName", "productId", "productName",
"currency", "deposit", "interestRate")
"currency", "deposit", "maturityInterestRate")
);
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
@@ -105,7 +105,7 @@ public class DepositAccountsApiResource {
Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("createdOn", "lastModifedOn",
"id", "clientId", "clientName", "productId", "productName",
"currency", "deposit", "interestRate")
"currency", "deposit", "maturityInterestRate")
);
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
@@ -135,7 +135,7 @@ public class DepositAccountsApiResource {
Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("createdOn", "lastModifedOn",
"id", "clientId", "clientName", "productId", "productName",
"currency", "deposit", "interestRate", "currencyOptions")
"currency", "deposit", "maturityInterestRate", "currencyOptions")
);
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
@@ -16,7 +16,7 @@ public class DepositAccountCommand {
private final String currencyCode;
private final Integer digitsAfterDecimal;
private final BigDecimal depositAmount;
private final BigDecimal interestRate;
private final BigDecimal maturityInterestRate;
private final Integer termInMonths;
private final Set<String> modifiedParameters;
@@ -39,7 +39,7 @@ public class DepositAccountCommand {
this.currencyCode = currencyCode;
this.digitsAfterDecimal = digitsAfterDecimal;
this.depositAmount = depositAmount;
this.interestRate = interestRate;
this.maturityInterestRate = interestRate;
this.termInMonths = termInMonths;
this.modifiedParameters = modifiedParameters;
@@ -72,9 +72,9 @@ public class DepositAccountCommand {
public BigDecimal getDepositAmount() {
return depositAmount;
}
public BigDecimal getInterestRate() {
return interestRate;
public BigDecimal getMaturityInterestRate() {
return maturityInterestRate;
}
public Integer getTermInMonths() {
@@ -21,7 +21,7 @@ public class DepositAccountData {
private final CurrencyData currency;
private final BigDecimal deposit;
private final BigDecimal interestRate;
private final BigDecimal maturityInterestRate;
private final DateTime createdOn;
private final DateTime lastModifedOn;
@@ -38,7 +38,7 @@ public class DepositAccountData {
this.productName = null;
this.currency = null;
this.deposit = null;
this.interestRate = null;
this.maturityInterestRate = null;
this.currencyOptions = new ArrayList<CurrencyData>();
}
@@ -52,7 +52,7 @@ public class DepositAccountData {
this.productName = account.getProductName();
this.currency = account.getCurrency();
this.deposit = account.getDeposit();
this.interestRate = account.getInterestRate();
this.maturityInterestRate = account.getMaturityInterestRate();
this.currencyOptions = currencies;
}
@@ -75,7 +75,7 @@ public class DepositAccountData {
this.productName = productName;
this.currency = currency;
this.deposit = deposit;
this.interestRate=interestRate;
this.maturityInterestRate=interestRate;
this.currencyOptions = new ArrayList<CurrencyData>();
}
@@ -107,8 +107,8 @@ public class DepositAccountData {
return deposit;
}
public BigDecimal getInterestRate() {
return interestRate;
public BigDecimal getMaturityInterestRate() {
return maturityInterestRate;
}
public DateTime getCreatedOn() {
@@ -1493,7 +1493,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(
Arrays.asList("clientId", "productId", "externalId", "currencyCode", "digitsAfterDecimal", "depositAmount", "interestRate", "termInMonths", "locale")
Arrays.asList("clientId", "productId", "externalId", "currencyCode", "digitsAfterDecimal", "depositAmount", "maturityInterestRate", "termInMonths", "locale")
);
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
@@ -1504,7 +1504,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
String currencyCode=extractStringParameter("currencyCode", requestMap,modifiedParameters);
Integer digitsAfterDecimalValue = extractIntegerParameter("digitsAfterDecimal", requestMap, modifiedParameters);
BigDecimal depositAmount=extractBigDecimalParameter("depositAmount", requestMap, modifiedParameters);
BigDecimal interestRate = extractBigDecimalParameter("interestRate", requestMap, modifiedParameters);
BigDecimal interestRate = extractBigDecimalParameter("maturityInterestRate", requestMap, modifiedParameters);
Integer termInMonths = extractIntegerParameter("termInMonths", requestMap, modifiedParameters);
// isRenewable, isPreClosureAllowed, expectedDepositDate, pojectMaturityDate, projectedInterestAccrued
@@ -1636,7 +1636,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
Set<String> supportedParameters = new HashSet<String>(
Arrays.asList("createdOn", "lastModifedOn",
"id", "clientId", "clientName", "productId", "productName",
"currency", "deposit", "interestRate", "currencyOptions")
"currency", "deposit", "maturityInterestRate", "currencyOptions")
);
final Set<String> parameterNamesToSkip = new HashSet<String>();
@@ -27,7 +27,7 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
private boolean deleted = false;
@Embedded
DepositProductRelatedDetail depositProductRelatedDetail;
private DepositProductRelatedDetail depositProductRelatedDetail;
protected DepositProduct(){
this.name = null;
@@ -115,4 +115,8 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
this.depositProductRelatedDetail.update(command);
}
public void validateInterestRateInRange(final BigDecimal interestRate) {
this.depositProductRelatedDetail.validateInterestRateInRange(interestRate);
}
}
@@ -8,6 +8,7 @@ import javax.persistence.Embedded;
import org.mifosng.platform.api.commands.DepositProductCommand;
import org.mifosng.platform.currency.domain.MonetaryCurrency;
import org.mifosng.platform.exceptions.InterestRateOutsideRangeException;
@Embeddable
public class DepositProductRelatedDetail {
@@ -165,4 +166,18 @@ import org.mifosng.platform.currency.domain.MonetaryCurrency;
}
}
public void validateInterestRateInRange(final BigDecimal interestRate) {
boolean inRange = true;
if (interestRate.compareTo(this.maturityMinInterestRate) < 0) {
inRange = false;
}
if (this.maturityMaxInterestRate.compareTo(interestRate) < 0) {
inRange = false;
}
if (!inRange) {
throw new InterestRateOutsideRangeException(interestRate, this.maturityMinInterestRate, this.maturityMaxInterestRate);
}
}
}
@@ -0,0 +1,14 @@
package org.mifosng.platform.exceptions;
import java.math.BigDecimal;
/**
* Exception thrown when an attempt is made update the parent of a root office.
*/
public class InterestRateOutsideRangeException extends AbstractPlatformDomainRuleException {
public InterestRateOutsideRangeException(final BigDecimal interestRate, final BigDecimal rangeMin, final BigDecimal rangeMax) {
super("error.msg.deposit.account.maturityInterestRate.outside.of.allowed.range", "Interest rate of " + interestRate.toPlainString() + " is outside of allowed range of ["
+ rangeMin.toPlainString() + ", " + rangeMax.toPlainString() + "].", interestRate, rangeMin, rangeMax);
}
}
@@ -14,6 +14,7 @@ import org.mifosng.platform.api.commands.DepositAccountCommand;
import org.mifosng.platform.client.domain.Client;
import org.mifosng.platform.currency.domain.MonetaryCurrency;
import org.mifosng.platform.currency.domain.Money;
import org.mifosng.platform.deposit.domain.DepositProduct;
import org.mifosng.platform.infrastructure.AbstractAuditableCustom;
import org.mifosng.platform.user.domain.AppUser;
@@ -25,9 +26,9 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
@JoinColumn(name = "client_id", nullable = false)
private Client client;
// @ManyToOne
// @JoinColumn(name = "product_id")
// private final DepositAccountProduct depositAccountProduct;
@ManyToOne
@JoinColumn(name = "product_id")
private final DepositProduct product;
@Column(name = "external_id")
private String externalId;
@@ -57,15 +58,19 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
private boolean deleted = false;
protected DepositAccount() {
//
this.product = null;
}
public DepositAccount(final Client client, final String externalId, final Money deposit, final BigDecimal interestRate, final Integer termInMonths) {
public DepositAccount(
final Client client, final DepositProduct product,
final String externalId, final Money deposit, final BigDecimal interestRate, final Integer termInMonths) {
this.client = client;
this.product = product;
this.externalId = externalId;
this.currency = deposit.getCurrency();
this.depositAmount = deposit.getAmount();
this.interestRate = interestRate;
product.validateInterestRateInRange(interestRate);
this.tenureInMonths = termInMonths;
this.preClosureInterestRate = BigDecimal.ZERO;
}
@@ -5,7 +5,10 @@ import org.mifosng.platform.client.domain.Client;
import org.mifosng.platform.client.domain.ClientRepository;
import org.mifosng.platform.currency.domain.MonetaryCurrency;
import org.mifosng.platform.currency.domain.Money;
import org.mifosng.platform.deposit.domain.DepositProduct;
import org.mifosng.platform.deposit.domain.DepositProductRepository;
import org.mifosng.platform.exceptions.ClientNotFoundException;
import org.mifosng.platform.exceptions.DepositProductNotFoundException;
import org.mifosng.platform.saving.domain.DepositAccount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -17,10 +20,12 @@ import org.springframework.stereotype.Service;
public class DepositAccountAssembler {
private final ClientRepository clientRepository;
private final DepositProductRepository depositProductRepository;
@Autowired
public DepositAccountAssembler(final ClientRepository clientRepository) {
public DepositAccountAssembler(final ClientRepository clientRepository, final DepositProductRepository depositProductRepository) {
this.clientRepository = clientRepository;
this.depositProductRepository = depositProductRepository;
}
public DepositAccount assembleFrom(final DepositAccountCommand command) {
@@ -28,11 +33,16 @@ public class DepositAccountAssembler {
Client client = this.clientRepository.findOne(command.getClientId());
if (client == null || client.isDeleted()) {
throw new ClientNotFoundException(command.getClientId());
}
DepositProduct product = this.depositProductRepository.findOne(command.getProductId());
if (product == null || product.isDeleted()) {
throw new DepositProductNotFoundException(command.getProductId());
}
MonetaryCurrency currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimal());
Money deposit = Money.of(currency, command.getDepositAmount());
return new DepositAccount(client, command.getExternalId(), deposit, command.getInterestRate(), command.getTermInMonths());
return new DepositAccount(client, product, command.getExternalId(), deposit, command.getMaturityInterestRate(), command.getTermInMonths());
}
}
@@ -30,13 +30,13 @@ public class DepositAccountCommandValidator {
baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).ignoreIfNull().notNull().inMinMaxRange(0, 6);
baseDataValidator.reset().parameter("depositAmount").value(command.getDepositAmount()).ignoreIfNull().notNull().integerGreaterThanZero();
baseDataValidator.reset().parameter("interestRate").value(command.getInterestRate()).ignoreIfNull().notNull().zeroOrPositiveAmount();
baseDataValidator.reset().parameter("maturityInterestRate").value(command.getMaturityInterestRate()).ignoreIfNull().notNull().zeroOrPositiveAmount();
baseDataValidator.reset().parameter("termInMonths").value(command.getTermInMonths()).ignoreIfNull().notNull().integerGreaterThanZero();
baseDataValidator.reset().anyOfNotNull(
command.getClientId(), command.getProductId(), command.getExternalId(),
command.getCurrencyCode(),command.getDigitsAfterDecimal(),
command.getDepositAmount(), command.getInterestRate(),command.getTermInMonths());
command.getCurrencyCode(), command.getDigitsAfterDecimal(),
command.getDepositAmount(), command.getMaturityInterestRate(), command.getTermInMonths());
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
@@ -56,7 +56,7 @@ public class DepositAccountCommandValidator {
baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank();
baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).notNull().inMinMaxRange(0, 6);
baseDataValidator.reset().parameter("depositAmount").value(command.getDepositAmount()).notNull().zeroOrPositiveAmount();
baseDataValidator.reset().parameter("interestRate").value(command.getInterestRate()).notNull().zeroOrPositiveAmount();
baseDataValidator.reset().parameter("maturityInterestRate").value(command.getMaturityInterestRate()).notNull().zeroOrPositiveAmount();
baseDataValidator.reset().parameter("termInMonths").value(command.getTermInMonths()).notNull().integerGreaterThanZero();
if (!dataValidationErrors.isEmpty()) {