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 79fdb4e0c..e16399eb6 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 @@ -14,6 +14,7 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -135,14 +136,17 @@ public class DepositAccountsApiResource { @Path("template") @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) - public String retrieveNewDepositAccountDetails(@Context final UriInfo uriInfo) { + public String retrieveNewDepositAccountDetails( + @QueryParam("clientId") final Long clientId, + @QueryParam("productId") final Long productId, + @Context final UriInfo uriInfo) { Set typicalResponseParameters = new HashSet( Arrays.asList("currencyOptions", "interestCompoundedEveryPeriodTypeOptions", "createdOn", "lastModifedOn", "id", "externalId", "clientId", "clientName", "productId", "productName", "currency", "deposit", "maturityInterestRate", "tenureInMonths", "interestCompoundedEvery", "interestCompoundedEveryPeriodType", - "renewalAllowed","preClosureAllowed","preClosureInterestRate" + "renewalAllowed","preClosureAllowed","preClosureInterestRate","allowedProducts" ) ); @@ -152,7 +156,7 @@ public class DepositAccountsApiResource { } boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); - DepositAccountData account = this.depositAccountReadPlatformService.retrieveNewDepositAccountDetails(); + DepositAccountData account = this.depositAccountReadPlatformService.retrieveNewDepositAccountDetails(clientId,productId); account = handleTemplateRelatedData(responseParameters, account); 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 1d7da720c..3ff2192b4 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 @@ -14,11 +14,11 @@ public class DepositAccountData { private final Long id; private final String externalId; - private final Long clientId; - private final String clientName; + private Long clientId; + private String clientName; - private final Long productId; - private final String productName; + private Long productId; + private String productName; private final CurrencyData currency; private final BigDecimal deposit; @@ -45,6 +45,9 @@ public class DepositAccountData { private final List currencyOptions; private final List interestCompoundedEveryPeriodTypeOptions; + + private List allowedProducts = new ArrayList(); + private DepositProductData selectedProduct; public DepositAccountData() { this.createdOn = null; @@ -270,4 +273,37 @@ public class DepositAccountData { public List getInterestCompoundedEveryPeriodTypeOptions() { return interestCompoundedEveryPeriodTypeOptions; } + + public List getAllowedProducts() { + return allowedProducts; + } + + 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 7ffbe24ba..e48f78ea9 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 @@ -1724,7 +1724,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService { "id", "externalId", "clientId", "clientName", "productId", "productName", "currency", "deposit", "maturityInterestRate", "tenureInMonths", "interestCompoundedEvery", "interestCompoundedEveryPeriodType", - "renewalAllowed","preClosureAllowed","preClosureInterestRate" + "renewalAllowed","preClosureAllowed","preClosureInterestRate","allowedProducts" ) ); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformService.java index eef634b6a..58ca8353c 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountReadPlatformService.java @@ -10,5 +10,5 @@ public interface DepositAccountReadPlatformService { DepositAccountData retrieveDepositAccount(Long accountId); - DepositAccountData retrieveNewDepositAccountDetails(); + DepositAccountData retrieveNewDepositAccountDetails(Long clientId, Long productId); } 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 658ef8324..939c54fa9 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,16 +3,23 @@ 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; +import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.CurrencyData; import org.mifosng.platform.api.data.DepositAccountData; +import org.mifosng.platform.api.data.DepositProductData; +import org.mifosng.platform.api.data.DepositProductLookup; import org.mifosng.platform.api.data.EnumOptionData; +import org.mifosng.platform.client.service.ClientReadPlatformService; import org.mifosng.platform.exceptions.LoanProductNotFoundException; import org.mifosng.platform.infrastructure.JdbcSupport; import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource; +import org.mifosng.platform.savingproduct.service.DepositProductReadPlatformService; import org.mifosng.platform.savingproduct.service.SavingsDepositEnumerations; import org.mifosng.platform.security.PlatformSecurityContext; import org.springframework.beans.factory.annotation.Autowired; @@ -26,11 +33,15 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead private final PlatformSecurityContext context; private final JdbcTemplate jdbcTemplate; + private final DepositProductReadPlatformService depositProductReadPlatformService; + private final ClientReadPlatformService clientReadPlatformService; @Autowired - public DepositAccountReadPlatformServiceImpl(final PlatformSecurityContext context,final TenantAwareRoutingDataSource dataSource) { + public DepositAccountReadPlatformServiceImpl(final PlatformSecurityContext context,final TenantAwareRoutingDataSource dataSource, final DepositProductReadPlatformService depositProductReadPlatformService,final ClientReadPlatformService clientReadPlatformService) { this.context=context; jdbcTemplate=new JdbcTemplate(dataSource); + this.depositProductReadPlatformService=depositProductReadPlatformService; + this.clientReadPlatformService=clientReadPlatformService; } @Override @@ -63,13 +74,41 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead } @Override - public DepositAccountData retrieveNewDepositAccountDetails() { - + public DepositAccountData retrieveNewDepositAccountDetails(final Long clientId, final Long productId) { + context.authenticatedUser(); DepositAccountData productData = new DepositAccountData(); + 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); + + } + + ClientData clientAccount = this.clientReadPlatformService.retrieveIndividualClient(clientId); + productData.setClientId(clientAccount.getId()); + productData.setClientName(clientAccount.getDisplayName()); + return productData; } - + + private DepositProductData findDepositProductById( + Collection depositProducts, Long productId) { + DepositProductData match= this.depositProductReadPlatformService.retrieveNewDepositProductDetails(); + for(DepositProductLookup depositProductLookup : depositProducts){ + if (depositProductLookup.getId().equals(productId)) { + match=this.depositProductReadPlatformService.retrieveDepositProductData(depositProductLookup.getId()); + break; + } + } + return match; + } + private static final class DepositAccountMapper implements RowMapper { public String schema() {