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>( Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("createdOn", "lastModifedOn", Arrays.asList("createdOn", "lastModifedOn",
"id", "clientId", "clientName", "productId", "productName", "id", "clientId", "clientName", "productId", "productName",
"currency", "deposit", "interestRate") "currency", "deposit", "maturityInterestRate")
); );
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
@@ -105,7 +105,7 @@ public class DepositAccountsApiResource {
Set<String> typicalResponseParameters = new HashSet<String>( Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("createdOn", "lastModifedOn", Arrays.asList("createdOn", "lastModifedOn",
"id", "clientId", "clientName", "productId", "productName", "id", "clientId", "clientName", "productId", "productName",
"currency", "deposit", "interestRate") "currency", "deposit", "maturityInterestRate")
); );
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
@@ -135,7 +135,7 @@ public class DepositAccountsApiResource {
Set<String> typicalResponseParameters = new HashSet<String>( Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("createdOn", "lastModifedOn", Arrays.asList("createdOn", "lastModifedOn",
"id", "clientId", "clientName", "productId", "productName", "id", "clientId", "clientName", "productId", "productName",
"currency", "deposit", "interestRate", "currencyOptions") "currency", "deposit", "maturityInterestRate", "currencyOptions")
); );
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
@@ -16,7 +16,7 @@ public class DepositAccountCommand {
private final String currencyCode; private final String currencyCode;
private final Integer digitsAfterDecimal; private final Integer digitsAfterDecimal;
private final BigDecimal depositAmount; private final BigDecimal depositAmount;
private final BigDecimal interestRate; private final BigDecimal maturityInterestRate;
private final Integer termInMonths; private final Integer termInMonths;
private final Set<String> modifiedParameters; private final Set<String> modifiedParameters;
@@ -39,7 +39,7 @@ public class DepositAccountCommand {
this.currencyCode = currencyCode; this.currencyCode = currencyCode;
this.digitsAfterDecimal = digitsAfterDecimal; this.digitsAfterDecimal = digitsAfterDecimal;
this.depositAmount = depositAmount; this.depositAmount = depositAmount;
this.interestRate = interestRate; this.maturityInterestRate = interestRate;
this.termInMonths = termInMonths; this.termInMonths = termInMonths;
this.modifiedParameters = modifiedParameters; this.modifiedParameters = modifiedParameters;
@@ -73,8 +73,8 @@ public class DepositAccountCommand {
return depositAmount; return depositAmount;
} }
public BigDecimal getInterestRate() { public BigDecimal getMaturityInterestRate() {
return interestRate; return maturityInterestRate;
} }
public Integer getTermInMonths() { public Integer getTermInMonths() {
@@ -21,7 +21,7 @@ public class DepositAccountData {
private final CurrencyData currency; private final CurrencyData currency;
private final BigDecimal deposit; private final BigDecimal deposit;
private final BigDecimal interestRate; private final BigDecimal maturityInterestRate;
private final DateTime createdOn; private final DateTime createdOn;
private final DateTime lastModifedOn; private final DateTime lastModifedOn;
@@ -38,7 +38,7 @@ public class DepositAccountData {
this.productName = null; this.productName = null;
this.currency = null; this.currency = null;
this.deposit = null; this.deposit = null;
this.interestRate = null; this.maturityInterestRate = null;
this.currencyOptions = new ArrayList<CurrencyData>(); this.currencyOptions = new ArrayList<CurrencyData>();
} }
@@ -52,7 +52,7 @@ public class DepositAccountData {
this.productName = account.getProductName(); this.productName = account.getProductName();
this.currency = account.getCurrency(); this.currency = account.getCurrency();
this.deposit = account.getDeposit(); this.deposit = account.getDeposit();
this.interestRate = account.getInterestRate(); this.maturityInterestRate = account.getMaturityInterestRate();
this.currencyOptions = currencies; this.currencyOptions = currencies;
} }
@@ -75,7 +75,7 @@ public class DepositAccountData {
this.productName = productName; this.productName = productName;
this.currency = currency; this.currency = currency;
this.deposit = deposit; this.deposit = deposit;
this.interestRate=interestRate; this.maturityInterestRate=interestRate;
this.currencyOptions = new ArrayList<CurrencyData>(); this.currencyOptions = new ArrayList<CurrencyData>();
} }
@@ -107,8 +107,8 @@ public class DepositAccountData {
return deposit; return deposit;
} }
public BigDecimal getInterestRate() { public BigDecimal getMaturityInterestRate() {
return interestRate; return maturityInterestRate;
} }
public DateTime getCreatedOn() { public DateTime getCreatedOn() {
@@ -1493,7 +1493,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap); Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>( 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); checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>(); Set<String> modifiedParameters = new HashSet<String>();
@@ -1504,7 +1504,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
String currencyCode=extractStringParameter("currencyCode", requestMap,modifiedParameters); String currencyCode=extractStringParameter("currencyCode", requestMap,modifiedParameters);
Integer digitsAfterDecimalValue = extractIntegerParameter("digitsAfterDecimal", requestMap, modifiedParameters); Integer digitsAfterDecimalValue = extractIntegerParameter("digitsAfterDecimal", requestMap, modifiedParameters);
BigDecimal depositAmount=extractBigDecimalParameter("depositAmount", 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); Integer termInMonths = extractIntegerParameter("termInMonths", requestMap, modifiedParameters);
// isRenewable, isPreClosureAllowed, expectedDepositDate, pojectMaturityDate, projectedInterestAccrued // isRenewable, isPreClosureAllowed, expectedDepositDate, pojectMaturityDate, projectedInterestAccrued
@@ -1636,7 +1636,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
Set<String> supportedParameters = new HashSet<String>( Set<String> supportedParameters = new HashSet<String>(
Arrays.asList("createdOn", "lastModifedOn", Arrays.asList("createdOn", "lastModifedOn",
"id", "clientId", "clientName", "productId", "productName", "id", "clientId", "clientName", "productId", "productName",
"currency", "deposit", "interestRate", "currencyOptions") "currency", "deposit", "maturityInterestRate", "currencyOptions")
); );
final Set<String> parameterNamesToSkip = new HashSet<String>(); final Set<String> parameterNamesToSkip = new HashSet<String>();
@@ -27,7 +27,7 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
private boolean deleted = false; private boolean deleted = false;
@Embedded @Embedded
DepositProductRelatedDetail depositProductRelatedDetail; private DepositProductRelatedDetail depositProductRelatedDetail;
protected DepositProduct(){ protected DepositProduct(){
this.name = null; this.name = null;
@@ -115,4 +115,8 @@ public class DepositProduct extends AbstractAuditableCustom<AppUser, Long> {
this.depositProductRelatedDetail.update(command); 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.api.commands.DepositProductCommand;
import org.mifosng.platform.currency.domain.MonetaryCurrency; import org.mifosng.platform.currency.domain.MonetaryCurrency;
import org.mifosng.platform.exceptions.InterestRateOutsideRangeException;
@Embeddable @Embeddable
public class DepositProductRelatedDetail { 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.client.domain.Client;
import org.mifosng.platform.currency.domain.MonetaryCurrency; import org.mifosng.platform.currency.domain.MonetaryCurrency;
import org.mifosng.platform.currency.domain.Money; import org.mifosng.platform.currency.domain.Money;
import org.mifosng.platform.deposit.domain.DepositProduct;
import org.mifosng.platform.infrastructure.AbstractAuditableCustom; import org.mifosng.platform.infrastructure.AbstractAuditableCustom;
import org.mifosng.platform.user.domain.AppUser; import org.mifosng.platform.user.domain.AppUser;
@@ -25,9 +26,9 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
@JoinColumn(name = "client_id", nullable = false) @JoinColumn(name = "client_id", nullable = false)
private Client client; private Client client;
// @ManyToOne @ManyToOne
// @JoinColumn(name = "product_id") @JoinColumn(name = "product_id")
// private final DepositAccountProduct depositAccountProduct; private final DepositProduct product;
@Column(name = "external_id") @Column(name = "external_id")
private String externalId; private String externalId;
@@ -57,15 +58,19 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
private boolean deleted = false; private boolean deleted = false;
protected DepositAccount() { 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.client = client;
this.product = product;
this.externalId = externalId; this.externalId = externalId;
this.currency = deposit.getCurrency(); this.currency = deposit.getCurrency();
this.depositAmount = deposit.getAmount(); this.depositAmount = deposit.getAmount();
this.interestRate = interestRate; this.interestRate = interestRate;
product.validateInterestRateInRange(interestRate);
this.tenureInMonths = termInMonths; this.tenureInMonths = termInMonths;
this.preClosureInterestRate = BigDecimal.ZERO; 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.client.domain.ClientRepository;
import org.mifosng.platform.currency.domain.MonetaryCurrency; import org.mifosng.platform.currency.domain.MonetaryCurrency;
import org.mifosng.platform.currency.domain.Money; 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.ClientNotFoundException;
import org.mifosng.platform.exceptions.DepositProductNotFoundException;
import org.mifosng.platform.saving.domain.DepositAccount; import org.mifosng.platform.saving.domain.DepositAccount;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -17,10 +20,12 @@ import org.springframework.stereotype.Service;
public class DepositAccountAssembler { public class DepositAccountAssembler {
private final ClientRepository clientRepository; private final ClientRepository clientRepository;
private final DepositProductRepository depositProductRepository;
@Autowired @Autowired
public DepositAccountAssembler(final ClientRepository clientRepository) { public DepositAccountAssembler(final ClientRepository clientRepository, final DepositProductRepository depositProductRepository) {
this.clientRepository = clientRepository; this.clientRepository = clientRepository;
this.depositProductRepository = depositProductRepository;
} }
public DepositAccount assembleFrom(final DepositAccountCommand command) { public DepositAccount assembleFrom(final DepositAccountCommand command) {
@@ -30,9 +35,14 @@ public class DepositAccountAssembler {
throw new ClientNotFoundException(command.getClientId()); 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()); MonetaryCurrency currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimal());
Money deposit = Money.of(currency, command.getDepositAmount()); 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("currencyCode").value(command.getCurrencyCode()).ignoreIfNull().notBlank();
baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).ignoreIfNull().notNull().inMinMaxRange(0, 6); 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("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().parameter("termInMonths").value(command.getTermInMonths()).ignoreIfNull().notNull().integerGreaterThanZero();
baseDataValidator.reset().anyOfNotNull( baseDataValidator.reset().anyOfNotNull(
command.getClientId(), command.getProductId(), command.getExternalId(), command.getClientId(), command.getProductId(), command.getExternalId(),
command.getCurrencyCode(),command.getDigitsAfterDecimal(), command.getCurrencyCode(), command.getDigitsAfterDecimal(),
command.getDepositAmount(), command.getInterestRate(),command.getTermInMonths()); command.getDepositAmount(), command.getMaturityInterestRate(), command.getTermInMonths());
if (!dataValidationErrors.isEmpty()) { if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); 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("currencyCode").value(command.getCurrencyCode()).notBlank();
baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).notNull().inMinMaxRange(0, 6); baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).notNull().inMinMaxRange(0, 6);
baseDataValidator.reset().parameter("depositAmount").value(command.getDepositAmount()).notNull().zeroOrPositiveAmount(); 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(); baseDataValidator.reset().parameter("termInMonths").value(command.getTermInMonths()).notNull().integerGreaterThanZero();
if (!dataValidationErrors.isEmpty()) { if (!dataValidationErrors.isEmpty()) {