From 8f70265337e5f17b97e71d81c868d3e55ac4f9e7 Mon Sep 17 00:00:00 2001 From: madhukar Date: Fri, 10 Aug 2012 14:40:03 +0530 Subject: [PATCH] Retrieveing Deposit Product,Basic Validation --- .../platform/DataValidatorBuilder.java | 12 +++ .../api/DepositProductsApiResource.java | 9 ++- .../platform/api/data/DepositProductData.java | 77 ++++++++++++++++++- .../ApiDataConversionServiceImpl.java | 7 +- .../DepositProductCommandValidator.java | 10 +++ ...DepositProductReadPlatformServiceImpl.java | 22 +++++- 6 files changed, 125 insertions(+), 12 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/DataValidatorBuilder.java b/mifosng-provider/src/main/java/org/mifosng/platform/DataValidatorBuilder.java index 03e58b859..ce15c6fe5 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/DataValidatorBuilder.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/DataValidatorBuilder.java @@ -264,4 +264,16 @@ public class DataValidatorBuilder { } return this; } + public DataValidatorBuilder comapareMinAndMaxOfTwoBigDecmimalNos(BigDecimal min,BigDecimal max){ + if(min!=null&&max!=null) + if(max.compareTo(min)==-1){ + StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".min.number.should.lessthan.max.number"); + StringBuilder defaultEnglishMessage = new StringBuilder("The ").append(" min number ").append(min).append(" should less than max number ").append(max).append("."); + ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, min, max); + dataValidationErrors.add(error); + return this; + } + return this; + } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositProductsApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositProductsApiResource.java index 656f4124f..72c49fc8d 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositProductsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositProductsApiResource.java @@ -83,7 +83,8 @@ public class DepositProductsApiResource { @Produces({MediaType.APPLICATION_JSON}) public String retrieveAllDepositProducts(@Context final UriInfo uriInfo){ Set typicalResponseParameters = new HashSet(Arrays.asList("id", "name", "description", "createdOn", "lastModifedOn", - "currencyCode","digitsAfterDecimal","minimumBalance","maximumBalance")); + "currencyCode","digitsAfterDecimal","minimumBalance","maximumBalance","tenureMonths","maturityDefaultInterestRate","maturityMinInterestRate", + "maturityMaxInterestRate","canRenew","canPreClose","preClosureInterestRate")); Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); if (responseParameters.isEmpty()) { @@ -101,7 +102,8 @@ public class DepositProductsApiResource { @Produces({MediaType.APPLICATION_JSON}) public String retrieveDepositProductDetails(@PathParam("productId") final Long productId, @Context final UriInfo uriInfo){ Set typicalResponseParameters = new HashSet(Arrays.asList("id", "name", "description", "createdOn", "lastModifedOn", - "currencyCode","digitsAfterDecimal","minimumBalance","maximumBalance")); + "currencyCode","digitsAfterDecimal","minimumBalance","maximumBalance","tenureMonths","maturityDefaultInterestRate","maturityMinInterestRate", + "maturityMaxInterestRate","canRenew","canPreClose","preClosureInterestRate")); Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); if (responseParameters.isEmpty()) { @@ -123,7 +125,8 @@ public class DepositProductsApiResource { public String retrieveNewDepositProductDetails(@Context final UriInfo uriInfo) { Set typicalResponseParameters = new HashSet( - Arrays.asList("id", "name", "description", "createdOn", "lastModifedOn","currencyCode","digitsAfterDecimal", "currencyOptions","minimumBalance","maximumBalance")); + Arrays.asList("id", "name", "description", "createdOn", "lastModifedOn","currencyCode","digitsAfterDecimal", "currencyOptions","minimumBalance","maximumBalance","tenureMonths","maturityDefaultInterestRate","maturityMinInterestRate", + "maturityMaxInterestRate","canRenew","canPreClose","preClosureInterestRate")); Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); if (responseParameters.isEmpty()) { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositProductData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositProductData.java index 1d6cc14ca..d3de27957 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositProductData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/DepositProductData.java @@ -21,13 +21,23 @@ public class DepositProductData implements Serializable { private DateTime createdOn; private DateTime lastModifedOn; + private Integer tenureMonths; + private BigDecimal maturityDefaultInterestRate = BigDecimal.ZERO; + private BigDecimal maturityMinInterestRate = BigDecimal.ZERO; + private BigDecimal maturityMaxInterestRate = BigDecimal.ZERO; + private Boolean canRenew; + private Boolean canPreClose; + private BigDecimal preClosureInterestRate = BigDecimal.ZERO; + private List currencyOptions = new ArrayList(); public DepositProductData() { // TODO Auto-generated constructor stub } - public DepositProductData(DateTime createdOn, DateTime lastModifedOn, Long id,String name, String description, String currencyCode, Integer digitsAfterDecimal,BigDecimal minimumBalance,BigDecimal maximumBalance) { + public DepositProductData(DateTime createdOn, DateTime lastModifedOn, Long id,String name, String description, String currencyCode, Integer digitsAfterDecimal,BigDecimal minimumBalance,BigDecimal maximumBalance, + Integer tenureMonths, BigDecimal maturityDefaultInterestRate, BigDecimal maturityMinInterestRate, BigDecimal maturityMaxInterestRate, + Boolean canRenew, Boolean canPreClose, BigDecimal preClosureInterestRate) { this.createdOn=createdOn; this.lastModifedOn=lastModifedOn; @@ -38,6 +48,14 @@ public class DepositProductData implements Serializable { this.digitsAfterDecimal=digitsAfterDecimal; this.minimumBalance=minimumBalance; this.maximumBalance=maximumBalance; + + this.tenureMonths=tenureMonths; + this.maturityDefaultInterestRate = maturityDefaultInterestRate; + this.maturityMinInterestRate=maturityMinInterestRate; + this.maturityMaxInterestRate=maturityMaxInterestRate; + this.canRenew=canRenew; + this.canPreClose=canPreClose; + this.preClosureInterestRate=preClosureInterestRate; } @@ -121,4 +139,61 @@ public class DepositProductData implements Serializable { public void setCurrencyOptions(List currencyOptions) { this.currencyOptions = currencyOptions; } + + public Integer getTenureMonths() { + return tenureMonths; + } + + public void setTenureMonths(Integer tenureMonths) { + this.tenureMonths = tenureMonths; + } + + public BigDecimal getMaturityDefaultInterestRate() { + return maturityDefaultInterestRate; + } + + public void setMaturityDefaultInterestRate( + BigDecimal maturityDefaultInterestRate) { + this.maturityDefaultInterestRate = maturityDefaultInterestRate; + } + + public BigDecimal getMaturityMinInterestRate() { + return maturityMinInterestRate; + } + + public void setMaturityMinInterestRate(BigDecimal maturityMinInterestRate) { + this.maturityMinInterestRate = maturityMinInterestRate; + } + + public BigDecimal getMaturityMaxInterestRate() { + return maturityMaxInterestRate; + } + + public void setMaturityMaxInterestRate(BigDecimal maturityMaxInterestRate) { + this.maturityMaxInterestRate = maturityMaxInterestRate; + } + + public Boolean getCanRenew() { + return canRenew; + } + + public void setCanRenew(Boolean canRenew) { + this.canRenew = canRenew; + } + + public Boolean getCanPreClose() { + return canPreClose; + } + + public void setCanPreClose(Boolean canPreClose) { + this.canPreClose = canPreClose; + } + + public BigDecimal getPreClosureInterestRate() { + return preClosureInterestRate; + } + + public void setPreClosureInterestRate(BigDecimal preClosureInterestRate) { + this.preClosureInterestRate = preClosureInterestRate; + } } 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 8e6435b33..82c359e5d 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 @@ -1589,10 +1589,9 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService { public String convertDepositProductDataToJson(boolean prettyPrint, Set responseParameters, DepositProductData... products) { - Set supportedParameters = new HashSet( - Arrays.asList("id", "name", "description","createdOn", "lastModifedOn","currencyCode","digitsAfterDecimal", "currencyOptions", - "minimumBalance","maximumBalance")); - + Set supportedParameters = new HashSet(Arrays.asList("id", "name", "description","createdOn", "lastModifedOn","currencyCode","digitsAfterDecimal", "currencyOptions", "minimumBalance","maximumBalance","tenureMonths","maturityDefaultInterestRate","maturityMinInterestRate", + "maturityMaxInterestRate","canRenew","canPreClose","preClosureInterestRate")); + final Set parameterNamesToSkip = new HashSet(); if (!responseParameters.isEmpty()) { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/depositproduct/service/DepositProductCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/depositproduct/service/DepositProductCommandValidator.java index a724da906..9b5d0b09c 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/depositproduct/service/DepositProductCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/depositproduct/service/DepositProductCommandValidator.java @@ -43,6 +43,12 @@ public class DepositProductCommandValidator { baseDataValidator.reset().parameter("preClosureInterestRate").value(command.getPreClosureInterestRate()).zeroOrPositiveAmount(); baseDataValidator.reset().comapareMinimumAndMaximumAmounts(command.getMinimumBalance(), command.getMaximumBalance()); + baseDataValidator.reset().comapareMinAndMaxOfTwoBigDecmimalNos(command.getMaturityMinInterestRate(), command.getMaturityMaxInterestRate()); + baseDataValidator.reset().comapareMinAndMaxOfTwoBigDecmimalNos(command.getMaturityDefaultInterestRate(), command.getMaturityMaxInterestRate()); + baseDataValidator.reset().comapareMinAndMaxOfTwoBigDecmimalNos(command.getMaturityMinInterestRate(), command.getMaturityDefaultInterestRate()); + baseDataValidator.reset().comapareMinAndMaxOfTwoBigDecmimalNos(command.getPreClosureInterestRate(), command.getMaturityMinInterestRate()); + + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); @@ -78,6 +84,10 @@ public class DepositProductCommandValidator { baseDataValidator.reset().parameter("preClosureInterestRate").value(command.getPreClosureInterestRate()).zeroOrPositiveAmount(); baseDataValidator.reset().comapareMinimumAndMaximumAmounts(command.getMinimumBalance(), command.getMaximumBalance()); + baseDataValidator.reset().comapareMinAndMaxOfTwoBigDecmimalNos(command.getMaturityMinInterestRate(), command.getMaturityMaxInterestRate()); + baseDataValidator.reset().comapareMinAndMaxOfTwoBigDecmimalNos(command.getMaturityDefaultInterestRate(), command.getMaturityMaxInterestRate()); + baseDataValidator.reset().comapareMinAndMaxOfTwoBigDecmimalNos(command.getMaturityMinInterestRate(), command.getMaturityDefaultInterestRate()); + baseDataValidator.reset().comapareMinAndMaxOfTwoBigDecmimalNos(command.getPreClosureInterestRate(), command.getMaturityMinInterestRate()); baseDataValidator.reset().anyOfNotNull(command.getName(), command.getDescription(),command.getCurrencyCode(),command.getDigitsAfterDecimal(),command.getMinimumBalance(),command.getMaximumBalance(),command.getTenureMonths(),command.getMaturityDefaultInterestRate(),command.getMaturityMaxInterestRate(),command.getMaturityMinInterestRate(),command.getCanRenew(),command.getCanPreClose(),command.getPreClosureInterestRate()); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/depositproduct/service/DepositProductReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/depositproduct/service/DepositProductReadPlatformServiceImpl.java index 001fdcc6d..178da3303 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/depositproduct/service/DepositProductReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/depositproduct/service/DepositProductReadPlatformServiceImpl.java @@ -38,7 +38,7 @@ public class DepositProductReadPlatformServiceImpl implements public Collection retrieveAllDepositProducts() { this.context.authenticatedUser(); DepositProductMapper depositProductMapper= new DepositProductMapper(); - String sql= "select " + depositProductMapper.depositProductSchema() + " where dp.is_deleted=0"; + String sql="select "+depositProductMapper.depositProductSchema() + " where dp.is_deleted=0"; return this.jdbcTemplate.query(sql,depositProductMapper, new Object[]{}); } @@ -70,7 +70,9 @@ public class DepositProductReadPlatformServiceImpl implements private static final class DepositProductMapper implements RowMapper{ public String depositProductSchema(){ - return "dp.id as id,dp.name as name, dp.description as description,dp.currency_code as currencyCode, dp.currency_digits as currencyDigits,dp.minimum_balance as minimumBalance,dp.maximum_balance as maximumBalance,dp.created_date as createdon, dp.lastmodified_date as modifiedon, " + + return "dp.id as id,dp.name as name, dp.description as description,dp.currency_code as currencyCode, dp.currency_digits as currencyDigits,dp.minimum_balance as minimumBalance,dp.maximum_balance as maximumBalance," + + "dp.created_date as createdon, dp.lastmodified_date as modifiedon,dp.tenure_months as tenureMonths, dp.maturity_default_interest_rate as maturityDefaultInterestRate, " + + "dp.maturity_min_interest_rate as maturityMinInterestRate, dp.maturity_max_interest_rate as maturityMaxInterestRate, dp.can_renew as canRenew, dp.can_pre_close as canPreClose, dp.pre_closure_interest_rate as preClosureInterestRate, " + "curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, curr.display_symbol as currencyDisplaySymbol " + "from portfolio_product_deposit dp join ref_currency curr on curr.code = dp.currency_code "; } @@ -91,7 +93,19 @@ public class DepositProductReadPlatformServiceImpl implements BigDecimal minimumBalance=rs.getBigDecimal("minimumBalance"); BigDecimal maximumBalance=rs.getBigDecimal("maximumBalance"); - return new DepositProductData(createdOn, lastModifedOn, id, name, description, currencyCode, currencyDigits, minimumBalance, maximumBalance); + + Integer tenureMonths = JdbcSupport.getInteger(rs, "tenureMonths"); + BigDecimal maturityDefaultInterestRate=rs.getBigDecimal("maturityDefaultInterestRate"); + BigDecimal maturityMinInterestRate= rs.getBigDecimal("maturityMinInterestRate"); + BigDecimal maturityMaxInterestRate = rs.getBigDecimal("maturityMaxInterestRate"); + + Boolean canRenew = rs.getBoolean("canRenew"); + Boolean canPreClose=rs.getBoolean("canPreClose"); + + BigDecimal preClosureInterestRate=rs.getBigDecimal("preClosureInterestRate"); + + return new DepositProductData(createdOn, lastModifedOn, id, name, description, currencyCode, currencyDigits, minimumBalance, maximumBalance, + tenureMonths, maturityDefaultInterestRate,maturityMinInterestRate,maturityMaxInterestRate,canRenew,canPreClose,preClosureInterestRate); } } @@ -118,4 +132,4 @@ public class DepositProductReadPlatformServiceImpl implements List currencyOptions = currencyReadPlatformService.retrieveAllowedCurrencies(); productData.setCurrencyOptions(currencyOptions); } -} \ No newline at end of file +}