Changes made for populating client name, available products

This commit is contained in:
madhukar
2012-08-17 18:14:40 +05:30
parent 440205fdfa
commit 88e4c4ec00
5 changed files with 92 additions and 13 deletions
@@ -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<String> typicalResponseParameters = new HashSet<String>(
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);
@@ -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<CurrencyData> currencyOptions;
private final List<EnumOptionData> interestCompoundedEveryPeriodTypeOptions;
private List<DepositProductLookup> allowedProducts = new ArrayList<DepositProductLookup>();
private DepositProductData selectedProduct;
public DepositAccountData() {
this.createdOn = null;
@@ -270,4 +273,37 @@ public class DepositAccountData {
public List<EnumOptionData> getInterestCompoundedEveryPeriodTypeOptions() {
return interestCompoundedEveryPeriodTypeOptions;
}
public List<DepositProductLookup> getAllowedProducts() {
return allowedProducts;
}
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;
}
}
@@ -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"
)
);
@@ -10,5 +10,5 @@ public interface DepositAccountReadPlatformService {
DepositAccountData retrieveDepositAccount(Long accountId);
DepositAccountData retrieveNewDepositAccountDetails();
DepositAccountData retrieveNewDepositAccountDetails(Long clientId, Long productId);
}
@@ -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<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);
}
ClientData clientAccount = this.clientReadPlatformService.retrieveIndividualClient(clientId);
productData.setClientId(clientAccount.getId());
productData.setClientName(clientAccount.getDisplayName());
return productData;
}
private DepositProductData findDepositProductById(
Collection<DepositProductLookup> 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<DepositAccountData> {
public String schema() {