diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java index e16399eb6..c05c251a6 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java @@ -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 typicalResponseParameters = new HashSet( - 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 responseParameters, final DepositAccountData account) { - responseParameters.addAll(Arrays.asList("currencyOptions", "interestCompoundedEveryPeriodTypeOptions")); - List allowedCurrencies = this.currencyReadPlatformService.retrieveAllowedCurrencies(); + responseParameters.addAll(Arrays.asList("interestCompoundedEveryPeriodTypeOptions", "productOptions")); + + Collection productOptions = depositProductReadPlatformService.retrieveAllDepositProductsForLookup(); EnumOptionData monthly = SavingsDepositEnumerations.interestCompoundingPeriodType(PeriodFrequencyType.MONTHS); List interestCompoundedEveryPeriodTypeOptions = Arrays.asList(monthly); - return new DepositAccountData(account, allowedCurrencies, interestCompoundedEveryPeriodTypeOptions); + return new DepositAccountData(account, interestCompoundedEveryPeriodTypeOptions, productOptions); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java index 3ff2192b4..04e094220 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositAccountData.java @@ -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 currencyOptions; private final List interestCompoundedEveryPeriodTypeOptions; - private List allowedProducts = new ArrayList(); - private DepositProductData selectedProduct; - - public DepositAccountData() { - this.createdOn = null; - this.lastModifedOn = null; - this.id = null; + private final List 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(); this.interestCompoundedEveryPeriodTypeOptions = new ArrayList(); + this.productOptions = new ArrayList(); } - - public DepositAccountData(final DepositAccountData account, final List currencies, final List interestCompoundedEveryPeriodTypeOptions) { + + public DepositAccountData( + final DepositAccountData account, + final List interestCompoundedEveryPeriodTypeOptions, + final Collection 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(productOptions); } public DepositAccountData( @@ -162,8 +173,51 @@ public class DepositAccountData { this.preClosureAllowed = preClosureAllowed; this.preClosureInterestRate = preClosureInterestRate; - this.currencyOptions = new ArrayList(); this.interestCompoundedEveryPeriodTypeOptions = new ArrayList(); + this.productOptions = new ArrayList(); + } + + 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(); + this.productOptions = new ArrayList(); } public Long getId() { @@ -266,44 +320,11 @@ public class DepositAccountData { return lastModifedOn; } - public List getCurrencyOptions() { - return currencyOptions; - } - public List getInterestCompoundedEveryPeriodTypeOptions() { return interestCompoundedEveryPeriodTypeOptions; } - public List getAllowedProducts() { - return allowedProducts; + public List getProductOptions() { + return productOptions; } - - public void setAllowedProducts(List 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; - } - } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java index e48f78ea9..ef978aec8 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java @@ -1719,12 +1719,12 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService { final DepositAccountData... accounts) { Set supportedParameters = new HashSet( - 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" ) ); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java index 939c54fa9..458d84380 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformServiceImpl.java @@ -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 depositProducts = this.depositProductReadPlatformService.retrieveAllDepositProductsForLookup(); - productData.setAllowedProducts(new ArrayList(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 depositProducts, Long productId) { + final Collection depositProducts, + final Long productId) { DepositProductData match= this.depositProductReadPlatformService.retrieveNewDepositProductDetails(); for(DepositProductLookup depositProductLookup : depositProducts){ if (depositProductLookup.getId().equals(productId)) {