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 fb1c44409..385253e79 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 @@ -23,9 +23,12 @@ 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.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.deposit.domain.SavingsDepositEnumerations; +import org.mifosng.platform.loan.domain.PeriodFrequencyType; import org.mifosng.platform.savingproduct.service.DepositAccountReadPlatformService; import org.mifosng.platform.savingproduct.service.DepositAccountWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; @@ -106,8 +109,10 @@ public class DepositAccountsApiResource { Set typicalResponseParameters = new HashSet( Arrays.asList("createdOn", "lastModifedOn", - "id", "clientId", "clientName", "productId", "productName", - "currency", "deposit", "maturityInterestRate") + "id", "externalId", "clientId", "clientName", "productId", "productName", + "currency", "deposit", "maturityInterestRate", "tenureInMonths", "interestCompoundedEvery", "interestCompoundedEveryPeriodType", + "renewalAllowed","preClosureAllowed","preClosureInterestRate" + ) ); Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); @@ -120,14 +125,12 @@ public class DepositAccountsApiResource { boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); if (template) { - responseParameters.addAll(Arrays.asList("currencyOptions")); - List allowedCurrencies = this.currencyReadPlatformService.retrieveAllowedCurrencies(); - account = new DepositAccountData(account, allowedCurrencies); + account = handleTemplateRelatedData(responseParameters, account); } return this.apiDataConversionService.convertDepositAccountDataToJson(prettyPrint, responseParameters, account); } - + @GET @Path("template") @Consumes({MediaType.APPLICATION_JSON}) @@ -135,9 +138,12 @@ public class DepositAccountsApiResource { public String retrieveNewDepositAccountDetails(@Context final UriInfo uriInfo) { Set typicalResponseParameters = new HashSet( - Arrays.asList("createdOn", "lastModifedOn", - "id", "clientId", "clientName", "productId", "productName", - "currency", "deposit", "maturityInterestRate", "currencyOptions") + Arrays.asList("currencyOptions", "interestCompoundedEveryPeriodTypeOptions", + "createdOn", "lastModifedOn", + "id", "externalId", "clientId", "clientName", "productId", "productName", + "currency", "deposit", "maturityInterestRate", "tenureInMonths", "interestCompoundedEvery", "interestCompoundedEveryPeriodType", + "renewalAllowed","preClosureAllowed","preClosureInterestRate" + ) ); Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters()); @@ -147,8 +153,8 @@ public class DepositAccountsApiResource { boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); DepositAccountData account = this.depositAccountReadPlatformService.retrieveNewDepositAccountDetails(); - List allowedCurrencies = this.currencyReadPlatformService.retrieveAllowedCurrencies(); - account = new DepositAccountData(account, allowedCurrencies); + + account = handleTemplateRelatedData(responseParameters, account); return this.apiDataConversionService.convertDepositAccountDataToJson(prettyPrint, responseParameters, account); } @@ -163,4 +169,17 @@ public class DepositAccountsApiResource { return Response.ok(new EntityIdentifier(accountId)).build(); } + + private DepositAccountData handleTemplateRelatedData( + final Set responseParameters, + final DepositAccountData account) { + + responseParameters.addAll(Arrays.asList("currencyOptions", "interestCompoundedEveryPeriodTypeOptions")); + List allowedCurrencies = this.currencyReadPlatformService.retrieveAllowedCurrencies(); + + EnumOptionData monthly = SavingsDepositEnumerations.interestCompoundingPeriodType(PeriodFrequencyType.MONTHS); + List interestCompoundedEveryPeriodTypeOptions = Arrays.asList(monthly); + + return new DepositAccountData(account, allowedCurrencies, interestCompoundedEveryPeriodTypeOptions); + } } \ 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 62698d5b0..f9458bb0f 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 @@ -3,6 +3,7 @@ package org.mifosng.platform.api; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Set; import javax.ws.rs.Consumes; @@ -19,12 +20,17 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import org.mifosng.platform.api.commands.DepositProductCommand; +import org.mifosng.platform.api.data.CurrencyData; import org.mifosng.platform.api.data.DepositProductData; 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.deposit.domain.SavingsDepositEnumerations; import org.mifosng.platform.depositproduct.service.DepositProductReadPlatformService; import org.mifosng.platform.depositproduct.service.DepositProductWritePlatformService; +import org.mifosng.platform.loan.domain.PeriodFrequencyType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -37,6 +43,9 @@ public class DepositProductsApiResource { @Autowired private DepositProductReadPlatformService depositProductReadPlatformService; + @Autowired + private CurrencyReadPlatformService currencyReadPlatformService; + @Autowired private DepositProductWritePlatformService depositProductWritePlatformService; @@ -117,13 +126,14 @@ public class DepositProductsApiResource { responseParameters.addAll(typicalResponseParameters); } boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); - boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); - if (template) { - responseParameters.addAll(Arrays.asList("currencyOptions", "interestCompoundedEveryPeriodTypeOptions")); - } DepositProductData productData = this.depositProductReadPlatformService.retrieveDepositProductData(productId); + boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); + if (template) { + productData = handleTemplateRelatedData(responseParameters, productData); + } + return this.apiDataConversionService.convertDepositProductDataToJson(prettyPrint, responseParameters, productData); } @@ -149,6 +159,21 @@ public class DepositProductsApiResource { DepositProductData depositProduct = this.depositProductReadPlatformService.retrieveNewDepositProductDetails(); + depositProduct = handleTemplateRelatedData(responseParameters, depositProduct); + return this.apiDataConversionService.convertDepositProductDataToJson(prettyPrint, responseParameters, depositProduct); - } + } + + private DepositProductData handleTemplateRelatedData( + final Set responseParameters, + final DepositProductData productData) { + + responseParameters.addAll(Arrays.asList("currencyOptions", "interestCompoundedEveryPeriodTypeOptions")); + List allowedCurrencies = this.currencyReadPlatformService.retrieveAllowedCurrencies(); + + EnumOptionData monthly = SavingsDepositEnumerations.interestCompoundingPeriodType(PeriodFrequencyType.MONTHS); + List interestCompoundedEveryPeriodTypeOptions = Arrays.asList(monthly); + + return new DepositProductData(productData, allowedCurrencies, interestCompoundedEveryPeriodTypeOptions); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositAccountCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositAccountCommand.java index ef1861e55..28dbf438e 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositAccountCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositAccountCommand.java @@ -17,7 +17,7 @@ public class DepositAccountCommand { private final BigDecimal depositAmount; private final BigDecimal maturityInterestRate; - private final Integer termInMonths; + private final Integer tenureInMonths; private final Integer interestCompoundedEvery; private final Integer interestCompoundedEveryPeriodType; @@ -35,7 +35,7 @@ public class DepositAccountCommand { final String externalId, final BigDecimal depositAmount, final BigDecimal interestRate, - final Integer termInMonths, final Integer compoundingInterestFrequency, final Integer compoundingInterestFrequencyType, final LocalDate commencementDate, + final Integer tenureInMonths, final Integer compoundingInterestFrequency, final Integer compoundingInterestFrequencyType, final LocalDate commencementDate, final boolean renewalAllowed, final boolean preClosureAllowed) { this.id = id; this.clientId = clientId; @@ -44,7 +44,7 @@ public class DepositAccountCommand { this.depositAmount = depositAmount; this.maturityInterestRate = interestRate; - this.termInMonths = termInMonths; + this.tenureInMonths = tenureInMonths; this.modifiedParameters = modifiedParameters; this.interestCompoundedEvery = compoundingInterestFrequency; @@ -77,11 +77,11 @@ public class DepositAccountCommand { public BigDecimal getMaturityInterestRate() { return maturityInterestRate; } - - public Integer getTermInMonths() { - return termInMonths; - } + public Integer getTenureInMonths() { + return tenureInMonths; + } + public Integer getInterestCompoundedEvery() { return interestCompoundedEvery; } @@ -106,12 +106,8 @@ public class DepositAccountCommand { return this.modifiedParameters.isEmpty(); } - public boolean isCurrencyCodeChanged() { - return this.modifiedParameters.contains("currencyCode"); - } - - public boolean isDigitsAfterDecimalChanged() { - return this.modifiedParameters.contains("digitsAfterDecimal"); + public boolean isTenureInMonthsChanged() { + return this.modifiedParameters.contains("tenureInMonths"); } public boolean isMaturityActualInterestRateChanged() { 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 7aadb10a8..1d7da720c 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 @@ -77,7 +77,7 @@ public class DepositAccountData { this.interestCompoundedEveryPeriodTypeOptions = new ArrayList(); } - public DepositAccountData(final DepositAccountData account, final List currencies) { + public DepositAccountData(final DepositAccountData account, final List currencies, final List interestCompoundedEveryPeriodTypeOptions) { this.createdOn = account.getCreatedOn(); this.lastModifedOn = account.getLastModifedOn(); this.id = account.getId(); @@ -105,7 +105,7 @@ public class DepositAccountData { this.preClosureInterestRate = account.getPreClosureInterestRate(); this.currencyOptions = currencies; - this.interestCompoundedEveryPeriodTypeOptions = new ArrayList(); + this.interestCompoundedEveryPeriodTypeOptions = interestCompoundedEveryPeriodTypeOptions; } public DepositAccountData( diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/deposit/domain/DepositProduct.java b/mifosng-provider/src/main/java/org/mifosng/platform/deposit/domain/DepositProduct.java index 6cbd84422..dac083ce5 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/deposit/domain/DepositProduct.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/deposit/domain/DepositProduct.java @@ -45,15 +45,12 @@ public class DepositProduct extends AbstractAuditableCustom { @Column(name = "maximum_balance", scale = 6, precision = 19, nullable = false) private BigDecimal maximumBalance; - @SuppressWarnings("unused") @Column(name = "interest_compounded_every", nullable=false) private Integer interestCompoundedEvery; - @SuppressWarnings("unused") @Column(name = "interest_compounded_every_period_enum", nullable=false) private PeriodFrequencyType interestCompoundedEveryPeriodType; - @SuppressWarnings("unused") @Column(name = "maturity_default_interest_rate", scale = 6, precision = 19, nullable = false) private BigDecimal maturityDefaultInterestRate; @@ -63,7 +60,6 @@ public class DepositProduct extends AbstractAuditableCustom { @Column(name = "maturity_max_interest_rate", scale = 6, precision = 19, nullable = false) private BigDecimal maturityMaxInterestRate; - @SuppressWarnings("unused") @Column(name = "tenure_months", nullable=false) private Integer tenureInMonths; @@ -122,6 +118,22 @@ public class DepositProduct extends AbstractAuditableCustom { public MonetaryCurrency getCurrency() { return currency; } + + public Integer getInterestCompoundedEvery() { + return interestCompoundedEvery; + } + + public PeriodFrequencyType getInterestCompoundedEveryPeriodType() { + return interestCompoundedEveryPeriodType; + } + + public Integer getTenureInMonths() { + return tenureInMonths; + } + + public BigDecimal getMaturityDefaultInterestRate() { + return maturityDefaultInterestRate; + } public boolean isRenewalAllowed() { return this.renewalAllowed; 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 e16ec5c30..683d96b19 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 @@ -3,7 +3,6 @@ package org.mifosng.platform.depositproduct.service; import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -12,7 +11,6 @@ import org.mifosng.platform.api.data.CurrencyData; 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.currency.service.CurrencyReadPlatformService; import org.mifosng.platform.deposit.domain.SavingsDepositEnumerations; import org.mifosng.platform.infrastructure.JdbcSupport; import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource; @@ -24,18 +22,15 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Service; @Service -public class DepositProductReadPlatformServiceImpl implements - DepositProductReadPlatformService { +public class DepositProductReadPlatformServiceImpl implements DepositProductReadPlatformService { private final PlatformSecurityContext context; private final JdbcTemplate jdbcTemplate; - private final CurrencyReadPlatformService currencyReadPlatformService; @Autowired - public DepositProductReadPlatformServiceImpl(final PlatformSecurityContext context,final TenantAwareRoutingDataSource dataSource,final CurrencyReadPlatformService currencyReadPlatformService) { + public DepositProductReadPlatformServiceImpl(final PlatformSecurityContext context,final TenantAwareRoutingDataSource dataSource) { this.context=context; jdbcTemplate=new JdbcTemplate(dataSource); - this.currencyReadPlatformService=currencyReadPlatformService; } @Override @@ -59,21 +54,15 @@ public class DepositProductReadPlatformServiceImpl implements DepositProductMapper depositProductMapper=new DepositProductMapper(); String sql = "select "+ depositProductMapper.depositProductSchema() +" where dp.id = ? and dp.is_deleted=0"; - DepositProductData productData = this.jdbcTemplate.queryForObject(sql, depositProductMapper, new Object[]{productId}); - - List currencyOptions = currencyReadPlatformService.retrieveAllowedCurrencies(); - EnumOptionData monthly = SavingsDepositEnumerations.interestCompoundingPeriodType(PeriodFrequencyType.MONTHS); - List interestCompoundedEveryPeriodTypeOptions = Arrays.asList(monthly); - - return new DepositProductData(productData, currencyOptions, interestCompoundedEveryPeriodTypeOptions); + return this.jdbcTemplate.queryForObject(sql, depositProductMapper, new Object[]{productId}); } @Override public DepositProductData retrieveNewDepositProductDetails() { - List currencyOptions = currencyReadPlatformService.retrieveAllowedCurrencies(); + List currencyOptions = null; + List interestCompoundedEveryPeriodTypeOptions = null; EnumOptionData monthly = SavingsDepositEnumerations.interestCompoundingPeriodType(PeriodFrequencyType.MONTHS); - List interestCompoundedEveryPeriodTypeOptions = Arrays.asList(monthly); return new DepositProductData(currencyOptions, monthly, interestCompoundedEveryPeriodTypeOptions); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/savingproduct/service/DepositAccountAssembler.java b/mifosng-provider/src/main/java/org/mifosng/platform/savingproduct/service/DepositAccountAssembler.java index d68101c63..215393743 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/savingproduct/service/DepositAccountAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/savingproduct/service/DepositAccountAssembler.java @@ -1,5 +1,7 @@ package org.mifosng.platform.savingproduct.service; +import java.math.BigDecimal; + import org.mifosng.platform.api.commands.DepositAccountCommand; import org.mifosng.platform.client.domain.Client; import org.mifosng.platform.client.domain.ClientRepository; @@ -40,15 +42,28 @@ public class DepositAccountAssembler { throw new DepositProductNotFoundException(command.getProductId()); } - // currency details inherited from product setting + // details inherited from product setting (unless allowed to be overridden through account creation api Money deposit = Money.of(product.getCurrency(), command.getDepositAmount()); - // default to months for now. - Integer interestCompoundingPeriodType = PeriodFrequencyType.MONTHS.getValue(); + Integer tenureInMonths = product.getTenureInMonths(); + if (command.getTenureInMonths() != null) { + tenureInMonths = command.getTenureInMonths(); + } + + BigDecimal maturityInterestRate = product.getMaturityDefaultInterestRate(); + if (command.getMaturityInterestRate() != null) { + maturityInterestRate = command.getMaturityInterestRate(); + } + + Integer compoundingInterestEvery = product.getInterestCompoundedEvery(); + if (command.getInterestCompoundedEvery() != null) { + compoundingInterestEvery = command.getInterestCompoundedEvery(); + } + + PeriodFrequencyType compoundingInterestFrequency = product.getInterestCompoundedEveryPeriodType(); if (command.getInterestCompoundedEveryPeriodType() != null) { - interestCompoundingPeriodType = command.getInterestCompoundedEveryPeriodType(); + compoundingInterestFrequency = PeriodFrequencyType.fromInt(command.getInterestCompoundedEveryPeriodType()); } - PeriodFrequencyType compoundingInterestFrequency = PeriodFrequencyType.fromInt(interestCompoundingPeriodType); boolean renewalAllowed = product.isRenewalAllowed(); if (command.isRenewalAllowedChanged()) { @@ -59,9 +74,13 @@ public class DepositAccountAssembler { if (command.isPreClosureAllowedChanged()) { preClosureAllowed = command.isPreClosureAllowed(); } + // end of details allowed to be overriden from product - DepositAccount account = DepositAccount.openNew(client, product, command.getExternalId(), deposit, command.getMaturityInterestRate(), - command.getTermInMonths(), command.getInterestCompoundedEvery(), compoundingInterestFrequency, command.getCommencementDate(), + DepositAccount account = DepositAccount.openNew(client, product, command.getExternalId(), + deposit, + maturityInterestRate, + tenureInMonths, compoundingInterestEvery, compoundingInterestFrequency, + command.getCommencementDate(), renewalAllowed, preClosureAllowed); return account; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/savingproduct/service/DepositAccountCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/savingproduct/service/DepositAccountCommandValidator.java index 317cb1bda..f268e1ceb 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/savingproduct/service/DepositAccountCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/savingproduct/service/DepositAccountCommandValidator.java @@ -29,7 +29,7 @@ public class DepositAccountCommandValidator { baseDataValidator.reset().parameter("depositAmount").value(command.getDepositAmount()).ignoreIfNull().notNull().integerGreaterThanZero(); baseDataValidator.reset().parameter("maturityInterestRate").value(command.getMaturityInterestRate()).ignoreIfNull().notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("termInMonths").value(command.getTermInMonths()).ignoreIfNull().notNull().integerGreaterThanZero(); + baseDataValidator.reset().parameter("tenureInMonths").value(command.getTenureInMonths()).ignoreIfNull().notNull().integerGreaterThanZero(); baseDataValidator.reset().parameter("interestCompoundedEvery").value(command.getInterestCompoundedEvery()).ignoreIfNull().integerGreaterThanZero(); baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(command.getInterestCompoundedEveryPeriodType()).ignoreIfNull().inMinMaxRange(2, 2); @@ -58,11 +58,11 @@ public class DepositAccountCommandValidator { baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100); baseDataValidator.reset().parameter("depositAmount").value(command.getDepositAmount()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("maturityInterestRate").value(command.getMaturityInterestRate()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("termInMonths").value(command.getTermInMonths()).notNull().integerGreaterThanZero(); + baseDataValidator.reset().parameter("maturityInterestRate").value(command.getMaturityInterestRate()).ignoreIfNull().zeroOrPositiveAmount(); + baseDataValidator.reset().parameter("tenureInMonths").value(command.getTenureInMonths()).ignoreIfNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("interestCompoundedEvery").value(command.getInterestCompoundedEvery()).notNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(command.getInterestCompoundedEveryPeriodType()).notNull().inMinMaxRange(2, 2); + baseDataValidator.reset().parameter("interestCompoundedEvery").value(command.getInterestCompoundedEvery()).ignoreIfNull().integerGreaterThanZero(); + baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(command.getInterestCompoundedEveryPeriodType()).ignoreIfNull().inMinMaxRange(2, 2); baseDataValidator.reset().parameter("commencementDate").value(command.getCommencementDate()).notNull(); if (!dataValidationErrors.isEmpty()) {