keep DepositAccountData as an immutable object. opt against used selectedProduct approach like in loans. drop currencyOptions as the product should define the currency. add productOptions (options for consistency) when retrieving template.

This commit is contained in:
Keith Woodlock
2012-08-17 15:02:36 +01:00
parent 88e4c4ec00
commit d855129fea
4 changed files with 104 additions and 78 deletions
@@ -21,16 +21,16 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.commands.DepositAccountCommand;
import org.mifosng.platform.api.data.CurrencyData;
import org.mifosng.platform.api.data.DepositAccountData;
import org.mifosng.platform.api.data.DepositProductLookup;
import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.data.EnumOptionData;
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
import org.mifosng.platform.api.infrastructure.ApiParameterHelper;
import org.mifosng.platform.currency.service.CurrencyReadPlatformService;
import org.mifosng.platform.loan.domain.PeriodFrequencyType;
import org.mifosng.platform.saving.service.DepositAccountReadPlatformService;
import org.mifosng.platform.saving.service.DepositAccountWritePlatformService;
import org.mifosng.platform.savingproduct.service.DepositProductReadPlatformService;
import org.mifosng.platform.savingproduct.service.SavingsDepositEnumerations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@@ -45,7 +45,7 @@ public class DepositAccountsApiResource {
private DepositAccountReadPlatformService depositAccountReadPlatformService;
@Autowired
private CurrencyReadPlatformService currencyReadPlatformService;
private DepositProductReadPlatformService depositProductReadPlatformService;
@Autowired
private DepositAccountWritePlatformService depositAccountWritePlatformService;
@@ -142,11 +142,11 @@ public class DepositAccountsApiResource {
@Context final UriInfo uriInfo) {
Set<String> typicalResponseParameters = new HashSet<String>(
Arrays.asList("currencyOptions", "interestCompoundedEveryPeriodTypeOptions",
Arrays.asList(
"createdOn", "lastModifedOn",
"id", "externalId", "clientId", "clientName", "productId", "productName",
"currency", "deposit", "maturityInterestRate", "tenureInMonths", "interestCompoundedEvery", "interestCompoundedEveryPeriodType",
"renewalAllowed","preClosureAllowed","preClosureInterestRate","allowedProducts"
"renewalAllowed","preClosureAllowed","preClosureInterestRate"
)
);
@@ -178,12 +178,13 @@ public class DepositAccountsApiResource {
final Set<String> responseParameters,
final DepositAccountData account) {
responseParameters.addAll(Arrays.asList("currencyOptions", "interestCompoundedEveryPeriodTypeOptions"));
List<CurrencyData> allowedCurrencies = this.currencyReadPlatformService.retrieveAllowedCurrencies();
responseParameters.addAll(Arrays.asList("interestCompoundedEveryPeriodTypeOptions", "productOptions"));
Collection<DepositProductLookup> productOptions = depositProductReadPlatformService.retrieveAllDepositProductsForLookup();
EnumOptionData monthly = SavingsDepositEnumerations.interestCompoundingPeriodType(PeriodFrequencyType.MONTHS);
List<EnumOptionData> interestCompoundedEveryPeriodTypeOptions = Arrays.asList(monthly);
return new DepositAccountData(account, allowedCurrencies, interestCompoundedEveryPeriodTypeOptions);
return new DepositAccountData(account, interestCompoundedEveryPeriodTypeOptions, productOptions);
}
}
@@ -2,6 +2,7 @@ package org.mifosng.platform.api.data;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.joda.time.DateTime;
@@ -14,11 +15,11 @@ public class DepositAccountData {
private final Long id;
private final String externalId;
private Long clientId;
private String clientName;
private Long productId;
private String productName;
private final Long clientId;
private final String clientName;
private final Long productId;
private final String productName;
private final CurrencyData currency;
private final BigDecimal deposit;
@@ -43,24 +44,31 @@ public class DepositAccountData {
private final DateTime createdOn;
private final DateTime lastModifedOn;
private final List<CurrencyData> currencyOptions;
private final List<EnumOptionData> interestCompoundedEveryPeriodTypeOptions;
private List<DepositProductLookup> allowedProducts = new ArrayList<DepositProductLookup>();
private DepositProductData selectedProduct;
public DepositAccountData() {
this.createdOn = null;
this.lastModifedOn = null;
this.id = null;
private final List<DepositProductLookup> productOptions;
/*
* used when returning account template data but only a clientId is passed, no selected product.
*/
public static DepositAccountData createFrom(final Long clientId, final String clientDisplayName) {
return new DepositAccountData(clientId, clientDisplayName);
}
private DepositAccountData(
final Long clientId,
final String clientName) {
this.createdOn=null;
this.lastModifedOn=null;
this.id=null;
this.externalId = null;
this.clientId = null;
this.clientName = null;
this.clientId = clientId;
this.clientName = clientName;
this.productId = null;
this.productName = null;
this.currency = null;
this.deposit = null;
this.maturityInterestRate = null;
this.maturityInterestRate=null;
this.tenureInMonths = null;
this.projectedCommencementDate = null;
this.actualCommencementDate = null;
@@ -76,11 +84,14 @@ public class DepositAccountData {
this.preClosureAllowed = false;
this.preClosureInterestRate = null;
this.currencyOptions = new ArrayList<CurrencyData>();
this.interestCompoundedEveryPeriodTypeOptions = new ArrayList<EnumOptionData>();
this.productOptions = new ArrayList<DepositProductLookup>();
}
public DepositAccountData(final DepositAccountData account, final List<CurrencyData> currencies, final List<EnumOptionData> interestCompoundedEveryPeriodTypeOptions) {
public DepositAccountData(
final DepositAccountData account,
final List<EnumOptionData> interestCompoundedEveryPeriodTypeOptions,
final Collection<DepositProductLookup> productOptions) {
this.createdOn = account.getCreatedOn();
this.lastModifedOn = account.getLastModifedOn();
this.id = account.getId();
@@ -107,8 +118,8 @@ public class DepositAccountData {
this.preClosureAllowed = account.isPreClosureAllowed();
this.preClosureInterestRate = account.getPreClosureInterestRate();
this.currencyOptions = currencies;
this.interestCompoundedEveryPeriodTypeOptions = interestCompoundedEveryPeriodTypeOptions;
this.productOptions = new ArrayList<DepositProductLookup>(productOptions);
}
public DepositAccountData(
@@ -162,8 +173,51 @@ public class DepositAccountData {
this.preClosureAllowed = preClosureAllowed;
this.preClosureInterestRate = preClosureInterestRate;
this.currencyOptions = new ArrayList<CurrencyData>();
this.interestCompoundedEveryPeriodTypeOptions = new ArrayList<EnumOptionData>();
this.productOptions = new ArrayList<DepositProductLookup>();
}
public DepositAccountData(
final Long clientId,
final String clientName,
final Long productId,
final String productName,
final CurrencyData currency,
final BigDecimal deposit, final BigDecimal interestRate,
final Integer tenureInMonths,
final Integer interestCompoundedEvery,
final EnumOptionData interestCompoundedEveryPeriodType,
final boolean renewalAllowed,
final boolean preClosureAllowed,
final BigDecimal preClosureInterestRate) {
this.createdOn=null;
this.lastModifedOn=null;
this.id=null;
this.externalId = null;
this.clientId = clientId;
this.clientName = clientName;
this.productId = productId;
this.productName = productName;
this.currency = currency;
this.deposit = deposit;
this.maturityInterestRate=interestRate;
this.tenureInMonths = tenureInMonths;
this.projectedCommencementDate = null;
this.actualCommencementDate = null;
this.projectedMaturityDate = null;
this.actualMaturityDate = null;
this.projectedInterestAccrued = null;
this.actualInterestAccrued = null;
this.projectedMaturityAmount = null;
this.actualMaturityAmount = null;
this.interestCompoundedEvery = interestCompoundedEvery;
this.interestCompoundedEveryPeriodType = interestCompoundedEveryPeriodType;
this.renewalAllowed = renewalAllowed;
this.preClosureAllowed = preClosureAllowed;
this.preClosureInterestRate = preClosureInterestRate;
this.interestCompoundedEveryPeriodTypeOptions = new ArrayList<EnumOptionData>();
this.productOptions = new ArrayList<DepositProductLookup>();
}
public Long getId() {
@@ -266,44 +320,11 @@ public class DepositAccountData {
return lastModifedOn;
}
public List<CurrencyData> getCurrencyOptions() {
return currencyOptions;
}
public List<EnumOptionData> getInterestCompoundedEveryPeriodTypeOptions() {
return interestCompoundedEveryPeriodTypeOptions;
}
public List<DepositProductLookup> getAllowedProducts() {
return allowedProducts;
public List<DepositProductLookup> getProductOptions() {
return productOptions;
}
public void setAllowedProducts(List<DepositProductLookup> allowedProducts) {
this.allowedProducts = allowedProducts;
}
public DepositProductData getSelectedProduct() {
return selectedProduct;
}
public void setSelectedProduct(DepositProductData selectedProduct) {
this.selectedProduct = selectedProduct;
}
public void setClientId(Long clientId) {
this.clientId = clientId;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}
public void setProductId(Long productId) {
this.productId = productId;
}
public void setProductName(String productName) {
this.productName = productName;
}
}
@@ -1719,12 +1719,12 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
final DepositAccountData... accounts) {
Set<String> supportedParameters = new HashSet<String>(
Arrays.asList("currencyOptions", "interestCompoundedEveryPeriodTypeOptions",
Arrays.asList("productOptions", "interestCompoundedEveryPeriodTypeOptions",
"createdOn", "lastModifedOn",
"id", "externalId", "clientId", "clientName", "productId", "productName",
"currency", "deposit", "maturityInterestRate", "tenureInMonths",
"interestCompoundedEvery", "interestCompoundedEveryPeriodType",
"renewalAllowed","preClosureAllowed","preClosureInterestRate","allowedProducts"
"renewalAllowed","preClosureAllowed","preClosureInterestRate"
)
);
@@ -3,9 +3,7 @@ package org.mifosng.platform.saving.service;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
@@ -75,30 +73,36 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead
@Override
public DepositAccountData retrieveNewDepositAccountDetails(final Long clientId, final Long productId) {
context.authenticatedUser();
DepositAccountData productData = new DepositAccountData();
ClientData clientAccount = this.clientReadPlatformService.retrieveIndividualClient(clientId);
DepositAccountData accountData = null;
Collection<DepositProductLookup> depositProducts = this.depositProductReadPlatformService.retrieveAllDepositProductsForLookup();
productData.setAllowedProducts(new ArrayList<DepositProductLookup>(depositProducts));
if (productId != null) {
DepositProductData selectedProduct = findDepositProductById(depositProducts,productId);
productData.setProductId(selectedProduct.getId());
productData.setProductName(selectedProduct.getName());
productData.setSelectedProduct(selectedProduct);
CurrencyData currency = new CurrencyData(selectedProduct.getCurrencyCode(), "", selectedProduct.getDigitsAfterDecimal(), "", "");
accountData = new DepositAccountData(
clientAccount.getId(), clientAccount.getDisplayName(), selectedProduct.getId(), selectedProduct.getName(),
currency, selectedProduct.getMinimumBalance(), selectedProduct.getMaturityDefaultInterestRate(),
selectedProduct.getTenureInMonths(), selectedProduct.getInterestCompoundedEvery(), selectedProduct.getInterestCompoundedEveryPeriodType(),
selectedProduct.isRenewalAllowed(), selectedProduct.isPreClosureAllowed(),
selectedProduct.getPreClosureInterestRate());
} else {
accountData = DepositAccountData.createFrom(clientAccount.getId(), clientAccount.getDisplayName());
}
ClientData clientAccount = this.clientReadPlatformService.retrieveIndividualClient(clientId);
productData.setClientId(clientAccount.getId());
productData.setClientName(clientAccount.getDisplayName());
return productData;
return accountData;
}
private DepositProductData findDepositProductById(
Collection<DepositProductLookup> depositProducts, Long productId) {
final Collection<DepositProductLookup> depositProducts,
final Long productId) {
DepositProductData match= this.depositProductReadPlatformService.retrieveNewDepositProductDetails();
for(DepositProductLookup depositProductLookup : depositProducts){
if (depositProductLookup.getId().equals(productId)) {