diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/PortfolioApiDataConversionService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/PortfolioApiDataConversionService.java new file mode 100644 index 000000000..f88680c1c --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/PortfolioApiDataConversionService.java @@ -0,0 +1,13 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.portfolio.group; + +import org.mifosplatform.portfolio.group.command.GroupCommand; + +public interface PortfolioApiDataConversionService { + + GroupCommand convertJsonToGroupCommand(Long resourceIdentifier, String json); +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/PortfolioApiDataConversionServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/PortfolioApiDataConversionServiceImpl.java new file mode 100644 index 000000000..e35f30304 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/PortfolioApiDataConversionServiceImpl.java @@ -0,0 +1,118 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.portfolio.group; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.mifosplatform.infrastructure.core.exception.InvalidJsonException; +import org.mifosplatform.infrastructure.core.exception.UnsupportedParameterException; +import org.mifosplatform.portfolio.group.command.GroupCommand; +import org.springframework.stereotype.Service; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; + +@Service +public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataConversionService { + + /** + * Google-gson class for converting to and from json. + */ + private final Gson gsonConverter; + + public PortfolioApiDataConversionServiceImpl() { + this.gsonConverter = new Gson(); + } + + @Override + public GroupCommand convertJsonToGroupCommand(final Long resourceIdentifier, final String json) { + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + + final Type typeOfMap = new TypeToken>() {}.getType(); + final Map requestMap = gsonConverter.fromJson(json, typeOfMap); + + final Set supportedParams = new HashSet(Arrays.asList("name", "officeId", "levelId", "parentId", "loanOfficerId", + "externalId", "clientMembers")); + + checkForUnsupportedParameters(requestMap, supportedParams); + + final Set modifiedParameters = new HashSet(); + + final String name = extractStringParameter("name", requestMap, modifiedParameters); + final Long officeId = extractLongParameter("officeId", requestMap, modifiedParameters); + final Long levelId = extractLongParameter("levelId", requestMap, modifiedParameters); + final Long parentId = extractLongParameter("parentId", requestMap, modifiedParameters); + final Long loanOfficerId = extractLongParameter("loanOfficerId", requestMap, modifiedParameters); + final String externalId = extractStringParameter("externalId", requestMap, modifiedParameters); + + final JsonParser parser = new JsonParser(); + + String[] clientMembers = null; + JsonElement element = parser.parse(json); + if (element.isJsonObject()) { + JsonObject object = element.getAsJsonObject(); + if (object.has("clientMembers")) { + modifiedParameters.add("clientMembers"); + JsonArray array = object.get("clientMembers").getAsJsonArray(); + clientMembers = new String[array.size()]; + for (int i = 0; i < array.size(); i++) { + clientMembers[i] = array.get(i).getAsString(); + } + } + } + + return new GroupCommand(modifiedParameters, resourceIdentifier, externalId, name, officeId, loanOfficerId, clientMembers, parentId, + levelId); + } + + private void checkForUnsupportedParameters(final Map requestMap, final Set supportedParams) { + List unsupportedParameterList = new ArrayList(); + for (String providedParameter : requestMap.keySet()) { + if (!supportedParams.contains(providedParameter)) { + unsupportedParameterList.add(providedParameter); + } + } + + if (!unsupportedParameterList.isEmpty()) { throw new UnsupportedParameterException(unsupportedParameterList); } + } + + private String extractStringParameter(final String paramName, final Map requestMap, final Set modifiedParameters) { + String paramValue = null; + if (requestMap.containsKey(paramName)) { + paramValue = (String) requestMap.get(paramName); + modifiedParameters.add(paramName); + } + + if (paramValue != null) { + paramValue = paramValue.trim(); + } + + return paramValue; + } + + private Long extractLongParameter(final String paramName, final Map requestMap, final Set modifiedParameters) { + Long paramValue = null; + if (requestMap.containsKey(paramName)) { + String valueAsString = (String) requestMap.get(paramName); + if (StringUtils.isNotBlank(valueAsString)) { + paramValue = Long.valueOf(Double.valueOf(valueAsString).longValue()); + } + modifiedParameters.add(paramName); + } + return paramValue; + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java index b78716743..7b07f5447 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java @@ -30,12 +30,12 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; +import org.mifosplatform.portfolio.group.PortfolioApiDataConversionService; import org.mifosplatform.portfolio.group.command.GroupCommand; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; import org.mifosplatform.portfolio.group.data.GroupData; import org.mifosplatform.portfolio.group.service.GroupReadPlatformService; import org.mifosplatform.portfolio.group.service.GroupWritePlatformService; -import org.mifosplatform.portfolio.savingsaccount.PortfolioApiDataConversionService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/GoogleGsonPortfolioApiJsonSerializerService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/GoogleGsonPortfolioApiJsonSerializerService.java deleted file mode 100644 index a2223e184..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/GoogleGsonPortfolioApiJsonSerializerService.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import org.mifosplatform.infrastructure.core.serialization.GoogleGsonSerializerHelper; -import org.mifosplatform.portfolio.savingsaccount.data.SavingAccountData; -import org.mifosplatform.portfolio.savingsaccount.data.SavingScheduleData; -import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductData; -import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositAccountData; -import org.mifosplatform.portfolio.savingsdepositproduct.data.DepositProductData; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.google.gson.Gson; - -/** - * Implementation of {@link PortfolioApiJsonSerializerService} that uses - * google-gson to serialize Java object representation into JSON. - */ -@Service -public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApiJsonSerializerService { - - private static final Set SAVINGS_PRODUCT_DATA_PARAMETERS = new HashSet(Arrays.asList("currencyOptions", "id", - "createdOn", "lastModifedOn", "locale", "name", "description", "currencyCode", "digitsAfterDecimal", "interstRate", - "minInterestRate", "maxInterestRate", "savingsDepositAmount", "savingProductType", "tenureType", "tenure", "frequency", - "interestType", "interestCalculationMethod", "minimumBalanceForWithdrawal", "isPartialDepositAllowed", "isLockinPeriodAllowed", - "lockinPeriod", "lockinPeriodType", "currencyOptions", "savingsProductTypeOptions", "tenureTypeOptions", "depositEvery", - "savingFrequencyOptions", "savingsInterestTypeOptions", "lockinPeriodTypeOptions", "interestCalculationOptions")); - - private static final Set SAVINGS_DEPOSIT_PRODUCT_DATA_PARAMETERS = new HashSet(Arrays.asList("currencyOptions", - "interestCompoundedEveryPeriodTypeOptions", "id", "externalId", "name", "description", "createdOn", "lastModifedOn", - "currencyCode", "digitsAfterDecimal", "minimumBalance", "maximumBalance", "tenureInMonths", "maturityDefaultInterestRate", - "maturityMinInterestRate", "maturityMaxInterestRate", "interestCompoundedEvery", "interestCompoundedEveryPeriodType", - "renewalAllowed", "preClosureAllowed", "preClosureInterestRate", "interestCompoundingAllowed", "isLockinPeriodAllowed", - "lockinPeriod", "lockinPeriodType", "currency")); - - private static final Set SAVINGS_DEPOSIT_ACCOUNT_DATA_PARAMETERS = new HashSet(Arrays.asList("productOptions", - "interestCompoundedEveryPeriodTypeOptions", "id", "externalId", "clientId", "clientName", "productId", "productName", "status", - "currency", "deposit", "maturityInterestRate", "tenureInMonths", "interestCompoundedEvery", - "interestCompoundedEveryPeriodType", "renewalAllowed", "preClosureAllowed", "preClosureInterestRate", "withdrawnonDate", - "rejectedonDate", "closedonDate", "transactions", "permissions", "isInterestWithdrawable", "interestPaid", - "interestCompoundingAllowed", "availableInterestForWithdrawal", "availableWithdrawalAmount", "todaysDate", - "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "printFDdetailsLocation", "availableInterest", - "interestPostedAmount", "lastInterestPostedDate", "nextInterestPostedDate", "fatherName", "address", "imageKey")); - - private static final Set SAVINGS_ACCOUNTS_DATA_PARAMETERS = new HashSet(Arrays.asList("id", "status", "externalId", - "clientId", "clientName", "productId", "productName", "productType", "currencyData", "savingsDepostiAmountPerPeriod", - "savingsFrequencyType", "totalDepositAmount", "reccuringInterestRate", "savingInterestRate", "interestType", - "interestCalculationMethod", "tenure", "tenureType", "projectedCommencementDate", "actualCommencementDate", "maturesOnDate", - "projectedInterestAccuredOnMaturity", "actualInterestAccured", "projectedMaturityAmount", "actualMaturityAmount","outstandingAmount", - "preClosureAllowed", "preClosureInterestRate", "withdrawnonDate", "rejectedonDate", "closedonDate", "isLockinPeriodAllowed", - "lockinPeriod", "lockinPeriodType", "productOptions", "currencyOptions", "savingsProductTypeOptions", "tenureTypeOptions", - "savingFrequencyOptions", "savingsInterestTypeOptions", "lockinPeriodTypeOptions", "interestCalculationOptions","permissions","savingScheduleDatas", - "dueAmount", "savingScheduleData", "transactions","interestPostEvery","interestPostFrequency")); - - private static final Set SAVING_SCHEDULE_DATA_PARAMETERS = new HashSet(Arrays.asList("periods", "cumulativeDepositDue")); - - private final GoogleGsonSerializerHelper helper; - - @Autowired - public GoogleGsonPortfolioApiJsonSerializerService(final GoogleGsonSerializerHelper helper) { - this.helper = helper; - } - - @Override - public String serializeSavingProductDataToJson(final boolean prettyPrint, final Set responseParameters, - final Collection products) { - final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(SAVINGS_PRODUCT_DATA_PARAMETERS, - prettyPrint, responseParameters); - return helper.serializedJsonFrom(gsonDeserializer, products.toArray(new SavingProductData[products.size()])); - } - - @Override - public String serializeSavingProductDataToJson(final boolean prettyPrint, final Set responseParameters, - final SavingProductData savingProduct) { - final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(SAVINGS_PRODUCT_DATA_PARAMETERS, - prettyPrint, responseParameters); - return helper.serializedJsonFrom(gsonDeserializer, savingProduct); - } - - @Override - public String serializeDepositProductDataToJson(final boolean prettyPrint, final Set responseParameters, - final Collection products) { - final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy( - SAVINGS_DEPOSIT_PRODUCT_DATA_PARAMETERS, prettyPrint, responseParameters); - return helper.serializedJsonFrom(gsonDeserializer, products.toArray(new DepositProductData[products.size()])); - } - - @Override - public String serializeDepositProductDataToJson(final boolean prettyPrint, final Set responseParameters, - final DepositProductData depositProduct) { - final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy( - SAVINGS_DEPOSIT_PRODUCT_DATA_PARAMETERS, prettyPrint, responseParameters); - return helper.serializedJsonFrom(gsonDeserializer, depositProduct); - } - - @Override - public String serializeDepositAccountDataToJson(final boolean prettyPrint, final Set responseParameters, - final Collection accounts) { - final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy( - SAVINGS_DEPOSIT_ACCOUNT_DATA_PARAMETERS, prettyPrint, responseParameters); - return helper.serializedJsonFrom(gsonDeserializer, accounts.toArray(new DepositAccountData[accounts.size()])); - } - - @Override - public String serializeDepositAccountDataToJson(final boolean prettyPrint, final Set responseParameters, - final DepositAccountData account) { - final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy( - SAVINGS_DEPOSIT_ACCOUNT_DATA_PARAMETERS, prettyPrint, responseParameters); - return helper.serializedJsonFrom(gsonDeserializer, account); - } - - @Override - public String serializeSavingAccountsDataToJson(boolean prettyPrint, Set responseParameters, SavingAccountData account) { - final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(SAVINGS_ACCOUNTS_DATA_PARAMETERS, - prettyPrint, responseParameters); - return helper.serializedJsonFrom(gsonDeserializer, account); - } - - @Override - public String serializeSavingAccountsDataToJson(boolean prettyPrint, Set responseParameters, - Collection accounts) { - final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(SAVINGS_ACCOUNTS_DATA_PARAMETERS, - prettyPrint, responseParameters); - return helper.serializedJsonFrom(gsonDeserializer, accounts.toArray(new SavingAccountData[accounts.size()])); - } - - @Override - public String serializeSavingScheduleDataToJson(boolean prettyPrint, Set responseParameters, - SavingScheduleData savingScheduleData) { - final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(SAVING_SCHEDULE_DATA_PARAMETERS, - prettyPrint, responseParameters); - return helper.serializedJsonFrom(gsonDeserializer, savingScheduleData); - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/PortfolioApiDataConversionService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/PortfolioApiDataConversionService.java deleted file mode 100644 index 996bbddd4..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/PortfolioApiDataConversionService.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount; - -import org.mifosplatform.portfolio.group.command.GroupCommand; -import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountApprovalCommand; -import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountCommand; -import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountDepositCommand; -import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountWithdrawalCommand; -import org.mifosplatform.portfolio.savingsaccount.command.SavingStateTransitionsCommand; -import org.mifosplatform.portfolio.savingsaccountproduct.command.SavingProductCommand; -import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountCommand; -import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountWithdrawInterestCommand; -import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountWithdrawalCommand; -import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionApprovalCommand; -import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionCommand; -import org.mifosplatform.portfolio.savingsdepositproduct.command.DepositProductCommand; - -public interface PortfolioApiDataConversionService { - - SavingProductCommand convertJsonToSavingProductCommand(Long resourceIdentifier, String json); - - DepositProductCommand convertJsonToDepositProductCommand(Long resourceIdentifier, String json); - - GroupCommand convertJsonToGroupCommand(Long resourceIdentifier, String json); - - DepositAccountCommand convertJsonToDepositAccountCommand(Long resourceIdentifier, String json); - - DepositStateTransitionCommand convertJsonToDepositStateTransitionCommand(Long resourceIdentifier, String json); - - DepositStateTransitionApprovalCommand convertJsonToDepositStateTransitionApprovalCommand(Long resourceIdentifier, String json); - - DepositAccountWithdrawalCommand convertJsonToDepositWithdrawalCommand(Long resourceIdentifier, String json); - - DepositAccountWithdrawInterestCommand convertJsonToDepositAccountWithdrawInterestCommand(Long resourceIdentifier, String json); - - SavingAccountCommand convertJsonToSavingAccountCommand(Long resourceIdentifier, String json); - - SavingStateTransitionsCommand convertJsonToSavingStateTransitionCommand(Long accountId, String json); - - SavingAccountApprovalCommand convertJsonToSavingApprovalCommand(Long accountId, String json); - - SavingAccountDepositCommand convertJsonToSavingAccountDepositCommand(Long accountId, String json); - - SavingAccountWithdrawalCommand convertJsonToSavingAccountWithdrawalCommand(Long accountId, String jsonRequestBody); - -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/PortfolioApiDataConversionServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/PortfolioApiDataConversionServiceImpl.java deleted file mode 100644 index 625b0aab6..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/PortfolioApiDataConversionServiceImpl.java +++ /dev/null @@ -1,938 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount; - -import java.lang.reflect.Type; -import java.math.BigDecimal; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.text.NumberFormat; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang.StringUtils; -import org.joda.time.LocalDate; -import org.joda.time.format.DateTimeFormat; -import org.mifosplatform.infrastructure.core.data.ApiParameterError; -import org.mifosplatform.infrastructure.core.exception.InvalidJsonException; -import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; -import org.mifosplatform.infrastructure.core.exception.UnsupportedParameterException; -import org.mifosplatform.portfolio.group.command.GroupCommand; -import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountApprovalCommand; -import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountCommand; -import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountDepositCommand; -import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountWithdrawalCommand; -import org.mifosplatform.portfolio.savingsaccount.command.SavingStateTransitionsCommand; -import org.mifosplatform.portfolio.savingsaccountproduct.command.SavingProductCommand; -import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountCommand; -import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountWithdrawInterestCommand; -import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountWithdrawalCommand; -import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionApprovalCommand; -import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionCommand; -import org.mifosplatform.portfolio.savingsdepositproduct.command.DepositProductCommand; -import org.springframework.format.number.NumberFormatter; -import org.springframework.stereotype.Service; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.reflect.TypeToken; - -@Service -public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataConversionService { - - /** - * Google-gson class for converting to and from json. - */ - private final Gson gsonConverter; - - public PortfolioApiDataConversionServiceImpl() { - this.gsonConverter = new Gson(); - } - - @Override - public GroupCommand convertJsonToGroupCommand(final Long resourceIdentifier, final String json) { - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - final Type typeOfMap = new TypeToken>() {}.getType(); - final Map requestMap = gsonConverter.fromJson(json, typeOfMap); - - final Set supportedParams = new HashSet(Arrays.asList("name", "officeId", "levelId", "parentId", "loanOfficerId", - "externalId", "clientMembers")); - - checkForUnsupportedParameters(requestMap, supportedParams); - - final Set modifiedParameters = new HashSet(); - - final String name = extractStringParameter("name", requestMap, modifiedParameters); - final Long officeId = extractLongParameter("officeId", requestMap, modifiedParameters); - final Long levelId = extractLongParameter("levelId", requestMap, modifiedParameters); - final Long parentId = extractLongParameter("parentId", requestMap, modifiedParameters); - final Long loanOfficerId = extractLongParameter("loanOfficerId", requestMap, modifiedParameters); - final String externalId = extractStringParameter("externalId", requestMap, modifiedParameters); - - final JsonParser parser = new JsonParser(); - - String[] clientMembers = null; - JsonElement element = parser.parse(json); - if (element.isJsonObject()) { - JsonObject object = element.getAsJsonObject(); - if (object.has("clientMembers")) { - modifiedParameters.add("clientMembers"); - JsonArray array = object.get("clientMembers").getAsJsonArray(); - clientMembers = new String[array.size()]; - for (int i = 0; i < array.size(); i++) { - clientMembers[i] = array.get(i).getAsString(); - } - } - } - - return new GroupCommand(modifiedParameters, resourceIdentifier, externalId, name, officeId, loanOfficerId , clientMembers ,parentId ,levelId); - } - - private void checkForUnsupportedParameters(Map requestMap, Set supportedParams) { - List unsupportedParameterList = new ArrayList(); - for (String providedParameter : requestMap.keySet()) { - if (!supportedParams.contains(providedParameter)) { - unsupportedParameterList.add(providedParameter); - } - } - - if (!unsupportedParameterList.isEmpty()) { throw new UnsupportedParameterException(unsupportedParameterList); } - } - - private String extractStringParameter(final String paramName, final Map requestMap, final Set modifiedParameters) { - String paramValue = null; - if (requestMap.containsKey(paramName)) { - paramValue = (String) requestMap.get(paramName); - modifiedParameters.add(paramName); - } - - if (paramValue != null) { - paramValue = paramValue.trim(); - } - - return paramValue; - } - - private Integer extractIntegerParameter(final String paramName, final Map requestMap, final Set modifiedParameters) { - Integer paramValue = null; - if (requestMap.containsKey(paramName)) { - String valueAsString = (String) requestMap.get(paramName); - paramValue = convertToInteger(valueAsString, paramName, extractLocaleValue(requestMap)); - modifiedParameters.add(paramName); - } - return paramValue; - } - - private BigDecimal extractBigDecimalParameter(final String paramName, final Map requestMap, - final Set modifiedParameters) { - BigDecimal paramValue = null; - if (requestMap.containsKey(paramName)) { - String valueAsString = (String) requestMap.get(paramName); - paramValue = convertFrom(valueAsString, paramName, extractLocaleValue(requestMap)); - modifiedParameters.add(paramName); - } - return paramValue; - } - - private boolean extractBooleanParameter(final String paramName, final Map requestMap, final Set modifiedParameters) { - boolean paramValue = false; - String paramValueAsString = null; - if (requestMap.containsKey(paramName)) { - paramValueAsString = (String) requestMap.get(paramName); - - if (paramValueAsString != null) { - paramValueAsString = paramValueAsString.trim(); - } - - paramValue = Boolean.valueOf(paramValueAsString); - modifiedParameters.add(paramName); - } - return paramValue; - } - - private Long extractLongParameter(final String paramName, final Map requestMap, final Set modifiedParameters) { - Long paramValue = null; - if (requestMap.containsKey(paramName)) { - String valueAsString = (String) requestMap.get(paramName); - if (StringUtils.isNotBlank(valueAsString)) { - paramValue = Long.valueOf(Double.valueOf(valueAsString).longValue()); - } - modifiedParameters.add(paramName); - } - return paramValue; - } - - private LocalDate extractLocalDateParameter(final String paramName, final Map requestMap, - final Set modifiedParameters) { - LocalDate paramValue = null; - if (requestMap.containsKey(paramName)) { - String valueAsString = (String) requestMap.get(paramName); - if (StringUtils.isNotBlank(valueAsString)) { - final String dateFormat = (String) requestMap.get("dateFormat"); - final Locale locale = new Locale((String) requestMap.get("locale")); - paramValue = convertFrom(valueAsString, paramName, dateFormat, locale); - } - modifiedParameters.add(paramName); - } - return paramValue; - } - - private Locale extractLocaleValue(Map requestMap) { - Locale clientApplicationLocale = null; - String locale = null; - if (requestMap.containsKey("locale")) { - locale = (String) requestMap.get("locale"); - clientApplicationLocale = localeFromString(locale); - } - return clientApplicationLocale; - } - - private LocalDate convertFrom(final String dateAsString, final String parameterName, final String dateFormat, - final Locale clientApplicationLocale) { - - if (StringUtils.isBlank(dateFormat) || clientApplicationLocale == null) { - - List dataValidationErrors = new ArrayList(); - if (StringUtils.isBlank(dateFormat)) { - String defaultMessage = new StringBuilder("The parameter '" + parameterName - + "' requires a 'dateFormat' parameter to be passed with it.").toString(); - ApiParameterError error = ApiParameterError.parameterError("validation.msg.missing.dateFormat.parameter", defaultMessage, - parameterName); - dataValidationErrors.add(error); - } - if (clientApplicationLocale == null) { - String defaultMessage = new StringBuilder("The parameter '" + parameterName - + "' requires a 'locale' parameter to be passed with it.").toString(); - ApiParameterError error = ApiParameterError.parameterError("validation.msg.missing.locale.parameter", defaultMessage, - parameterName); - dataValidationErrors.add(error); - } - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", - dataValidationErrors); - } - - LocalDate eventLocalDate = null; - if (StringUtils.isNotBlank(dateAsString)) { - try { - // Locale locale = LocaleContextHolder.getLocale(); - eventLocalDate = DateTimeFormat.forPattern(dateFormat).withLocale(clientApplicationLocale) - .parseLocalDate(dateAsString.toLowerCase(clientApplicationLocale)); - } catch (IllegalArgumentException e) { - List dataValidationErrors = new ArrayList(); - ApiParameterError error = ApiParameterError.parameterError("validation.msg.invalid.date.format", "The parameter " - + parameterName + " is invalid based on the dateFormat: '" + dateFormat + "' and locale: '" - + clientApplicationLocale + "' provided:", parameterName, dateAsString, dateFormat); - dataValidationErrors.add(error); - - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", - dataValidationErrors); - } - } - - return eventLocalDate; - } - - private Integer convertToInteger(final String numericalValueFormatted, final String parameterName, final Locale clientApplicationLocale) { - - if (clientApplicationLocale == null) { - - List dataValidationErrors = new ArrayList(); - String defaultMessage = new StringBuilder("The parameter '" + parameterName - + "' requires a 'locale' parameter to be passed with it.").toString(); - ApiParameterError error = ApiParameterError.parameterError("validation.msg.missing.locale.parameter", defaultMessage, - parameterName); - dataValidationErrors.add(error); - - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", - dataValidationErrors); - } - - try { - Integer number = null; - - if (StringUtils.isNotBlank(numericalValueFormatted)) { - - String source = numericalValueFormatted.trim(); - - NumberFormat format = NumberFormat.getInstance(clientApplicationLocale); - DecimalFormat df = (DecimalFormat) format; - DecimalFormatSymbols symbols = df.getDecimalFormatSymbols(); - df.setParseBigDecimal(true); - - // http://bugs.sun.com/view_bug.do?bug_id=4510618 - char groupingSeparator = symbols.getGroupingSeparator(); - if (groupingSeparator == '\u00a0') { - source = source.replaceAll(" ", Character.toString('\u00a0')); - } - - Number parsedNumber = df.parse(source); - - double parsedNumberDouble = parsedNumber.doubleValue(); - int parsedNumberInteger = parsedNumber.intValue(); - - if (source.contains(Character.toString(symbols.getDecimalSeparator()))) { throw new ParseException(source, 0); } - - if (!Double.valueOf(parsedNumberDouble).equals(Double.valueOf(Integer.valueOf(parsedNumberInteger)))) { throw new ParseException( - source, 0); } - - number = parsedNumber.intValue(); - } - - return number; - } catch (ParseException e) { - - List dataValidationErrors = new ArrayList(); - ApiParameterError error = ApiParameterError.parameterError("validation.msg.invalid.integer.format", "The parameter " - + parameterName + " has value: " + numericalValueFormatted + " which is invalid integer value for provided locale of [" - + clientApplicationLocale.toString() + "].", parameterName, numericalValueFormatted, clientApplicationLocale); - dataValidationErrors.add(error); - - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", - dataValidationErrors); - } - } - - private BigDecimal convertFrom(final String numericalValueFormatted, final String parameterName, final Locale clientApplicationLocale) { - - if (clientApplicationLocale == null) { - - List dataValidationErrors = new ArrayList(); - String defaultMessage = new StringBuilder("The parameter '" + parameterName - + "' requires a 'locale' parameter to be passed with it.").toString(); - ApiParameterError error = ApiParameterError.parameterError("validation.msg.missing.locale.parameter", defaultMessage, - parameterName); - dataValidationErrors.add(error); - - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", - dataValidationErrors); - } - - try { - BigDecimal number = null; - - if (StringUtils.isNotBlank(numericalValueFormatted)) { - - String source = numericalValueFormatted.trim(); - - NumberFormat format = NumberFormat.getNumberInstance(clientApplicationLocale); - DecimalFormat df = (DecimalFormat) format; - DecimalFormatSymbols symbols = df.getDecimalFormatSymbols(); - // http://bugs.sun.com/view_bug.do?bug_id=4510618 - char groupingSeparator = symbols.getGroupingSeparator(); - if (groupingSeparator == '\u00a0') { - source = source.replaceAll(" ", Character.toString('\u00a0')); - } - - NumberFormatter numberFormatter = new NumberFormatter(); - Number parsedNumber = numberFormatter.parse(source, clientApplicationLocale); - number = BigDecimal.valueOf(Double.valueOf(parsedNumber.doubleValue())); - } - - return number; - } catch (ParseException e) { - - List dataValidationErrors = new ArrayList(); - ApiParameterError error = ApiParameterError.parameterError("validation.msg.invalid.decimal.format", "The parameter " - + parameterName + " has value: " + numericalValueFormatted + " which is invalid decimal value for provided locale of [" - + clientApplicationLocale.toString() + "].", parameterName, numericalValueFormatted, clientApplicationLocale); - dataValidationErrors.add(error); - - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", - dataValidationErrors); - } - } - - /* - * private LocalDate convertFrom(final String dateAsString, final String - * parameterName, final String dateFormat) { - * - * if (StringUtils.isBlank(dateFormat)) { - * - * List dataValidationErrors = new - * ArrayList(); String defaultMessage = new - * StringBuilder("The parameter '" + parameterName + - * "' requires a 'dateFormat' parameter to be passed with it.").toString(); - * ApiParameterError error = ApiParameterError.parameterError( - * "validation.msg.missing.dateFormat.parameter", defaultMessage, - * parameterName); dataValidationErrors.add(error); - * - * throw new PlatformApiDataValidationException( - * "validation.msg.validation.errors.exist", "Validation errors exist.", - * dataValidationErrors); } - * - * LocalDate eventLocalDate = null; if - * (StringUtils.isNotBlank(dateAsString)) { try { Locale locale = - * LocaleContextHolder.getLocale(); eventLocalDate = - * DateTimeFormat.forPattern(dateFormat) .withLocale(locale) - * .parseLocalDate(dateAsString.toLowerCase(locale)); } catch - * (IllegalArgumentException e) { List - * dataValidationErrors = new ArrayList(); - * ApiParameterError error = ApiParameterError .parameterError( - * "validation.msg.invalid.date.format", "The parameter " + parameterName + - * " is invalid based on the dateFormat provided:" + dateFormat, - * parameterName, dateAsString, dateFormat); - * dataValidationErrors.add(error); - * - * throw new PlatformApiDataValidationException( - * "validation.msg.validation.errors.exist", "Validation errors exist.", - * dataValidationErrors); } } - * - * return eventLocalDate; } - * - * private Integer convertToInteger(final String numericalValueFormatted, - * final String parameterName, final Locale clientApplicationLocale) { - * - * if (clientApplicationLocale == null) { - * - * List dataValidationErrors = new - * ArrayList(); String defaultMessage = new - * StringBuilder("The parameter '" + parameterName + - * "' requires a 'locale' parameter to be passed with it.").toString(); - * ApiParameterError error = - * ApiParameterError.parameterError("validation.msg.missing.locale.parameter" - * , defaultMessage, parameterName); dataValidationErrors.add(error); - * - * throw new PlatformApiDataValidationException( - * "validation.msg.validation.errors.exist", "Validation errors exist.", - * dataValidationErrors); } - * - * try { Integer number = null; - * - * if (StringUtils.isNotBlank(numericalValueFormatted)) { - * - * String source = numericalValueFormatted.trim(); - * - * NumberFormat format = NumberFormat.getInstance(clientApplicationLocale); - * DecimalFormat df = (DecimalFormat) format; DecimalFormatSymbols symbols = - * df.getDecimalFormatSymbols(); df.setParseBigDecimal(true); - * - * // http://bugs.sun.com/view_bug.do?bug_id=4510618 char groupingSeparator - * = symbols.getGroupingSeparator(); if (groupingSeparator == '\u00a0') { - * source = source.replaceAll(" ", Character.toString('\u00a0')); } - * - * Number parsedNumber = df.parse(source); - * - * double parsedNumberDouble = parsedNumber.doubleValue(); int - * parsedNumberInteger = parsedNumber.intValue(); - * - * if (source.contains(Character.toString(symbols.getDecimalSeparator()))) { - * throw new ParseException(source, 0); } - * - * if - * (!Double.valueOf(parsedNumberDouble).equals(Double.valueOf(Integer.valueOf - * (parsedNumberInteger)))) { throw new ParseException(source, 0); } - * - * number = parsedNumber.intValue(); } - * - * return number; } catch (ParseException e) { - * - * List dataValidationErrors = new - * ArrayList(); ApiParameterError error = - * ApiParameterError.parameterError( - * "validation.msg.invalid.integer.format", "The parameter " + parameterName - * + " has value: " + numericalValueFormatted + - * " which is invalid integer value for provided locale of [" + - * clientApplicationLocale.toString() + "].", parameterName, - * numericalValueFormatted, clientApplicationLocale); - * dataValidationErrors.add(error); - * - * throw new PlatformApiDataValidationException( - * "validation.msg.validation.errors.exist", "Validation errors exist.", - * dataValidationErrors); } } - * - * private BigDecimal convertFrom(final String numericalValueFormatted, - * final String parameterName, final Locale clientApplicationLocale) { - * - * if (clientApplicationLocale == null) { - * - * List dataValidationErrors = new - * ArrayList(); String defaultMessage = new - * StringBuilder("The parameter '" + parameterName + - * "' requires a 'locale' parameter to be passed with it.").toString(); - * ApiParameterError error = - * ApiParameterError.parameterError("validation.msg.missing.locale.parameter" - * , defaultMessage, parameterName); dataValidationErrors.add(error); - * - * throw new PlatformApiDataValidationException( - * "validation.msg.validation.errors.exist", "Validation errors exist.", - * dataValidationErrors); } - * - * try { BigDecimal number = null; - * - * if (StringUtils.isNotBlank(numericalValueFormatted)) { - * - * String source = numericalValueFormatted.trim(); - * - * NumberFormat format = - * NumberFormat.getNumberInstance(clientApplicationLocale); DecimalFormat df - * = (DecimalFormat) format; DecimalFormatSymbols symbols = - * df.getDecimalFormatSymbols(); // - * http://bugs.sun.com/view_bug.do?bug_id=4510618 char groupingSeparator = - * symbols.getGroupingSeparator(); if (groupingSeparator == '\u00a0') { - * source = source.replaceAll(" ", Character.toString('\u00a0')); } - * - * NumberFormatter numberFormatter = new NumberFormatter(); Number - * parsedNumber = numberFormatter.parse(source, clientApplicationLocale); - * number = BigDecimal.valueOf(Double.valueOf(parsedNumber.doubleValue())); - * } - * - * return number; } catch (ParseException e) { - * - * List dataValidationErrors = new - * ArrayList(); ApiParameterError error = - * ApiParameterError.parameterError( - * "validation.msg.invalid.decimal.format", "The parameter " + parameterName - * + " has value: " + numericalValueFormatted + - * " which is invalid decimal value for provided locale of [" + - * clientApplicationLocale.toString() + "].", parameterName, - * numericalValueFormatted, clientApplicationLocale); - * dataValidationErrors.add(error); - * - * throw new PlatformApiDataValidationException( - * "validation.msg.validation.errors.exist", "Validation errors exist.", - * dataValidationErrors); } } - */ - private Locale localeFromString(final String localeAsString) { - - if (StringUtils.isBlank(localeAsString)) { - List dataValidationErrors = new ArrayList(); - ApiParameterError error = ApiParameterError.parameterError("validation.msg.invalid.locale.format", - "The parameter locale is invalid. It cannot be blank.", "locale"); - dataValidationErrors.add(error); - - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", - dataValidationErrors); - } - - String languageCode = ""; - String courntryCode = ""; - String variantCode = ""; - - String[] localeParts = localeAsString.split("_"); - - if (localeParts != null && localeParts.length == 1) { - languageCode = localeParts[0]; - } - - if (localeParts != null && localeParts.length == 2) { - languageCode = localeParts[0]; - courntryCode = localeParts[1]; - } - - if (localeParts != null && localeParts.length == 3) { - languageCode = localeParts[0]; - courntryCode = localeParts[1]; - variantCode = localeParts[2]; - } - - return localeFrom(languageCode, courntryCode, variantCode); - } - - private Locale localeFrom(final String languageCode, final String courntryCode, final String variantCode) { - - List dataValidationErrors = new ArrayList(); - - List allowedLanguages = Arrays.asList(Locale.getISOLanguages()); - if (!allowedLanguages.contains(languageCode.toLowerCase())) { - ApiParameterError error = ApiParameterError.parameterError("validation.msg.invalid.locale.format", - "The parameter locale has an invalid language value " + languageCode + " .", "locale", languageCode); - dataValidationErrors.add(error); - } - - if (StringUtils.isNotBlank(courntryCode.toUpperCase())) { - List allowedCountries = Arrays.asList(Locale.getISOCountries()); - if (!allowedCountries.contains(courntryCode)) { - ApiParameterError error = ApiParameterError.parameterError("validation.msg.invalid.locale.format", - "The parameter locale has an invalid country value " + courntryCode + " .", "locale", courntryCode); - dataValidationErrors.add(error); - } - } - - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); } - - return new Locale(languageCode.toLowerCase(), courntryCode.toUpperCase(), variantCode); - } - - @Override - public SavingProductCommand convertJsonToSavingProductCommand(final Long resourceIdentifier, final String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - Type typeOfMap = new TypeToken>() {}.getType(); - Map requestMap = gsonConverter.fromJson(json, typeOfMap); - - Set supportedParams = new HashSet(Arrays.asList("locale", "name", "description", "currencyCode", - "digitsAfterDecimal", "interestRate", "minInterestRate", "maxInterestRate", "savingsDepositAmount", "savingProductType", - "tenureType", "tenure", "frequency", "interestType", "interestCalculationMethod", "minimumBalanceForWithdrawal", - "isPartialDepositAllowed", "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "depositEvery")); - - checkForUnsupportedParameters(requestMap, supportedParams); - Set modifiedParameters = new HashSet(); - String name = extractStringParameter("name", requestMap, modifiedParameters); - String description = extractStringParameter("description", requestMap, modifiedParameters); - String currencyCode = extractStringParameter("currencyCode", requestMap, modifiedParameters); - Integer digitsAfterDecimalValue = extractIntegerParameter("digitsAfterDecimal", requestMap, modifiedParameters); - BigDecimal interestRate = extractBigDecimalParameter("interestRate", requestMap, modifiedParameters); - BigDecimal minInterestRate = extractBigDecimalParameter("minInterestRate", requestMap, modifiedParameters); - BigDecimal maxInterestRate = extractBigDecimalParameter("maxInterestRate", requestMap, modifiedParameters); - BigDecimal savingsDepositAmount = extractBigDecimalParameter("savingsDepositAmount", requestMap, modifiedParameters); - Integer depositEvery = extractIntegerParameter("depositEvery", requestMap, modifiedParameters); - Integer savingProductType = extractIntegerParameter("savingProductType", requestMap, modifiedParameters); - Integer tenureType = extractIntegerParameter("tenureType", requestMap, modifiedParameters); - Integer tenure = extractIntegerParameter("tenure", requestMap, modifiedParameters); - Integer frequency = extractIntegerParameter("frequency", requestMap, modifiedParameters); - Integer interestType = extractIntegerParameter("interestType", requestMap, modifiedParameters); - Integer interestCalculationMethod = extractIntegerParameter("interestCalculationMethod", requestMap, modifiedParameters); - BigDecimal minimumBalanceForWithdrawal = extractBigDecimalParameter("minimumBalanceForWithdrawal", requestMap, modifiedParameters); - boolean isPartialDepositAllowed = extractBooleanParameter("isPartialDepositAllowed", requestMap, modifiedParameters); - boolean isLockinPeriodAllowed = extractBooleanParameter("isLockinPeriodAllowed", requestMap, modifiedParameters); - Integer lockinPeriod = extractIntegerParameter("lockinPeriod", requestMap, modifiedParameters); - Integer lockinPeriodType = extractIntegerParameter("lockinPeriodType", requestMap, modifiedParameters); - - return new SavingProductCommand(modifiedParameters, resourceIdentifier, name, description, currencyCode, digitsAfterDecimalValue, - interestRate, minInterestRate, maxInterestRate, savingsDepositAmount, depositEvery, savingProductType, tenureType, tenure, - frequency, interestType, interestCalculationMethod, minimumBalanceForWithdrawal, isPartialDepositAllowed, - isLockinPeriodAllowed, lockinPeriod, lockinPeriodType); - } - - @Override - public DepositAccountCommand convertJsonToDepositAccountCommand(final Long resourceIdentifier, final String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - Type typeOfMap = new TypeToken>() {}.getType(); - Map requestMap = gsonConverter.fromJson(json, typeOfMap); - - // preClosureInterestRate - Set supportedParams = new HashSet(Arrays.asList("clientId", "productId", "externalId", "deposit", - "maturityInterestRate", "preClosureInterestRate", "tenureInMonths", "interestCompoundedEvery", - "interestCompoundedEveryPeriodType", "commencementDate", "renewalAllowed", "preClosureAllowed", - "interestCompoundingAllowed", "locale", "dateFormat", "isInterestWithdrawable", "isLockinPeriodAllowed", "lockinPeriod", - "lockinPeriodType")); - checkForUnsupportedParameters(requestMap, supportedParams); - Set modifiedParameters = new HashSet(); - - Long clientId = extractLongParameter("clientId", requestMap, modifiedParameters); - Long productId = extractLongParameter("productId", requestMap, modifiedParameters); - String externalId = extractStringParameter("externalId", requestMap, modifiedParameters); - BigDecimal deposit = extractBigDecimalParameter("deposit", requestMap, modifiedParameters); - BigDecimal interestRate = extractBigDecimalParameter("maturityInterestRate", requestMap, modifiedParameters); - BigDecimal preClosureInterestRate = extractBigDecimalParameter("preClosureInterestRate", requestMap, modifiedParameters); - Integer tenureInMonths = extractIntegerParameter("tenureInMonths", requestMap, modifiedParameters); - - boolean isLockinPeriodAllowed = extractBooleanParameter("isLockinPeriodAllowed", requestMap, modifiedParameters); - Integer lockinPeriod = extractIntegerParameter("lockinPeriod", requestMap, modifiedParameters); - Integer lockinPeriodType = extractIntegerParameter("lockinPeriodType", requestMap, modifiedParameters); - - Integer interestCompoundedEvery = extractIntegerParameter("interestCompoundedEvery", requestMap, modifiedParameters); - Integer interestCompoundedEveryPeriodType = extractIntegerParameter("interestCompoundedEveryPeriodType", requestMap, - modifiedParameters); - LocalDate commencementDate = extractLocalDateParameter("commencementDate", requestMap, modifiedParameters); - - boolean renewalAllowed = extractBooleanParameter("renewalAllowed", requestMap, modifiedParameters); - boolean preClosureAllowed = extractBooleanParameter("preClosureAllowed", requestMap, modifiedParameters); - boolean isInterestWithdrawable = extractBooleanParameter("isInterestWithdrawable", requestMap, modifiedParameters); - boolean interestCompoundingAllowed = extractBooleanParameter("interestCompoundingAllowed", requestMap, modifiedParameters); - - return new DepositAccountCommand(modifiedParameters, resourceIdentifier, clientId, productId, externalId, deposit, interestRate, - preClosureInterestRate, tenureInMonths, interestCompoundedEvery, interestCompoundedEveryPeriodType, commencementDate, - renewalAllowed, preClosureAllowed, isInterestWithdrawable, interestCompoundingAllowed, isLockinPeriodAllowed, lockinPeriod, - lockinPeriodType); - } - - @Override - public DepositProductCommand convertJsonToDepositProductCommand(final Long resourceIdentifier, final String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - Type typeOfMap = new TypeToken>() {}.getType(); - Map requestMap = gsonConverter.fromJson(json, typeOfMap); - - Set supportedParams = new HashSet(Arrays.asList("locale", "name", "externalId", "description", "currencyCode", - "digitsAfterDecimal", "minimumBalance", "maximumBalance", "tenureInMonths", "maturityDefaultInterestRate", - "maturityMinInterestRate", "maturityMaxInterestRate", "interestCompoundedEvery", "interestCompoundedEveryPeriodType", - "renewalAllowed", "preClosureAllowed", "preClosureInterestRate", "interestCompoundingAllowed", "isLockinPeriodAllowed", - "lockinPeriod", "lockinPeriodType")); - checkForUnsupportedParameters(requestMap, supportedParams); - Set modifiedParameters = new HashSet(); - String name = extractStringParameter("name", requestMap, modifiedParameters); - String externalId = extractStringParameter("externalId", requestMap, modifiedParameters); - - String description = extractStringParameter("description", requestMap, modifiedParameters); - String currencyCode = extractStringParameter("currencyCode", requestMap, modifiedParameters); - Integer digitsAfterDecimalValue = extractIntegerParameter("digitsAfterDecimal", requestMap, modifiedParameters); - BigDecimal minimumBalance = extractBigDecimalParameter("minimumBalance", requestMap, modifiedParameters); - BigDecimal maximumBalance = extractBigDecimalParameter("maximumBalance", requestMap, modifiedParameters); - - Integer tenureMonths = extractIntegerParameter("tenureInMonths", requestMap, modifiedParameters); - BigDecimal maturityDefaultInterestRate = extractBigDecimalParameter("maturityDefaultInterestRate", requestMap, modifiedParameters); - BigDecimal maturityMinInterestRate = extractBigDecimalParameter("maturityMinInterestRate", requestMap, modifiedParameters); - BigDecimal maturityMaxInterestRate = extractBigDecimalParameter("maturityMaxInterestRate", requestMap, modifiedParameters); - - Integer interestCompoundedEvery = extractIntegerParameter("interestCompoundedEvery", requestMap, modifiedParameters); - Integer interestCompoundedEveryPeriodType = extractIntegerParameter("interestCompoundedEveryPeriodType", requestMap, - modifiedParameters); - - boolean interestCompoundingAllowed = extractBooleanParameter("interestCompoundingAllowed", requestMap, modifiedParameters); - - boolean canRenew = extractBooleanParameter("renewalAllowed", requestMap, modifiedParameters); - boolean canPreClose = extractBooleanParameter("preClosureAllowed", requestMap, modifiedParameters); - BigDecimal preClosureInterestRate = extractBigDecimalParameter("preClosureInterestRate", requestMap, modifiedParameters); - - boolean isLockinPeriodAllowed = extractBooleanParameter("isLockinPeriodAllowed", requestMap, modifiedParameters); - Integer lockinPeriod = extractIntegerParameter("lockinPeriod", requestMap, modifiedParameters); - Integer lockinPeriodType = extractIntegerParameter("lockinPeriodType", requestMap, modifiedParameters); - - return new DepositProductCommand(modifiedParameters, resourceIdentifier, externalId, name, description, currencyCode, - digitsAfterDecimalValue, minimumBalance, maximumBalance, tenureMonths, maturityDefaultInterestRate, - maturityMinInterestRate, maturityMaxInterestRate, interestCompoundedEvery, interestCompoundedEveryPeriodType, canRenew, - canPreClose, preClosureInterestRate, interestCompoundingAllowed, isLockinPeriodAllowed, lockinPeriod, lockinPeriodType); - } - - @Override - public DepositStateTransitionCommand convertJsonToDepositStateTransitionCommand(Long resourceIdentifier, String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - Type typeOfMap = new TypeToken>() {}.getType(); - Map requestMap = gsonConverter.fromJson(json, typeOfMap); - - Set supportedParams = new HashSet(Arrays.asList("eventDate", "locale", "dateFormat", "note")); - - checkForUnsupportedParameters(requestMap, supportedParams); - - Set modifiedParameters = new HashSet(); - - LocalDate eventDate = extractLocalDateParameter("eventDate", requestMap, modifiedParameters); - String note = extractStringParameter("note", requestMap, modifiedParameters); - - return new DepositStateTransitionCommand(resourceIdentifier, eventDate, note); - } - - @Override - public DepositStateTransitionApprovalCommand convertJsonToDepositStateTransitionApprovalCommand(final Long resourceIdentifier, - final String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - Type typeOfMap = new TypeToken>() {}.getType(); - Map requestMap = gsonConverter.fromJson(json, typeOfMap); - - Set supportedParams = new HashSet(Arrays.asList("locale", "commencementDate", "locale", "dateFormat", - "tenureInMonths", "deposit", "interestCompoundedEveryPeriodType", "productId", "interestCompoundedEvery", "note", - "maturityInterestRate")); - - checkForUnsupportedParameters(requestMap, supportedParams); - - Set modifiedParameters = new HashSet(); - - LocalDate commencementDate = extractLocalDateParameter("commencementDate", requestMap, modifiedParameters); - BigDecimal deposit = extractBigDecimalParameter("deposit", requestMap, modifiedParameters); - BigDecimal maturityInterestRate = extractBigDecimalParameter("maturityInterestRate", requestMap, modifiedParameters); - Integer tenureInMonths = extractIntegerParameter("tenureInMonths", requestMap, modifiedParameters); - Integer interestCompoundedEveryPeriodType = extractIntegerParameter("interestCompoundedEveryPeriodType", requestMap, - modifiedParameters); - Integer interestCompoundedEvery = extractIntegerParameter("interestCompoundedEvery", requestMap, modifiedParameters); - Long productId = extractLongParameter("productId", requestMap, modifiedParameters); - String note = extractStringParameter("note", requestMap, modifiedParameters); - - return new DepositStateTransitionApprovalCommand(resourceIdentifier, productId, commencementDate, tenureInMonths, deposit, - interestCompoundedEveryPeriodType, interestCompoundedEvery, note, maturityInterestRate); - } - - @Override - public DepositAccountWithdrawalCommand convertJsonToDepositWithdrawalCommand(final Long resourceIdentifier, final String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - Type typeOfMap = new TypeToken>() {}.getType(); - Map requestMap = gsonConverter.fromJson(json, typeOfMap); - - Set supportedParams = new HashSet(Arrays.asList("note", "locale", "maturesOnDate", "dateFormat")); - - checkForUnsupportedParameters(requestMap, supportedParams); - - Set modifiedParameters = new HashSet(); - - String note = extractStringParameter("note", requestMap, modifiedParameters); - LocalDate maturesOnDate = extractLocalDateParameter("maturesOnDate", requestMap, modifiedParameters); - - return new DepositAccountWithdrawalCommand(resourceIdentifier, note, maturesOnDate); - } - - @Override - public DepositAccountWithdrawInterestCommand convertJsonToDepositAccountWithdrawInterestCommand(final Long resourceIdentifier, - final String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - Type typeOfMap = new TypeToken>() {}.getType(); - Map requestMap = gsonConverter.fromJson(json, typeOfMap); - - Set supportedParams = new HashSet(Arrays.asList("amount", "note", "locale")); - - checkForUnsupportedParameters(requestMap, supportedParams); - - Set modifiedParameters = new HashSet(); - - BigDecimal amount = extractBigDecimalParameter("amount", requestMap, modifiedParameters); - String note = extractStringParameter("note", requestMap, modifiedParameters); - - return new DepositAccountWithdrawInterestCommand(resourceIdentifier, amount, note); - } - - @Override - public SavingAccountCommand convertJsonToSavingAccountCommand(Long resourceIdentifier, String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - Type typeOfMap = new TypeToken>() {}.getType(); - Map requestMap = gsonConverter.fromJson(json, typeOfMap); - - // currencyCode, currencyDigits - Set supportedParams = new HashSet(Arrays.asList("clientId", "productId", "externalId", "currencyCode", - "digitsAfterDecimal", "savingsDepositAmountPerPeriod", "recurringInterestRate", "savingInterestRate", "tenure", - "commencementDate", "locale", "dateFormat", "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "tenureType", - "frequency", "interestType", "interestCalculationMethod", "minimumBalanceForWithdrawal", "isPartialDepositAllowed", - "depositEvery", "interestPostEvery", "interestPostFrequency")); - checkForUnsupportedParameters(requestMap, supportedParams); - Set modifiedParameters = new HashSet(); - - Long clientId = extractLongParameter("clientId", requestMap, modifiedParameters); - Long productId = extractLongParameter("productId", requestMap, modifiedParameters); - String externalId = extractStringParameter("externalId", requestMap, modifiedParameters); - String currencyCode = extractStringParameter("currencyCode", requestMap, modifiedParameters); - Integer digitsAfterDecimalValue = extractIntegerParameter("digitsAfterDecimal", requestMap, modifiedParameters); - BigDecimal savingsDepositAmount = extractBigDecimalParameter("savingsDepositAmountPerPeriod", requestMap, modifiedParameters); - BigDecimal recurringInterestRate = extractBigDecimalParameter("recurringInterestRate", requestMap, modifiedParameters); - BigDecimal savingInterestRate = extractBigDecimalParameter("savingInterestRate", requestMap, modifiedParameters); - Integer tenure = extractIntegerParameter("tenure", requestMap, modifiedParameters); - - boolean isLockinPeriodAllowed = extractBooleanParameter("isLockinPeriodAllowed", requestMap, modifiedParameters); - Integer lockinPeriod = extractIntegerParameter("lockinPeriod", requestMap, modifiedParameters); - Integer lockinPeriodType = extractIntegerParameter("lockinPeriodType", requestMap, modifiedParameters); - - LocalDate commencementDate = extractLocalDateParameter("commencementDate", requestMap, modifiedParameters); - Integer tenureType = extractIntegerParameter("tenureType", requestMap, modifiedParameters); - Integer depositfrequency = extractIntegerParameter("frequency", requestMap, modifiedParameters); - Integer interestType = extractIntegerParameter("interestType", requestMap, modifiedParameters); - Integer interestCalculationMethod = extractIntegerParameter("interestCalculationMethod", requestMap, modifiedParameters); - BigDecimal minimumBalanceForWithdrawal = extractBigDecimalParameter("minimumBalanceForWithdrawal", requestMap, modifiedParameters); - boolean isPartialDepositAllowed = extractBooleanParameter("isPartialDepositAllowed", requestMap, modifiedParameters); - Integer depositEvery = extractIntegerParameter("depositEvery", requestMap, modifiedParameters); - - Integer interestPostEvery = extractIntegerParameter("interestPostEvery", requestMap, modifiedParameters); - Integer interestPostFrequency = extractIntegerParameter("interestPostFrequency", requestMap, modifiedParameters); - - return new SavingAccountCommand(modifiedParameters, resourceIdentifier, clientId, productId, externalId, currencyCode, - digitsAfterDecimalValue, savingsDepositAmount, recurringInterestRate, savingInterestRate, tenure, commencementDate, - tenureType, depositfrequency, interestType, minimumBalanceForWithdrawal, interestCalculationMethod, isLockinPeriodAllowed, - isPartialDepositAllowed, lockinPeriod, lockinPeriodType, depositEvery, interestPostEvery, interestPostFrequency); - } - - @Override - public SavingStateTransitionsCommand convertJsonToSavingStateTransitionCommand(Long accountId, String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - Type typeOfMap = new TypeToken>() {}.getType(); - Map requestMap = gsonConverter.fromJson(json, typeOfMap); - - Set supportedParams = new HashSet(Arrays.asList("eventDate", "locale", "dateFormat", "note")); - - checkForUnsupportedParameters(requestMap, supportedParams); - - Set modifiedParameters = new HashSet(); - - LocalDate eventDate = extractLocalDateParameter("eventDate", requestMap, modifiedParameters); - String note = extractStringParameter("note", requestMap, modifiedParameters); - - return new SavingStateTransitionsCommand(accountId, eventDate, note); - - } - - @Override - public SavingAccountApprovalCommand convertJsonToSavingApprovalCommand(Long accountId, String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - Type typeOfMap = new TypeToken>() {}.getType(); - Map requestMap = gsonConverter.fromJson(json, typeOfMap); - - Set supportedParams = new HashSet(Arrays.asList("locale", "dateFormat", "commencementDate", - "savingsDepositAmountPerPeriod", "minimumBalanceForWithdrawal", "recurringInterestRate", "savingInterestRate", - "interestType", "tenure", "tenureType", "frequency", "payEvery", "note", "interestPostEvery", "interestPostFrequency")); - - checkForUnsupportedParameters(requestMap, supportedParams); - Set modifiedParameters = new HashSet(); - - LocalDate commencementDate = extractLocalDateParameter("commencementDate", requestMap, modifiedParameters); - BigDecimal savingsDepositAmountPerPeriod = extractBigDecimalParameter("savingsDepositAmountPerPeriod", requestMap, - modifiedParameters); - BigDecimal minimumBalanceForWithdrawal = extractBigDecimalParameter("minimumBalanceForWithdrawal", requestMap, modifiedParameters); - BigDecimal recurringInterestRate = extractBigDecimalParameter("recurringInterestRate", requestMap, modifiedParameters); - BigDecimal savingInterestRate = extractBigDecimalParameter("savingInterestRate", requestMap, modifiedParameters); - Integer interestType = extractIntegerParameter("interestType", requestMap, modifiedParameters); - Integer tenure = extractIntegerParameter("tenure", requestMap, modifiedParameters); - Integer tenureType = extractIntegerParameter("tenureType", requestMap, modifiedParameters); - Integer frequency = extractIntegerParameter("frequency", requestMap, modifiedParameters); - Integer payEvery = extractIntegerParameter("payEvery", requestMap, modifiedParameters); - String note = extractStringParameter("note", requestMap, modifiedParameters); - Integer interestPostEvery = extractIntegerParameter("interestPostEvery", requestMap, modifiedParameters); - Integer interestPostFrequency = extractIntegerParameter("interestPostFrequency", requestMap, modifiedParameters); - return new SavingAccountApprovalCommand(accountId, commencementDate, savingsDepositAmountPerPeriod, minimumBalanceForWithdrawal, - recurringInterestRate, savingInterestRate, interestType, tenure, tenureType, frequency, payEvery, note, interestPostEvery, - interestPostFrequency); - } - - @Override - public SavingAccountDepositCommand convertJsonToSavingAccountDepositCommand(Long accountId, String json) { - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - Type typeOfMap = new TypeToken>() {}.getType(); - Map requestMap = gsonConverter.fromJson(json, typeOfMap); - - Set supportedParams = new HashSet(Arrays.asList("locale", "dateFormat", "depositDate", - "savingsDepositAmountPerPeriod", "note")); - - checkForUnsupportedParameters(requestMap, supportedParams); - Set modifiedParameters = new HashSet(); - - LocalDate depositDate = extractLocalDateParameter("depositDate", requestMap, modifiedParameters); - BigDecimal savingsDepositAmountPerPeriod = extractBigDecimalParameter("savingsDepositAmountPerPeriod", requestMap, - modifiedParameters); - String note = extractStringParameter("note", requestMap, modifiedParameters); - return new SavingAccountDepositCommand(accountId, savingsDepositAmountPerPeriod, depositDate, note); - } - - @Override - public SavingAccountWithdrawalCommand convertJsonToSavingAccountWithdrawalCommand(Long accountId, String json) { - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } - - Type typeOfMap = new TypeToken>() {}.getType(); - Map requestMap = gsonConverter.fromJson(json, typeOfMap); - - Set supportedParams = new HashSet(Arrays.asList("locale", "dateFormat", "transactionDate", "amount", "note")); - - checkForUnsupportedParameters(requestMap, supportedParams); - Set modifiedParameters = new HashSet(); - - LocalDate transactionDate = extractLocalDateParameter("transactionDate", requestMap, modifiedParameters); - BigDecimal amount = extractBigDecimalParameter("amount", requestMap, modifiedParameters); - String note = extractStringParameter("note", requestMap, modifiedParameters); - return new SavingAccountWithdrawalCommand(accountId, transactionDate, amount, note); - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/PortfolioApiJsonSerializerService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/PortfolioApiJsonSerializerService.java deleted file mode 100644 index 763a30265..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/PortfolioApiJsonSerializerService.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount; - -import java.util.Collection; -import java.util.Set; - -import org.mifosplatform.portfolio.savingsaccount.data.SavingAccountData; -import org.mifosplatform.portfolio.savingsaccount.data.SavingScheduleData; -import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductData; -import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositAccountData; -import org.mifosplatform.portfolio.savingsdepositproduct.data.DepositProductData; - -public interface PortfolioApiJsonSerializerService { - - String serializeSavingProductDataToJson(boolean prettyPrint, Set responseParameters, Collection products); - - String serializeSavingProductDataToJson(boolean prettyPrint, Set responseParameters, SavingProductData savingProduct); - - String serializeDepositProductDataToJson(boolean prettyPrint, Set responseParameters, Collection products); - - String serializeDepositProductDataToJson(boolean prettyPrint, Set responseParameters, DepositProductData depositProduct); - - String serializeDepositAccountDataToJson(boolean prettyPrint, Set responseParameters, Collection accounts); - - String serializeDepositAccountDataToJson(boolean prettyPrint, Set responseParameters, DepositAccountData account); - - String serializeSavingAccountsDataToJson(boolean prettyPrint, Set responseParameters, SavingAccountData account); - - String serializeSavingAccountsDataToJson(boolean prettyPrint, Set responseParameters, Collection accounts); - - String serializeSavingScheduleDataToJson(boolean prettyPrint, Set responseParameters, SavingScheduleData savingScheduleData); - -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/api/SavingsAccountApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/api/SavingsAccountApiResource.java index f3ca0b764..c9f3d0f08 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/api/SavingsAccountApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/api/SavingsAccountApiResource.java @@ -69,16 +69,17 @@ import com.google.gson.JsonElement; @Component @Scope("singleton") public class SavingsAccountApiResource { - - private final Set SAVINGS_ACCOUNTS_DATA_PARAMETERS = new HashSet(Arrays.asList("id", "status", "externalId", + + private final Set SAVINGS_ACCOUNTS_DATA_PARAMETERS = new HashSet(Arrays.asList("id", "status", "externalId", "clientId", "clientName", "productId", "productName", "productType", "currencyData", "savingsDepostiAmountPerPeriod", "savingsFrequencyType", "totalDepositAmount", "reccuringInterestRate", "savingInterestRate", "interestType", "interestCalculationMethod", "tenure", "tenureType", "projectedCommencementDate", "actualCommencementDate", "maturesOnDate", - "projectedInterestAccuredOnMaturity", "actualInterestAccured", "projectedMaturityAmount", "actualMaturityAmount","outstandingAmount", - "preClosureAllowed", "preClosureInterestRate", "withdrawnonDate", "rejectedonDate", "closedonDate", "isLockinPeriodAllowed", - "lockinPeriod", "lockinPeriodType", "productOptions", "currencyOptions", "savingsProductTypeOptions", "tenureTypeOptions", - "savingFrequencyOptions", "savingsInterestTypeOptions", "lockinPeriodTypeOptions", "interestCalculationOptions","permissions","savingScheduleDatas", - "dueAmount", "savingScheduleData", "transactions","interestPostEvery","interestPostFrequency")); + "projectedInterestAccuredOnMaturity", "actualInterestAccured", "projectedMaturityAmount", "actualMaturityAmount", + "outstandingAmount", "preClosureAllowed", "preClosureInterestRate", "withdrawnonDate", "rejectedonDate", "closedonDate", + "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "productOptions", "currencyOptions", "savingsProductTypeOptions", + "tenureTypeOptions", "savingFrequencyOptions", "savingsInterestTypeOptions", "lockinPeriodTypeOptions", + "interestCalculationOptions", "permissions", "savingScheduleDatas", "dueAmount", "savingScheduleData", "transactions", + "interestPostEvery", "interestPostFrequency")); private final SavingAccountWritePlatformService savingAccountWritePlatformService; private final SavingAccountReadPlatformService savingAccountReadPlatformService; @@ -92,68 +93,66 @@ public class SavingsAccountApiResource { private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final FromJsonHelper fromJsonHelper; private final DefaultToApiJsonSerializer savingScheduleToApiJsonSerializer; - + @Autowired public SavingsAccountApiResource(final SavingAccountWritePlatformService savingAccountWritePlatformService, - final SavingAccountReadPlatformService savingAccountReadPlatformService, - final SavingProductReadPlatformService savingProductReadPlatformService, - final CurrencyReadPlatformService currencyReadPlatformService, - final PlatformSecurityContext context,final CalculateSavingSchedule calculateSavingSchedule, - final ToApiJsonSerializer toApiJsonSerializer, - final ApiRequestParameterHelper apiRequestParameterHelper, - final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, - final FromJsonHelper fromJsonHelper, - final DefaultToApiJsonSerializer savingScheduleToApiJsonSerializer) { - this.savingAccountWritePlatformService = savingAccountWritePlatformService; - this.savingAccountReadPlatformService = savingAccountReadPlatformService; - this.savingProductReadPlatformService = savingProductReadPlatformService; - this.currencyReadPlatformService = currencyReadPlatformService; - this.context = context; - this.calculateSavingSchedule = calculateSavingSchedule; - this.toApiJsonSerializer = toApiJsonSerializer; - this.apiRequestParameterHelper = apiRequestParameterHelper; - this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; - this.fromJsonHelper = fromJsonHelper; - this.savingScheduleToApiJsonSerializer = savingScheduleToApiJsonSerializer; - } + final SavingAccountReadPlatformService savingAccountReadPlatformService, + final SavingProductReadPlatformService savingProductReadPlatformService, + final CurrencyReadPlatformService currencyReadPlatformService, final PlatformSecurityContext context, + final CalculateSavingSchedule calculateSavingSchedule, final ToApiJsonSerializer toApiJsonSerializer, + final ApiRequestParameterHelper apiRequestParameterHelper, + final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final FromJsonHelper fromJsonHelper, + final DefaultToApiJsonSerializer savingScheduleToApiJsonSerializer) { + this.savingAccountWritePlatformService = savingAccountWritePlatformService; + this.savingAccountReadPlatformService = savingAccountReadPlatformService; + this.savingProductReadPlatformService = savingProductReadPlatformService; + this.currencyReadPlatformService = currencyReadPlatformService; + this.context = context; + this.calculateSavingSchedule = calculateSavingSchedule; + this.toApiJsonSerializer = toApiJsonSerializer; + this.apiRequestParameterHelper = apiRequestParameterHelper; + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + this.fromJsonHelper = fromJsonHelper; + this.savingScheduleToApiJsonSerializer = savingScheduleToApiJsonSerializer; + } @POST @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String createSavingAccount(@QueryParam("command") final String commandParam, @Context final UriInfo uriInfo, final String apiRequestBodyAsJson) { - - if (is(commandParam, "calculateSavingSchedule")) { - - final JsonElement parsedQuery = this.fromJsonHelper.parse(apiRequestBodyAsJson); + + if (is(commandParam, "calculateSavingSchedule")) { + + final JsonElement parsedQuery = this.fromJsonHelper.parse(apiRequestBodyAsJson); final JsonQuery query = JsonQuery.from(apiRequestBodyAsJson, parsedQuery, this.fromJsonHelper); - + SavingScheduleData savingSchedule = this.calculateSavingSchedule.calculateSavingSchedule(query); - + final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); - + return this.savingScheduleToApiJsonSerializer.serialize(settings, savingSchedule, new HashSet()); - + } - - final CommandWrapper commandRequest = new CommandWrapperBuilder().createSavingAccount().withJson(apiRequestBodyAsJson).build(); - - final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + + final CommandWrapper commandRequest = new CommandWrapperBuilder().createSavingAccount().withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } - @PUT @Path("{accountId}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String updateSavingAccount(@PathParam("accountId") final Long accountId, final String apiRequestBodyAsJson) { - - final CommandWrapper commandRequest = new CommandWrapperBuilder().updateSavingAccount(accountId).withJson(apiRequestBodyAsJson).build(); - - final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateSavingAccount(accountId).withJson(apiRequestBodyAsJson) + .build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -166,7 +165,7 @@ public class SavingsAccountApiResource { context.authenticatedUser().validateHasReadPermission(entityType); Collection accounts = this.savingAccountReadPlatformService.retrieveAllSavingsAccounts(); - + final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.toApiJsonSerializer.serialize(settings, accounts, SAVINGS_ACCOUNTS_DATA_PARAMETERS); @@ -185,7 +184,7 @@ public class SavingsAccountApiResource { Collection transactions = null; SavingAccountData account = this.savingAccountReadPlatformService.retrieveSavingsAccount(accountId); - + final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); if (settings.isTemplate()) { @@ -196,7 +195,7 @@ public class SavingsAccountApiResource { if (!associationParameters.isEmpty()) { if (associationParameters.contains("all")) { associationParameters.addAll(Arrays.asList("savingScheduleData", "transactions")); - } + } if (associationParameters.contains("savingScheduleData")) { CurrencyData currencyData = account.getCurrencyData(); @@ -225,13 +224,13 @@ public class SavingsAccountApiResource { SavingAccountData account = this.savingAccountReadPlatformService.retrieveNewSavingsAccountDetails(clientId, productId); account = handleTemplateRelatedData(account); - + final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.toApiJsonSerializer.serialize(settings, account, SAVINGS_ACCOUNTS_DATA_PARAMETERS); } - private SavingAccountData handleTemplateRelatedData(SavingAccountData account) { - + private SavingAccountData handleTemplateRelatedData(final SavingAccountData account) { + Collection productOptions = savingProductReadPlatformService.retrieveAllSavingProductsForLookup(); Collection currencyOptions = this.currencyReadPlatformService.retrieveAllowedCurrencies(); @@ -274,30 +273,32 @@ public class SavingsAccountApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String savingStateTransitions(@PathParam("accountId") final Long accountId, @QueryParam("command") final String commandParam, final String apiRequestBodyAsJson) { - - CommandWrapperBuilder builder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson); - CommandProcessingResult result = null; - + + CommandWrapperBuilder builder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson); + CommandProcessingResult result = null; + if (is(commandParam, "approve")) { - final CommandWrapper commandRequest = builder.approveSavingAccountApplication(accountId).build(); - result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + final CommandWrapper commandRequest = builder.approveSavingAccountApplication(accountId).build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, "depositmoney")) { - final CommandWrapper commandRequest = builder.depositOfSavingAmount(accountId).build(); - result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + final CommandWrapper commandRequest = builder.depositOfSavingAmount(accountId).build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, "withdraw")) { - final CommandWrapper commandRequest = builder.withdrawSavingAmount(accountId).build(); - result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + final CommandWrapper commandRequest = builder.withdrawSavingAmount(accountId).build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, "reject")) { - final CommandWrapper commandRequest = builder.rejectSavingApplication(accountId).build(); - result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + final CommandWrapper commandRequest = builder.rejectSavingApplication(accountId).build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, "withdrewbyclient")) { - final CommandWrapper commandRequest = builder.withdrawSavingApplication(accountId).build(); - result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + final CommandWrapper commandRequest = builder.withdrawSavingApplication(accountId).build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, "undoapproval")) { final CommandWrapper commandRequest = builder.undoApprovalOfSavingApplication(accountId).build(); result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); - } else { throw new UnrecognizedQueryParamException("command", commandParam); } - + } else { + throw new UnrecognizedQueryParamException("command", commandParam); + } + return this.toApiJsonSerializer.serialize(result); } @@ -306,10 +307,10 @@ public class SavingsAccountApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String deleteSavingAccount(@PathParam("accountId") final Long accountId) { - - final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteSavingAccount(accountId).build(); - - final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + + final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteSavingAccount(accountId).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/CalculateSavingScheduleCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/CalculateSavingScheduleCommand.java deleted file mode 100644 index abc0e4ae8..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/CalculateSavingScheduleCommand.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount.command; - -import java.math.BigDecimal; - -import org.joda.time.LocalDate; - -public class CalculateSavingScheduleCommand { - - private final Long productId; - private final BigDecimal deposit; - private final Integer depositEvery; - private final Integer paymentFrequencyType; - private final BigDecimal interestRate; - private final LocalDate paymentsStartingFromDate; - private final Integer tenure; - private final Integer tenureType; - private final Integer interestPostEvery; - private final Integer interestPostFrequency; - private final Integer interestCalculationMethod; - - public CalculateSavingScheduleCommand(final Long productId, final BigDecimal deposit, final Integer depositEvery, - final Integer paymentFrequencyType, final BigDecimal interestRate, final LocalDate paymentsStartingFromDate, - final Integer tenure, final Integer tenureType, final Integer interestPostEvery, final Integer interestPostFrequency, final Integer interestCalculationMethod) { - - this.productId = productId; - this.deposit = deposit; - this.depositEvery = depositEvery; - this.paymentFrequencyType = paymentFrequencyType; - this.interestRate = interestRate; - this.paymentsStartingFromDate = paymentsStartingFromDate; - this.tenure = tenure; - this.tenureType = tenureType; - this.interestPostEvery = interestPostEvery; - this.interestPostFrequency = interestPostFrequency; - this.interestCalculationMethod = interestCalculationMethod; - - } - - public Long getProductId() { - return this.productId; - } - - public BigDecimal getDeposit() { - return this.deposit; - } - - public Integer getDepositEvery() { - return this.depositEvery; - } - - public Integer getPaymentFrequencyType() { - return this.paymentFrequencyType; - } - - public BigDecimal getInterestRate() { - return this.interestRate; - } - - public LocalDate getPaymentsStartingFromDate() { - return this.paymentsStartingFromDate; - } - - public Integer getTenure() { - return this.tenure; - } - - public Integer getInterestPostEvery() { - return this.interestPostEvery; - } - - public Integer getInterestPostFrequency() { - return this.interestPostFrequency; - } - - public Integer getTenureType() { - return this.tenureType; - } - - public Integer getInterestCalculationMethod() { - return this.interestCalculationMethod; - } - -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountApprovalCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountApprovalCommand.java deleted file mode 100644 index 3e5076cf7..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountApprovalCommand.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount.command; - -import java.math.BigDecimal; - -import org.joda.time.LocalDate; - -public class SavingAccountApprovalCommand { - - private final Long accountId; - private final LocalDate approvalDate; - private final BigDecimal depositAmountPerPeriod; - private final BigDecimal minimumBalanceForWithdrawal; - private final BigDecimal recurringInterestRate; - private final BigDecimal savingInterestRate; - private final Integer interestType; - private final Integer tenure; - private final Integer tenureType; - private final Integer depositFrequencyType; - private final Integer depositEvery; - - private final Integer interestPostEvery; - private final Integer interestPostFrequency; - - private final String note; - - public SavingAccountApprovalCommand(final Long accountId, final LocalDate approvalDate, - final BigDecimal depositAmountPerPeriod, final BigDecimal minimumBalanceForWithdrawal, final BigDecimal recurringInterestRate, - final BigDecimal savingInterestRate, final Integer interestType, final Integer tenure, final Integer tenureType, - final Integer depositFrequencyType, final Integer depositEvery, final String note, - final Integer interestPostEvery, final Integer interestPostFrequency) { - this.accountId = accountId; - this.approvalDate = approvalDate; - this.depositAmountPerPeriod = depositAmountPerPeriod; - this.minimumBalanceForWithdrawal = minimumBalanceForWithdrawal; - this.recurringInterestRate = recurringInterestRate; - this.savingInterestRate = savingInterestRate; - this.interestType = interestType; - this.tenure = tenure; - this.tenureType = tenureType; - this.depositFrequencyType = depositFrequencyType; - this.depositEvery = depositEvery; - this.note = note; - - this.interestPostEvery = interestPostEvery; - this.interestPostFrequency = interestPostFrequency; - } - - public Long getAccountId() { - return this.accountId; - } - - public LocalDate getApprovalDate() { - return this.approvalDate; - } - - public BigDecimal getDepositAmountPerPeriod() { - return this.depositAmountPerPeriod; - } - - public BigDecimal getMinimumBalanceForWithdrawal() { - return this.minimumBalanceForWithdrawal; - } - - public BigDecimal getRecurringInterestRate() { - return this.recurringInterestRate; - } - - public BigDecimal getSavingInterestRate() { - return this.savingInterestRate; - } - - public Integer getInterestType() { - return this.interestType; - } - - public Integer getTenure() { - return this.tenure; - } - - public Integer getTenureType() { - return this.tenureType; - } - - public Integer getDepositFrequencyType() { - return this.depositFrequencyType; - } - - public Integer getDepositEvery() { - return this.depositEvery; - } - - public String getNote() { - return this.note; - } - - public Integer getInterestPostEvery() { - return this.interestPostEvery; - } - - public Integer getInterestPostFrequency() { - return this.interestPostFrequency; - } - -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountApprovalCommandValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountApprovalCommandValidator.java deleted file mode 100644 index e1ad12e81..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountApprovalCommandValidator.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount.command; - -import java.util.ArrayList; -import java.util.List; - -import org.mifosplatform.infrastructure.core.data.ApiParameterError; -import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; -import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; - -public class SavingAccountApprovalCommandValidator { - - private final SavingAccountApprovalCommand command; - - public SavingAccountApprovalCommandValidator(final SavingAccountApprovalCommand command) { - this.command = command ; - } - - public void validate() { - List dataValidationErrors = new ArrayList(); - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("saving.account.transition.approve"); - baseDataValidator.reset().parameter("accountId").value(command.getAccountId()).notNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("commencementDate").value(command.getApprovalDate()).notNull(); - baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(command.getDepositAmountPerPeriod()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(command.getMinimumBalanceForWithdrawal()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("recurringInterestRate").value(command.getRecurringInterestRate()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("savingInterestRate").value(command.getSavingInterestRate()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("interestType").value(command.getInterestType()).notNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("tenure").value(command.getTenure()).notNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("tenureType").value(command.getTenureType()).notNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("frequency").value(command.getDepositFrequencyType()).notNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("payEvery").value(command.getDepositEvery()).notNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("note").value(command.getNote()).notNull(); - - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); } - } - -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountCommand.java deleted file mode 100644 index 26f968cee..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountCommand.java +++ /dev/null @@ -1,266 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount.command; - -import java.math.BigDecimal; -import java.util.Set; - -import org.joda.time.LocalDate; - -public class SavingAccountCommand { - - private final Long id; - private final Long clientId; - private final Long productId; - private final String externalId; - - private final String currencyCode; - private final Integer digitsAfterDecimal; - private final BigDecimal savingsDepositAmount; - private final BigDecimal recurringInterestRate; - private final BigDecimal savingInterestRate; - private final Integer tenure; - - private final boolean isLockinPeriodAllowed; - private final Integer lockinPeriod; - private final Integer lockinPeriodType; - - private final LocalDate commencementDate; - private final Integer tenureType; - private final Integer frequency; - private final Integer interestType; - - private final Integer interestCalculationMethod; - private final BigDecimal minimumBalanceForWithdrawal; - private final boolean isPartialDepositAllowed; - private final Integer depositEvery; - - private final Integer interestPostEvery; - private final Integer interestPostFrequency; - - private final Set modifiedParameters; - - public SavingAccountCommand(final Set modifiedParameters, final Long id, final Long clientId, final Long productId, - final String externalId, final String currencyCode, final Integer digitsAfterDecimal, final BigDecimal savingsDepositAmount, - final BigDecimal recurringInterestRate, final BigDecimal savingInterestRate, final Integer tenure, - final LocalDate commencementDate, final Integer tenureType, final Integer frequency, - final Integer interestType, final BigDecimal minimumBalanceForWithdrawal, final Integer interestCalculationMethod, - final boolean isLockinPeriodAllowed, final boolean isPartialDepositAllowed, final Integer lockInPeriod, - final Integer lockinPeriodType, final Integer depositEvery,final Integer interestPostEvery,final Integer interestPostFrequency) { - this.id = id; - this.clientId = clientId; - this.productId = productId; - this.externalId = externalId; - - this.currencyCode = currencyCode; - this.digitsAfterDecimal = digitsAfterDecimal; - this.savingsDepositAmount = savingsDepositAmount; - this.recurringInterestRate = recurringInterestRate; - this.savingInterestRate = savingInterestRate; - this.tenure = tenure; - - this.modifiedParameters = modifiedParameters; - this.commencementDate = commencementDate; - - this.tenureType = tenureType; - this.frequency = frequency; - this.interestType = interestType; - this.isPartialDepositAllowed = isPartialDepositAllowed; - - this.isLockinPeriodAllowed = isLockinPeriodAllowed; - this.lockinPeriod = lockInPeriod; - this.lockinPeriodType = lockinPeriodType; - this.minimumBalanceForWithdrawal = minimumBalanceForWithdrawal; - this.interestCalculationMethod = interestCalculationMethod; - this.depositEvery = depositEvery; - - this.interestPostEvery = interestPostEvery; - this.interestPostFrequency = interestPostFrequency; - } - - public Long getId() { - return id; - } - - public Long getClientId() { - return clientId; - } - - public Long getProductId() { - return productId; - } - - public String getExternalId() { - return externalId; - } - - public String getCurrencyCode() { - return currencyCode; - } - - public Integer getDigitsAfterDecimal() { - return digitsAfterDecimal; - } - - public BigDecimal getSavingsDepositAmount() { - return savingsDepositAmount; - } - - public BigDecimal getRecurringInterestRate() { - return recurringInterestRate; - } - - public BigDecimal getSavingInterestRate() { - return savingInterestRate; - } - - public Integer getTenure() { - return tenure; - } - - public boolean isLockinPeriodAllowed() { - return isLockinPeriodAllowed; - } - - public Integer getLockinPeriod() { - return lockinPeriod; - } - - public Integer getLockinPeriodType() { - return lockinPeriodType; - } - - public LocalDate getCommencementDate() { - return commencementDate; - } - - public Integer getTenureType() { - return tenureType; - } - - public Integer getFrequency() { - return frequency; - } - - public Integer getInterestType() { - return interestType; - } - - public Integer getInterestCalculationMethod() { - return interestCalculationMethod; - } - - public BigDecimal getMinimumBalanceForWithdrawal() { - return minimumBalanceForWithdrawal; - } - - public boolean isPartialDepositAllowed() { - return isPartialDepositAllowed; - } - - public Integer getDepositEvery() { - return this.depositEvery; - } - - public Integer getInterestPostEvery() { - return this.interestPostEvery; - } - - public Integer getInterestPostFrequency() { - return this.interestPostFrequency; - } - - public boolean isNoFieldChanged() { - return this.modifiedParameters.isEmpty(); - } - - public boolean isProductIdChanged() { - return this.modifiedParameters.contains("productId"); - } - - public boolean isExternalIdChanged() { - return this.modifiedParameters.contains("externalId"); - } - - public boolean isDepositAmountChanged() { - return this.modifiedParameters.contains("deposit"); - } - - public boolean isTenureInMonthsChanged() { - return this.modifiedParameters.contains("tenureInMonths"); - } - - public boolean isLockinPeriodChanged() { - return this.modifiedParameters.contains("lockinPeriod"); - } - - public boolean isPreClosureInterestRateChanged() { - return this.modifiedParameters.contains("preClosureInterestRate"); - } - - public boolean isPreClosureAllowedChanged() { - return this.modifiedParameters.contains("preClosureAllowed"); - } - - public boolean isCommencementDateChanged() { - return this.modifiedParameters.contains("commencementDate"); - } - - public boolean isTenureTypeEnumChanged() { - return this.modifiedParameters.contains("tenureType"); - } - - public boolean isSavingProductTypeChanged() { - return this.modifiedParameters.contains("savingProductType"); - } - - public boolean isSavingFrequencyTypeChanged() { - return this.modifiedParameters.contains("frequency"); - } - - public boolean isSavingInterestCalculationMethodChanged() { - return this.modifiedParameters.contains("interestCalculationMethod"); - } - - public boolean isReccuringInterestRateChanged() { - return this.modifiedParameters.contains("recurringInterestRate"); - } - - public boolean isSavingInterestRateChanged() { - return this.modifiedParameters.contains("savingInterestRate"); - } - - public boolean isLockinPeriodAllowedChanged() { - return this.modifiedParameters.contains("isLockinPeriodAllowed"); - } - - public boolean isLockinPeriodTypeChanged() { - return this.modifiedParameters.contains("lockinPeriodType"); - } - - public boolean isPartialDepositAllowedChanged() { - return this.modifiedParameters.contains("isPartialDepositAllowed"); - } - - public boolean isDepositEveryChanged() { - return this.modifiedParameters.contains("depositEvery"); - } - - public boolean isInterestPostedEveryChanged(){ - return this.modifiedParameters.contains(interestPostEvery); - } - - public boolean isInterestPostingChanged(){ - return this.modifiedParameters.contains(interestPostFrequency); - } - - - public CalculateSavingScheduleCommand toCalculateSavingScheduleCommand() { - return new CalculateSavingScheduleCommand(productId, savingsDepositAmount, depositEvery, frequency, recurringInterestRate, - commencementDate, tenure, tenureType, interestPostEvery, interestPostFrequency,interestCalculationMethod); - } - -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountCommandValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountCommandValidator.java deleted file mode 100644 index f28feb202..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountCommandValidator.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount.command; - -import java.util.ArrayList; -import java.util.List; - -import org.mifosplatform.infrastructure.core.data.ApiParameterError; -import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; -import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; - -public class SavingAccountCommandValidator { - - private final SavingAccountCommand command; - - public SavingAccountCommandValidator(final SavingAccountCommand command) { - this.command = command; - } - - public void validateForCreate() { - - List dataValidationErrors = new ArrayList(); - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("saving.account"); - - baseDataValidator.reset().parameter("clientId").value(command.getClientId()).notNull(); - baseDataValidator.reset().parameter("productId").value(command.getProductId()).notNull(); - baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).notNull().notExceedingLengthOf(100); - baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank(); - baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).notNull().inMinMaxRange(0, 6); - baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(command.getSavingsDepositAmount()).notNull() - .zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("recurringInterestRate").value(command.getRecurringInterestRate()).notNull() - .zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("savingInterestRate").value(command.getSavingInterestRate()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("savingInterestRate") - .comapareMinAndMaxOfTwoBigDecmimalNos(command.getSavingInterestRate(), command.getRecurringInterestRate()); - baseDataValidator.reset().parameter("tenureType").value(command.getTenureType()).notNull(); - baseDataValidator.reset().parameter("tenure").value(command.getTenure()).notNull(); - baseDataValidator.reset().parameter("frequency").value(command.getFrequency()).notNull(); - baseDataValidator.reset().parameter("interestType").value(command.getInterestType()).notNull(); - baseDataValidator.reset().parameter("interestCalculationMethod").value(command.getInterestCalculationMethod()).notNull(); - baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(command.getMinimumBalanceForWithdrawal()).notNull() - .zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("isPartialDepositAllowed").value(command.isPartialDepositAllowed()) - .trueOrFalseRequired(command.isPartialDepositAllowedChanged()).notNull(); - baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(command.isLockinPeriodAllowed()) - .trueOrFalseRequired(command.isLockinPeriodAllowedChanged()).notNull(); - baseDataValidator.reset().parameter("lockinPeriod").value(command.getLockinPeriod()).notNull(); - baseDataValidator.reset().parameter("lockinPeriodType").value(command.getLockinPeriodType()).notNull(); - baseDataValidator.reset().parameter("commencementDate").value(command.getCommencementDate()).notNull(); - - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); } - - } - - public void validateForUpdate() { - - List dataValidationErrors = new ArrayList(); - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("saving.account"); - - baseDataValidator.reset().parameter("id").value(command.getId()).notNull(); - baseDataValidator.reset().parameter("clientId").value(command.getClientId()).ignoreIfNull().notNull(); - baseDataValidator.reset().parameter("productId").value(command.getProductId()).ignoreIfNull().notNull(); - baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100); - baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank(); - baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).ignoreIfNull().inMinMaxRange(0, 6); - baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(command.getSavingsDepositAmount()).ignoreIfNull() - .zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("recurringInterestRate").value(command.getRecurringInterestRate()).ignoreIfNull() - .zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("savingInterestRate").value(command.getSavingInterestRate()).ignoreIfNull() - .zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("savingInterestRate") - .comapareMinAndMaxOfTwoBigDecmimalNos(command.getSavingInterestRate(), command.getRecurringInterestRate()); - baseDataValidator.reset().parameter("tenureType").value(command.getTenureType()).ignoreIfNull(); - baseDataValidator.reset().parameter("tenure").value(command.getTenure()).ignoreIfNull(); - baseDataValidator.reset().parameter("frequency").value(command.getFrequency()).ignoreIfNull(); - baseDataValidator.reset().parameter("interestType").value(command.getInterestType()).ignoreIfNull(); - baseDataValidator.reset().parameter("interestCalculationMethod").value(command.getInterestCalculationMethod()).ignoreIfNull(); - baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(command.getMinimumBalanceForWithdrawal()).ignoreIfNull() - .zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("isPartialDepositAllowed").value(command.isPartialDepositAllowed()) - .trueOrFalseRequired(command.isPartialDepositAllowedChanged()).ignoreIfNull(); - baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(command.isLockinPeriodAllowed()) - .trueOrFalseRequired(command.isLockinPeriodAllowedChanged()).ignoreIfNull(); - baseDataValidator.reset().parameter("lockinPeriod").value(command.getLockinPeriod()).ignoreIfNull(); - baseDataValidator.reset().parameter("lockinPeriodType").value(command.getLockinPeriodType()).ignoreIfNull(); - baseDataValidator.reset().parameter("commencementDate").value(command.getCommencementDate()).ignoreIfNull(); - baseDataValidator.reset().parameter("commencementDate").value(command.getCommencementDate()).ignoreIfNull(); - - if (command.isNoFieldChanged()) { - StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append("deposit.account").append( - ".no.parameters.for.update"); - StringBuilder defaultEnglishMessage = new StringBuilder("No parameters passed for update."); - ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), - "id"); - dataValidationErrors.add(error); - } - - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); } - - } - -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountDepositCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountDepositCommand.java deleted file mode 100644 index c1b99b134..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountDepositCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount.command; - -import java.math.BigDecimal; - -import org.joda.time.LocalDate; - -public class SavingAccountDepositCommand { - - private final Long accountId; - private final BigDecimal savingsDepostiAmountPerPeriod; - private final LocalDate depositDate; - private final String note; - - public SavingAccountDepositCommand(final Long accountId, final BigDecimal savingsDepostiAmountPerPeriod, final LocalDate depositDate, final String note) { - this.accountId = accountId; - this.savingsDepostiAmountPerPeriod = savingsDepostiAmountPerPeriod; - this.depositDate = depositDate; - this.note = note; - } - - public Long getAccountId() { - return this.accountId; - } - - public BigDecimal getSavingsDepostiAmountPerPeriod() { - return this.savingsDepostiAmountPerPeriod; - } - - public LocalDate getDepositDate() { - return this.depositDate; - } - - public String getNote() { - return this.note; - } - -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountDepositCommandValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountDepositCommandValidator.java deleted file mode 100644 index beec04163..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountDepositCommandValidator.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount.command; - -import java.util.ArrayList; -import java.util.List; - -import org.mifosplatform.infrastructure.core.data.ApiParameterError; -import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; -import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; - -public class SavingAccountDepositCommandValidator { - - private final SavingAccountDepositCommand command; - - public SavingAccountDepositCommandValidator(final SavingAccountDepositCommand command) { - this.command = command; - } - - public void validate(){ - - List dataValidationErrors = new ArrayList(); - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("saving.account.transaction.deposit"); - baseDataValidator.reset().parameter("accountId").value(command.getAccountId()).notNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("depositDate").value(command.getDepositDate()).notNull(); - baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(command.getSavingsDepostiAmountPerPeriod()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("note").value(command.getNote()).notNull(); - - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); } - } - -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountStateTransitionCommandValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountStateTransitionCommandValidator.java deleted file mode 100644 index 3fa0231af..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountStateTransitionCommandValidator.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount.command; - -import java.util.ArrayList; -import java.util.List; - -import org.mifosplatform.infrastructure.core.data.ApiParameterError; -import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; -import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; - -public class SavingAccountStateTransitionCommandValidator { - - private final SavingStateTransitionsCommand command; - - public SavingAccountStateTransitionCommandValidator(final SavingStateTransitionsCommand command) { - this.command = command; - } - - public void validate() { - - List dataValidationErrors = new ArrayList(); - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("saving.account.transition"); - baseDataValidator.reset().parameter("accountId").value(command.getAccountId()).notNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("eventDate").value(command.getEventDate()).notNull(); - baseDataValidator.reset().parameter("note").value(command.getNote()).notNull(); - - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); } - } - -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountWithdrawalCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountWithdrawalCommand.java deleted file mode 100644 index 2371416d7..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingAccountWithdrawalCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount.command; - -import java.math.BigDecimal; - -import org.joda.time.LocalDate; - -public class SavingAccountWithdrawalCommand { - - private final Long accountId; - private final LocalDate transactionDate; - private final BigDecimal amount; - private final String note; - - public SavingAccountWithdrawalCommand(final Long accountId, final LocalDate transactionDate, final BigDecimal amount, final String note) { - this.accountId = accountId; - this.transactionDate = transactionDate; - this.amount = amount; - this.note = note; - } - - public Long getAccountId() { - return this.accountId; - } - - public LocalDate getTransactionDate() { - return this.transactionDate; - } - - public BigDecimal getAmount() { - return this.amount; - } - - public String getNote() { - return this.note; - } -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingStateTransitionsCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingStateTransitionsCommand.java deleted file mode 100644 index 8bac286e1..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/command/SavingStateTransitionsCommand.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount.command; - -import org.joda.time.LocalDate; - -public class SavingStateTransitionsCommand { - - private final Long accountId; - private final LocalDate eventDate; - private final String note; - - public SavingStateTransitionsCommand( final Long accountId, final LocalDate eventDate, final String note) { - this.accountId = accountId; - this.eventDate = eventDate; - this.note = note; - } - - public Long getAccountId() { - return this.accountId; - } - - public LocalDate getEventDate() { - return this.eventDate; - } - - public String getNote() { - return this.note; - } -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/DepositScheduleDateGenerator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/DepositScheduleDateGenerator.java index 02dfbc844..35904e1eb 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/DepositScheduleDateGenerator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/DepositScheduleDateGenerator.java @@ -11,8 +11,6 @@ import org.joda.time.LocalDate; import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingFrequencyType; public interface DepositScheduleDateGenerator { - + List generate(LocalDate startDate, Integer paymentPeriods, Integer depositFrequency, SavingFrequencyType savingFrequencyType); - -} - +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccount.java index 05e73e573..7eca5393b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccount.java @@ -557,15 +557,16 @@ public class SavingAccount extends AbstractAuditableCustom { } public void depositMoney(final JsonCommand command) { - - final BigDecimal depositAmountCommandValue = command.bigDecimalValueOfParameterNamed("savingsDepositAmountPerPeriod"); - final LocalDate depositDateCommandValue = command.localDateValueOfParameterNamed("depositDate"); - + + final BigDecimal depositAmountCommandValue = command.bigDecimalValueOfParameterNamed("savingsDepositAmountPerPeriod"); + final LocalDate depositDateCommandValue = command.localDateValueOfParameterNamed("depositDate"); + BigDecimal depositAmount = BigDecimal.ZERO; BigDecimal remainAmountToBePaid = BigDecimal.ZERO; BigDecimal commandRemainDepositAmount = depositAmountCommandValue; - SavingAccountTransaction savingAccountTransaction = SavingAccountTransaction.deposit(depositAmountCommandValue, depositDateCommandValue); + SavingAccountTransaction savingAccountTransaction = SavingAccountTransaction.deposit(depositAmountCommandValue, + depositDateCommandValue); savingAccountTransaction.updateAccount(this); this.savingAccountTransactions.add(savingAccountTransaction); this.outstandingAmount = this.outstandingAmount.add(depositAmountCommandValue); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccountRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccountRepository.java index ea5154db0..54305fd69 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccountRepository.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/domain/SavingAccountRepository.java @@ -10,4 +10,4 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; public interface SavingAccountRepository extends JpaRepository, JpaSpecificationExecutor { -} +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/serialization/CalculateSavingScheduleQueryFromApiJsonHelper.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/serialization/CalculateSavingScheduleQueryFromApiJsonHelper.java index c784374e3..c258fa80f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/serialization/CalculateSavingScheduleQueryFromApiJsonHelper.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/serialization/CalculateSavingScheduleQueryFromApiJsonHelper.java @@ -25,21 +25,23 @@ import com.google.gson.reflect.TypeToken; @Component public final class CalculateSavingScheduleQueryFromApiJsonHelper { - - final Set supportedParams = new HashSet(Arrays.asList("clientId", "productId", "externalId", "savingsDepositAmountPerPeriod", "recurringInterestRate", - "savingInterestRate", "tenure", "commencementDate", "locale", "dateFormat", "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "tenureType", "frequency", - "interestType", "interestCalculationMethod", "minimumBalanceForWithdrawal", "isPartialDepositAllowed","depositEvery", "interestPostEvery", "interestPostFrequency")); - - private final FromJsonHelper fromApiJsonHelper; - - @Autowired - public CalculateSavingScheduleQueryFromApiJsonHelper(final FromJsonHelper fromApiJsonHelper) { - this.fromApiJsonHelper = fromApiJsonHelper; - } - - public void validate(final String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + + final Set supportedParams = new HashSet(Arrays.asList("clientId", "productId", "externalId", + "savingsDepositAmountPerPeriod", "recurringInterestRate", "savingInterestRate", "tenure", "commencementDate", "locale", + "dateFormat", "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "tenureType", "frequency", "interestType", + "interestCalculationMethod", "minimumBalanceForWithdrawal", "isPartialDepositAllowed", "depositEvery", "interestPostEvery", + "interestPostFrequency")); + + private final FromJsonHelper fromApiJsonHelper; + + @Autowired + public CalculateSavingScheduleQueryFromApiJsonHelper(final FromJsonHelper fromApiJsonHelper) { + this.fromApiJsonHelper = fromApiJsonHelper; + } + + public void validate(final String json) { + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams); @@ -48,74 +50,80 @@ public final class CalculateSavingScheduleQueryFromApiJsonHelper { final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("saving.account"); final JsonElement element = fromApiJsonHelper.parse(json); - - final Long productId = fromApiJsonHelper.extractLongNamed("productId", element); - baseDataValidator.reset().parameter("productId").value(productId).notNull(); - - final BigDecimal savingsDepositAmountPerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("savingsDepositAmountPerPeriod", element); - baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(savingsDepositAmountPerPeriod).notNull().zeroOrPositiveAmount(); - + + final Long productId = fromApiJsonHelper.extractLongNamed("productId", element); + baseDataValidator.reset().parameter("productId").value(productId).notNull(); + + final BigDecimal savingsDepositAmountPerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed( + "savingsDepositAmountPerPeriod", element); + baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(savingsDepositAmountPerPeriod).notNull() + .zeroOrPositiveAmount(); + final BigDecimal recurringInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("recurringInterestRate", element); baseDataValidator.reset().parameter("recurringInterestRate").value(recurringInterestRate).notNull().zeroOrPositiveAmount(); - + final BigDecimal savingInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("savingInterestRate", element); baseDataValidator.reset().parameter("savingInterestRate").value(savingInterestRate).notNull().zeroOrPositiveAmount(); - + final Integer tenure = fromApiJsonHelper.extractIntegerNamed("tenure", element, Locale.getDefault()); baseDataValidator.reset().parameter("tenure").value(tenure).notNull(); - + final LocalDate commencementDate = fromApiJsonHelper.extractLocalDateNamed("commencementDate", element); - baseDataValidator.reset().parameter("commencementDate").value(commencementDate).notNull(); - - final Boolean isLockinPeriodAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element); - baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(isLockinPeriodAllowedCommandValue).trueOrFalseRequired(isBooleanValueUpdated(isLockinPeriodAllowedCommandValue)); - - final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault()); - baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).notNull().zeroOrPositiveAmount(); - - final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault()); - baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).notNull().inMinMaxRange(1, 3); - - final Integer tenureType = fromApiJsonHelper.extractIntegerNamed("tenureType", element, Locale.getDefault()); + baseDataValidator.reset().parameter("commencementDate").value(commencementDate).notNull(); + + final Boolean isLockinPeriodAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element); + baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(isLockinPeriodAllowedCommandValue) + .trueOrFalseRequired(isBooleanValueUpdated(isLockinPeriodAllowedCommandValue)); + + final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault()); + baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).notNull().zeroOrPositiveAmount(); + + final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault()); + baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).notNull().inMinMaxRange(1, 3); + + final Integer tenureType = fromApiJsonHelper.extractIntegerNamed("tenureType", element, Locale.getDefault()); baseDataValidator.reset().parameter("tenureType").value(tenureType).ignoreIfNull(); - + final Integer frequency = fromApiJsonHelper.extractIntegerNamed("frequency", element, Locale.getDefault()); baseDataValidator.reset().parameter("frequency").value(frequency).ignoreIfNull(); - + final Integer interestType = fromApiJsonHelper.extractIntegerNamed("interestType", element, Locale.getDefault()); baseDataValidator.reset().parameter("interestType").value(interestType).ignoreIfNull(); - - final Integer interestCalculationMethod = fromApiJsonHelper.extractIntegerNamed("interestCalculationMethod", element, Locale.getDefault()); + + final Integer interestCalculationMethod = fromApiJsonHelper.extractIntegerNamed("interestCalculationMethod", element, + Locale.getDefault()); baseDataValidator.reset().parameter("interestCalculationMethod").value(interestCalculationMethod).ignoreIfNull(); - - final BigDecimal minimumBalanceForWithdrawal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalanceForWithdrawal", element); - baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(minimumBalanceForWithdrawal).ignoreIfNull().zeroOrPositiveAmount(); - + + final BigDecimal minimumBalanceForWithdrawal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalanceForWithdrawal", + element); + baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(minimumBalanceForWithdrawal).ignoreIfNull() + .zeroOrPositiveAmount(); + final Boolean isPartialDepositAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isPartialDepositAllowed", element); baseDataValidator.reset().parameter("isPartialDepositAllowed").value(isPartialDepositAllowedCommandValue) - .trueOrFalseRequired(isBooleanValueUpdated(isPartialDepositAllowedCommandValue)).ignoreIfNull(); - + .trueOrFalseRequired(isBooleanValueUpdated(isPartialDepositAllowedCommandValue)).ignoreIfNull(); + final Integer depositEvery = fromApiJsonHelper.extractIntegerNamed("depositEvery", element, Locale.getDefault()); - baseDataValidator.reset().parameter("depositEvery").value(depositEvery).notNull().zeroOrPositiveAmount(); - - final Integer interestPostEvery = fromApiJsonHelper.extractIntegerNamed("interestPostEvery", element, Locale.getDefault()); - baseDataValidator.reset().parameter("interestPostEvery").value(interestPostEvery).notNull().zeroOrPositiveAmount(); - - final Integer interestPostFrequency = fromApiJsonHelper.extractIntegerNamed("interestPostFrequency", element, Locale.getDefault()); - baseDataValidator.reset().parameter("interestPostFrequency").value(interestPostFrequency).notNull().zeroOrPositiveAmount(); - - throwExceptionIfValidationWarningsExist(dataValidationErrors); - } - - private Boolean isBooleanValueUpdated(Boolean actualValue) { - Boolean isUpdated = false; - if(actualValue != null){ - isUpdated = true; - } - return isUpdated; - } - - private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { + baseDataValidator.reset().parameter("depositEvery").value(depositEvery).notNull().zeroOrPositiveAmount(); + + final Integer interestPostEvery = fromApiJsonHelper.extractIntegerNamed("interestPostEvery", element, Locale.getDefault()); + baseDataValidator.reset().parameter("interestPostEvery").value(interestPostEvery).notNull().zeroOrPositiveAmount(); + + final Integer interestPostFrequency = fromApiJsonHelper.extractIntegerNamed("interestPostFrequency", element, Locale.getDefault()); + baseDataValidator.reset().parameter("interestPostFrequency").value(interestPostFrequency).notNull().zeroOrPositiveAmount(); + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + private Boolean isBooleanValueUpdated(final Boolean actualValue) { + Boolean isUpdated = false; + if (actualValue != null) { + isUpdated = true; + } + return isUpdated; + } + + private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/serialization/SavingAccountCommandFromApiJsonDeserializer.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/serialization/SavingAccountCommandFromApiJsonDeserializer.java index 6b0198859..021937f6d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/serialization/SavingAccountCommandFromApiJsonDeserializer.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/serialization/SavingAccountCommandFromApiJsonDeserializer.java @@ -25,22 +25,23 @@ import com.google.gson.reflect.TypeToken; @Component public class SavingAccountCommandFromApiJsonDeserializer { - - final Set supportedParams = new HashSet(Arrays.asList("clientId", "productId", "externalId", "currencyCode", "digitsAfterDecimal", - "savingsDepositAmountPerPeriod", "recurringInterestRate", "savingInterestRate", "tenure","commencementDate", "locale", "dateFormat", "isLockinPeriodAllowed", - "lockinPeriod", "lockinPeriodType", "tenureType", "frequency", "interestType", "interestCalculationMethod", "minimumBalanceForWithdrawal", - "isPartialDepositAllowed", "depositEvery", "interestPostEvery", "interestPostFrequency")); - - private final FromJsonHelper fromApiJsonHelper; - - @Autowired - public SavingAccountCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) { - this.fromApiJsonHelper = fromApiJsonHelper; - } - - public void validateForCreate(String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + + final Set supportedParams = new HashSet(Arrays.asList("clientId", "productId", "externalId", "currencyCode", + "digitsAfterDecimal", "savingsDepositAmountPerPeriod", "recurringInterestRate", "savingInterestRate", "tenure", + "commencementDate", "locale", "dateFormat", "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "tenureType", + "frequency", "interestType", "interestCalculationMethod", "minimumBalanceForWithdrawal", "isPartialDepositAllowed", + "depositEvery", "interestPostEvery", "interestPostFrequency")); + + private final FromJsonHelper fromApiJsonHelper; + + @Autowired + public SavingAccountCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) { + this.fromApiJsonHelper = fromApiJsonHelper; + } + + public void validateForCreate(final String json) { + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams); @@ -49,74 +50,80 @@ public class SavingAccountCommandFromApiJsonDeserializer { final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("saving.account"); final JsonElement element = fromApiJsonHelper.parse(json); - + final Long clientId = fromApiJsonHelper.extractLongNamed("clientId", element); - baseDataValidator.reset().parameter("clientId").value(clientId).notNull(); - - final Long productId = fromApiJsonHelper.extractLongNamed("productId", element); - baseDataValidator.reset().parameter("productId").value(productId).notNull(); - + baseDataValidator.reset().parameter("clientId").value(clientId).notNull(); + + final Long productId = fromApiJsonHelper.extractLongNamed("productId", element); + baseDataValidator.reset().parameter("productId").value(productId).notNull(); + final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element); baseDataValidator.reset().parameter("externalId").value(externalId).ignoreIfNull().notExceedingLengthOf(100); - - final BigDecimal savingsDepositAmountPerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("savingsDepositAmountPerPeriod", element); - baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(savingsDepositAmountPerPeriod).notNull().zeroOrPositiveAmount(); - + + final BigDecimal savingsDepositAmountPerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed( + "savingsDepositAmountPerPeriod", element); + baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(savingsDepositAmountPerPeriod).notNull() + .zeroOrPositiveAmount(); + final BigDecimal recurringInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("recurringInterestRate", element); baseDataValidator.reset().parameter("recurringInterestRate").value(recurringInterestRate).notNull().zeroOrPositiveAmount(); - + final BigDecimal savingInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("savingInterestRate", element); baseDataValidator.reset().parameter("savingInterestRate").value(savingInterestRate).notNull().zeroOrPositiveAmount(); - + final Integer tenure = fromApiJsonHelper.extractIntegerNamed("tenure", element, Locale.getDefault()); baseDataValidator.reset().parameter("tenure").value(tenure).notNull(); - + final LocalDate commencementDate = fromApiJsonHelper.extractLocalDateNamed("commencementDate", element); - baseDataValidator.reset().parameter("commencementDate").value(commencementDate).notNull(); - - final Boolean isLockinPeriodAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element); - baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(isLockinPeriodAllowedCommandValue).trueOrFalseRequired(isBooleanValueUpdated(isLockinPeriodAllowedCommandValue)); - - final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault()); - baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).notNull().zeroOrPositiveAmount(); - - final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault()); - baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).notNull().inMinMaxRange(1, 3); - - final Integer tenureType = fromApiJsonHelper.extractIntegerNamed("tenureType", element, Locale.getDefault()); + baseDataValidator.reset().parameter("commencementDate").value(commencementDate).notNull(); + + final Boolean isLockinPeriodAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element); + baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(isLockinPeriodAllowedCommandValue) + .trueOrFalseRequired(isBooleanValueUpdated(isLockinPeriodAllowedCommandValue)); + + final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault()); + baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).notNull().zeroOrPositiveAmount(); + + final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault()); + baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).notNull().inMinMaxRange(1, 3); + + final Integer tenureType = fromApiJsonHelper.extractIntegerNamed("tenureType", element, Locale.getDefault()); baseDataValidator.reset().parameter("tenureType").value(tenureType).ignoreIfNull(); - + final Integer frequency = fromApiJsonHelper.extractIntegerNamed("frequency", element, Locale.getDefault()); baseDataValidator.reset().parameter("frequency").value(frequency).ignoreIfNull(); - + final Integer interestType = fromApiJsonHelper.extractIntegerNamed("interestType", element, Locale.getDefault()); baseDataValidator.reset().parameter("interestType").value(interestType).ignoreIfNull(); - - final Integer interestCalculationMethod = fromApiJsonHelper.extractIntegerNamed("interestCalculationMethod", element, Locale.getDefault()); + + final Integer interestCalculationMethod = fromApiJsonHelper.extractIntegerNamed("interestCalculationMethod", element, + Locale.getDefault()); baseDataValidator.reset().parameter("interestCalculationMethod").value(interestCalculationMethod).ignoreIfNull(); - - final BigDecimal minimumBalanceForWithdrawal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalanceForWithdrawal", element); - baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(minimumBalanceForWithdrawal).ignoreIfNull().zeroOrPositiveAmount(); - + + final BigDecimal minimumBalanceForWithdrawal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalanceForWithdrawal", + element); + baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(minimumBalanceForWithdrawal).ignoreIfNull() + .zeroOrPositiveAmount(); + final Boolean isPartialDepositAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isPartialDepositAllowed", element); baseDataValidator.reset().parameter("isPartialDepositAllowed").value(isPartialDepositAllowedCommandValue) - .trueOrFalseRequired(isBooleanValueUpdated(isPartialDepositAllowedCommandValue)).ignoreIfNull(); - + .trueOrFalseRequired(isBooleanValueUpdated(isPartialDepositAllowedCommandValue)).ignoreIfNull(); + final Integer depositEvery = fromApiJsonHelper.extractIntegerNamed("depositEvery", element, Locale.getDefault()); - baseDataValidator.reset().parameter("depositEvery").value(depositEvery).notNull().zeroOrPositiveAmount(); - - final Integer interestPostEvery = fromApiJsonHelper.extractIntegerNamed("interestPostEvery", element, Locale.getDefault()); - baseDataValidator.reset().parameter("interestPostEvery").value(interestPostEvery).notNull().zeroOrPositiveAmount(); - - final Integer interestPostFrequency = fromApiJsonHelper.extractIntegerNamed("interestPostFrequency", element, Locale.getDefault()); - baseDataValidator.reset().parameter("interestPostFrequency").value(interestPostFrequency).notNull().zeroOrPositiveAmount(); - - throwExceptionIfValidationWarningsExist(dataValidationErrors); - } - - public void validateForUpdate(String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + baseDataValidator.reset().parameter("depositEvery").value(depositEvery).notNull().zeroOrPositiveAmount(); + + final Integer interestPostEvery = fromApiJsonHelper.extractIntegerNamed("interestPostEvery", element, Locale.getDefault()); + baseDataValidator.reset().parameter("interestPostEvery").value(interestPostEvery).notNull().zeroOrPositiveAmount(); + + final Integer interestPostFrequency = fromApiJsonHelper.extractIntegerNamed("interestPostFrequency", element, Locale.getDefault()); + baseDataValidator.reset().parameter("interestPostFrequency").value(interestPostFrequency).notNull().zeroOrPositiveAmount(); + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + public void validateForUpdate(final String json) { + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams); @@ -125,80 +132,85 @@ public class SavingAccountCommandFromApiJsonDeserializer { final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("saving.account"); final JsonElement element = fromApiJsonHelper.parse(json); - - final Long productId = fromApiJsonHelper.extractLongNamed("productId", element); - baseDataValidator.reset().parameter("productId").value(productId).ignoreIfNull(); - + + final Long productId = fromApiJsonHelper.extractLongNamed("productId", element); + baseDataValidator.reset().parameter("productId").value(productId).ignoreIfNull(); + final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element); baseDataValidator.reset().parameter("externalId").value(externalId).ignoreIfNull().notExceedingLengthOf(100); - - final BigDecimal savingsDepositAmountPerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("savingsDepositAmountPerPeriod", element); - baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(savingsDepositAmountPerPeriod).ignoreIfNull().zeroOrPositiveAmount(); - + + final BigDecimal savingsDepositAmountPerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed( + "savingsDepositAmountPerPeriod", element); + baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(savingsDepositAmountPerPeriod).ignoreIfNull() + .zeroOrPositiveAmount(); + final BigDecimal recurringInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("recurringInterestRate", element); baseDataValidator.reset().parameter("recurringInterestRate").value(recurringInterestRate).ignoreIfNull().zeroOrPositiveAmount(); - + final BigDecimal savingInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("savingInterestRate", element); baseDataValidator.reset().parameter("savingInterestRate").value(savingInterestRate).ignoreIfNull().zeroOrPositiveAmount(); - + final Integer tenure = fromApiJsonHelper.extractIntegerNamed("tenure", element, Locale.getDefault()); baseDataValidator.reset().parameter("tenure").value(tenure).ignoreIfNull(); - + final LocalDate commencementDate = fromApiJsonHelper.extractLocalDateNamed("commencementDate", element); - baseDataValidator.reset().parameter("commencementDate").value(commencementDate).ignoreIfNull(); - - final Boolean isLockinPeriodAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element); - baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(isLockinPeriodAllowedCommandValue).trueOrFalseRequired(isBooleanValueUpdated(isLockinPeriodAllowedCommandValue)); - - final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault()); - baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).ignoreIfNull().zeroOrPositiveAmount(); - - final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault()); - baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).ignoreIfNull().inMinMaxRange(1, 3); - - final Integer tenureType = fromApiJsonHelper.extractIntegerNamed("tenureType", element, Locale.getDefault()); + baseDataValidator.reset().parameter("commencementDate").value(commencementDate).ignoreIfNull(); + + final Boolean isLockinPeriodAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element); + baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(isLockinPeriodAllowedCommandValue) + .trueOrFalseRequired(isBooleanValueUpdated(isLockinPeriodAllowedCommandValue)); + + final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault()); + baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).ignoreIfNull().zeroOrPositiveAmount(); + + final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault()); + baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).ignoreIfNull().inMinMaxRange(1, 3); + + final Integer tenureType = fromApiJsonHelper.extractIntegerNamed("tenureType", element, Locale.getDefault()); baseDataValidator.reset().parameter("tenureType").value(tenureType).ignoreIfNull(); - + final Integer frequency = fromApiJsonHelper.extractIntegerNamed("frequency", element, Locale.getDefault()); baseDataValidator.reset().parameter("frequency").value(frequency).ignoreIfNull(); - + final Integer interestType = fromApiJsonHelper.extractIntegerNamed("interestType", element, Locale.getDefault()); baseDataValidator.reset().parameter("interestType").value(interestType).ignoreIfNull(); - - final Integer interestCalculationMethod = fromApiJsonHelper.extractIntegerNamed("interestCalculationMethod", element, Locale.getDefault()); + + final Integer interestCalculationMethod = fromApiJsonHelper.extractIntegerNamed("interestCalculationMethod", element, + Locale.getDefault()); baseDataValidator.reset().parameter("interestCalculationMethod").value(interestCalculationMethod).ignoreIfNull(); - - final BigDecimal minimumBalanceForWithdrawal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalanceForWithdrawal", element); - baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(minimumBalanceForWithdrawal).ignoreIfNull().zeroOrPositiveAmount(); - + + final BigDecimal minimumBalanceForWithdrawal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalanceForWithdrawal", + element); + baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(minimumBalanceForWithdrawal).ignoreIfNull() + .zeroOrPositiveAmount(); + final Boolean isPartialDepositAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isPartialDepositAllowed", element); baseDataValidator.reset().parameter("isPartialDepositAllowed").value(isPartialDepositAllowedCommandValue) - .trueOrFalseRequired(isBooleanValueUpdated(isPartialDepositAllowedCommandValue)).ignoreIfNull(); - - final Integer depositEvery = fromApiJsonHelper.extractIntegerNamed("depositEvery", element, Locale.getDefault()); - baseDataValidator.reset().parameter("depositEvery").value(depositEvery).ignoreIfNull().zeroOrPositiveAmount(); - - final Integer interestPostEvery = fromApiJsonHelper.extractIntegerNamed("interestPostEvery", element, Locale.getDefault()); - baseDataValidator.reset().parameter("interestPostEvery").value(interestPostEvery).ignoreIfNull().zeroOrPositiveAmount(); - - final Integer interestPostFrequency = fromApiJsonHelper.extractIntegerNamed("interestPostFrequency", element, Locale.getDefault()); - baseDataValidator.reset().parameter("interestPostFrequency").value(interestPostFrequency).ignoreIfNull().zeroOrPositiveAmount(); - - throwExceptionIfValidationWarningsExist(dataValidationErrors); - - } - - private Boolean isBooleanValueUpdated(Boolean actualValue) { - Boolean isUpdated = false; - if(actualValue != null){ - isUpdated = true; - } - return isUpdated; - } - - private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); } - } + .trueOrFalseRequired(isBooleanValueUpdated(isPartialDepositAllowedCommandValue)).ignoreIfNull(); -} + final Integer depositEvery = fromApiJsonHelper.extractIntegerNamed("depositEvery", element, Locale.getDefault()); + baseDataValidator.reset().parameter("depositEvery").value(depositEvery).ignoreIfNull().zeroOrPositiveAmount(); + + final Integer interestPostEvery = fromApiJsonHelper.extractIntegerNamed("interestPostEvery", element, Locale.getDefault()); + baseDataValidator.reset().parameter("interestPostEvery").value(interestPostEvery).ignoreIfNull().zeroOrPositiveAmount(); + + final Integer interestPostFrequency = fromApiJsonHelper.extractIntegerNamed("interestPostFrequency", element, Locale.getDefault()); + baseDataValidator.reset().parameter("interestPostFrequency").value(interestPostFrequency).ignoreIfNull().zeroOrPositiveAmount(); + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + + } + + private Boolean isBooleanValueUpdated(final Boolean actualValue) { + Boolean isUpdated = false; + if (actualValue != null) { + isUpdated = true; + } + return isUpdated; + } + + private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); } + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/serialization/SavingAccountStateTransitionCommandFromApiJsonDeserializer.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/serialization/SavingAccountStateTransitionCommandFromApiJsonDeserializer.java index f2c5cf0f7..ff8f47a14 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/serialization/SavingAccountStateTransitionCommandFromApiJsonDeserializer.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/serialization/SavingAccountStateTransitionCommandFromApiJsonDeserializer.java @@ -25,21 +25,21 @@ import com.google.gson.reflect.TypeToken; @Component public class SavingAccountStateTransitionCommandFromApiJsonDeserializer { - - private final Set supportedParams = new HashSet(Arrays.asList("locale", "dateFormat", "commencementDate", "eventDate", + + private final Set supportedParams = new HashSet(Arrays.asList("locale", "dateFormat", "commencementDate", "eventDate", "savingsDepositAmountPerPeriod", "minimumBalanceForWithdrawal", "recurringInterestRate", "savingInterestRate", "depositDate", "interestType", "tenure", "tenureType", "frequency", "payEvery", "note", "interestPostEvery", "interestPostFrequency")); - - private final FromJsonHelper fromApiJsonHelper; - - @Autowired - public SavingAccountStateTransitionCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) { - this.fromApiJsonHelper = fromApiJsonHelper; - } - public void validateForApprove(String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + private final FromJsonHelper fromApiJsonHelper; + + @Autowired + public SavingAccountStateTransitionCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) { + this.fromApiJsonHelper = fromApiJsonHelper; + } + + public void validateForApprove(final String json) { + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams); @@ -48,43 +48,47 @@ public class SavingAccountStateTransitionCommandFromApiJsonDeserializer { final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("saving.account.transition"); final JsonElement element = fromApiJsonHelper.parse(json); - + final LocalDate commencementDate = fromApiJsonHelper.extractLocalDateNamed("commencementDate", element); - baseDataValidator.reset().parameter("commencementDate").value(commencementDate).notNull(); - - final BigDecimal savingsDepositAmountPerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("savingsDepositAmountPerPeriod", element); - baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(savingsDepositAmountPerPeriod).ignoreIfNull().zeroOrPositiveAmount(); - - final BigDecimal minimumBalanceForWithdrawal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalanceForWithdrawal", element); - baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(minimumBalanceForWithdrawal).ignoreIfNull().zeroOrPositiveAmount(); - + baseDataValidator.reset().parameter("commencementDate").value(commencementDate).notNull(); + + final BigDecimal savingsDepositAmountPerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed( + "savingsDepositAmountPerPeriod", element); + baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(savingsDepositAmountPerPeriod).ignoreIfNull() + .zeroOrPositiveAmount(); + + final BigDecimal minimumBalanceForWithdrawal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalanceForWithdrawal", + element); + baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(minimumBalanceForWithdrawal).ignoreIfNull() + .zeroOrPositiveAmount(); + final BigDecimal recurringInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("recurringInterestRate", element); baseDataValidator.reset().parameter("recurringInterestRate").value(recurringInterestRate).ignoreIfNull().zeroOrPositiveAmount(); - + final BigDecimal savingInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("savingInterestRate", element); baseDataValidator.reset().parameter("savingInterestRate").value(savingInterestRate).ignoreIfNull().zeroOrPositiveAmount(); - + final Integer interestType = fromApiJsonHelper.extractIntegerNamed("interestType", element, Locale.getDefault()); baseDataValidator.reset().parameter("interestType").value(interestType).ignoreIfNull().zeroOrPositiveAmount(); - + final Integer tenureType = fromApiJsonHelper.extractIntegerNamed("tenureType", element, Locale.getDefault()); baseDataValidator.reset().parameter("tenureType").value(tenureType).ignoreIfNull().zeroOrPositiveAmount(); - + final Integer tenure = fromApiJsonHelper.extractIntegerNamed("tenure", element, Locale.getDefault()); baseDataValidator.reset().parameter("tenure").value(tenure).ignoreIfNull().zeroOrPositiveAmount(); - + final Integer frequency = fromApiJsonHelper.extractIntegerNamed("frequency", element, Locale.getDefault()); baseDataValidator.reset().parameter("frequency").value(frequency).ignoreIfNull().zeroOrPositiveAmount(); - + final Integer depositEvery = fromApiJsonHelper.extractIntegerNamed("payEvery", element, Locale.getDefault()); - baseDataValidator.reset().parameter("payEvery").value(depositEvery).ignoreIfNull().zeroOrPositiveAmount(); - - throwExceptionIfValidationWarningsExist(dataValidationErrors); - } + baseDataValidator.reset().parameter("payEvery").value(depositEvery).ignoreIfNull().zeroOrPositiveAmount(); - public void validateForReject(String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + public void validateForReject(final String json) { + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams); @@ -93,16 +97,16 @@ public class SavingAccountStateTransitionCommandFromApiJsonDeserializer { final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("saving.account.transition"); final JsonElement element = fromApiJsonHelper.parse(json); - + final LocalDate eventDate = fromApiJsonHelper.extractLocalDateNamed("eventDate", element); baseDataValidator.reset().parameter("eventDate").value(eventDate).notNull(); - - throwExceptionIfValidationWarningsExist(dataValidationErrors); - } - public void validateForWithdrawApplication(String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + public void validateForWithdrawApplication(final String json) { + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams); @@ -111,37 +115,39 @@ public class SavingAccountStateTransitionCommandFromApiJsonDeserializer { final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("saving.account.transition"); final JsonElement element = fromApiJsonHelper.parse(json); - + final LocalDate eventDate = fromApiJsonHelper.extractLocalDateNamed("eventDate", element); baseDataValidator.reset().parameter("eventDate").value(eventDate).notNull(); - - throwExceptionIfValidationWarningsExist(dataValidationErrors); - } - public void validateForDepositAmount(String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + public void validateForDepositAmount(final String json) { + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams); final List dataValidationErrors = new ArrayList(); - final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("saving.account.transaction.deposit"); + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource("saving.account.transaction.deposit"); final JsonElement element = fromApiJsonHelper.parse(json); - + final LocalDate depositDate = fromApiJsonHelper.extractLocalDateNamed("depositDate", element); baseDataValidator.reset().parameter("depositDate").value(depositDate).notNull(); - - final BigDecimal savingsDepositAmountPerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("savingsDepositAmountPerPeriod", element); - baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(savingsDepositAmountPerPeriod).notNull().zeroOrPositiveAmount(); - + + final BigDecimal savingsDepositAmountPerPeriod = fromApiJsonHelper.extractBigDecimalWithLocaleNamed( + "savingsDepositAmountPerPeriod", element); + baseDataValidator.reset().parameter("savingsDepositAmountPerPeriod").value(savingsDepositAmountPerPeriod).notNull() + .zeroOrPositiveAmount(); + throwExceptionIfValidationWarningsExist(dataValidationErrors); - } - - private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { + } + + private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } } - -} +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountAssembler.java index 63d9620c3..8c8c201e6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountAssembler.java @@ -52,10 +52,8 @@ public class SavingAccountAssembler { private final SavingScheduleAssembler savingScheduleAssembler; @Autowired - public SavingAccountAssembler( final ClientRepository clientRepository, - final SavingProductRepository savingProductRepository, - final ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, - final FromJsonHelper fromApiJsonHelper, + public SavingAccountAssembler(final ClientRepository clientRepository, final SavingProductRepository savingProductRepository, + final ReccuringDepositInterestCalculator reccuringDepositInterestCalculator, final FromJsonHelper fromApiJsonHelper, final SavingScheduleAssembler savingScheduleAssembler) { this.clientRepository = clientRepository; this.savingProductRepository = savingProductRepository; @@ -64,10 +62,10 @@ public class SavingAccountAssembler { this.savingScheduleAssembler = savingScheduleAssembler; } - public SavingAccount assembleFrom(JsonCommand command) { - - final JsonElement element = command.parsedJson(); - final Long clientId = fromApiJsonHelper.extractLongNamed("clientId", element); + public SavingAccount assembleFrom(final JsonCommand command) { + + final JsonElement element = command.parsedJson(); + final Long clientId = fromApiJsonHelper.extractLongNamed("clientId", element); final Long productId = fromApiJsonHelper.extractLongNamed("productId", element); final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element); final String currencyCode = command.stringValueOfParameterNamed("currencyCode"); @@ -84,12 +82,13 @@ public class SavingAccountAssembler { final Integer frequencyCommandValue = command.integerValueOfParameterNamed("frequency"); final Integer interestTypeCommandValue = command.integerValueOfParameterNamed("interestType"); final Integer interestCalculationMethodCommandValue = command.integerValueOfParameterNamed("interestCalculationMethod"); - // final BigDecimal minimumBalanceForWithdrawal = command.bigDecimalValueOfParameterNamed("minimumBalanceForWithdrawal"); - // final boolean isPartialDepositAllowed = command.booleanPrimitiveValueOfParameterNamed("isPartialDepositAllowed"); + // final BigDecimal minimumBalanceForWithdrawal = + // command.bigDecimalValueOfParameterNamed("minimumBalanceForWithdrawal"); + // final boolean isPartialDepositAllowed = + // command.booleanPrimitiveValueOfParameterNamed("isPartialDepositAllowed"); final Integer depositEvery = command.integerValueOfParameterNamed("depositEvery"); final Integer interestPostEvery = command.integerValueOfParameterNamed("interestPostEvery"); final Integer interestPostFrequencyCommandValue = command.integerValueOfParameterNamed("interestPostFrequency"); - Client client = this.clientRepository.findOne(clientId); if (client == null || client.isDeleted()) { throw new ClientNotFoundException(clientId); } @@ -103,9 +102,9 @@ public class SavingAccountAssembler { Money savingsDeposit = Money.of(currency, product.getSavingProductRelatedDetail().getSavingsDepositAmount()); if (savingsDepositAmountPerPeriod != null) { - savingsDeposit = Money.of(currency, savingsDepositAmountPerPeriod); - } - + savingsDeposit = Money.of(currency, savingsDepositAmountPerPeriod); + } + Integer tenure = product.getSavingProductRelatedDetail().getTenure(); if (tenureCommandValue != null) { tenure = tenureCommandValue; @@ -123,8 +122,8 @@ public class SavingAccountAssembler { savingFrequencyType = SavingFrequencyType.fromInt(frequencyCommandValue); } - SavingInterestCalculationMethod savingInterestCalculationMethod = SavingInterestCalculationMethod.fromInt(product.getSavingProductRelatedDetail() - .getInterestCalculationMethod()); + SavingInterestCalculationMethod savingInterestCalculationMethod = SavingInterestCalculationMethod.fromInt(product + .getSavingProductRelatedDetail().getInterestCalculationMethod()); if (interestCalculationMethodCommandValue != null) { savingInterestCalculationMethod = SavingInterestCalculationMethod.fromInt(interestCalculationMethodCommandValue); } @@ -151,30 +150,32 @@ public class SavingAccountAssembler { if (lockinPeriodTypeCommandValue != null) { lockinPeriodType = PeriodFrequencyType.fromInt(lockinPeriodTypeCommandValue); } - + Integer interestPostFrequency = PeriodFrequencyType.fromInt(interestPostFrequencyCommandValue).getValue(); SavingAccount account = SavingAccount.openNew(client, product, externalId, savingsDeposit, recurringInterestRate, - savingInterestRate, tenure, commencementDate, tenureTypeEnum, savingProductType, savingFrequencyType, - interestType, savingInterestCalculationMethod, isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, - this.reccuringDepositInterestCalculator, defaultDepositLifecycleStateMachine(),depositEvery,interestPostEvery, interestPostFrequency); + savingInterestRate, tenure, commencementDate, tenureTypeEnum, savingProductType, savingFrequencyType, interestType, + savingInterestCalculationMethod, isLockinPeriodAllowed, lockinPeriod, lockinPeriodType, + this.reccuringDepositInterestCalculator, defaultDepositLifecycleStateMachine(), depositEvery, interestPostEvery, + interestPostFrequency); SavingScheduleData savingScheduleData = this.savingScheduleAssembler.fromJson(element); for (SavingSchedulePeriodData savingSchedulePeriodData : savingScheduleData.getPeriods()) { final SavingScheduleInstallments installment = new SavingScheduleInstallments(account, savingSchedulePeriodData.getDueDate() - .toDate(), savingSchedulePeriodData.getPeriod(), savingSchedulePeriodData.getDepositDue(), savingSchedulePeriodData.getInterestAccured()); + .toDate(), savingSchedulePeriodData.getPeriod(), savingSchedulePeriodData.getDepositDue(), + savingSchedulePeriodData.getInterestAccured()); account.addSavingScheduleInstallment(installment); } return account; } - public Map assembleFrom(JsonCommand command, SavingAccount account) { - - JsonElement element = command.parsedJson(); - Map actualChanges = new LinkedHashMap(20); - final String localeAsInput = command.locale(); + public Map assembleFrom(final JsonCommand command, final SavingAccount account) { + + JsonElement element = command.parsedJson(); + Map actualChanges = new LinkedHashMap(20); + final String localeAsInput = command.locale(); SavingProduct product = account.getProduct(); final String productIdParamName = "productId"; @@ -196,7 +197,7 @@ public class SavingAccountAssembler { } Money savingsDeposit = Money.of(product.getCurrency(), account.getSavingsDepositAmountPerPeriod()); - + final String savingsDepositAmountPerPeriodParamName = "savingsDepositAmountPerPeriod"; if (command.isChangeInBigDecimalParameterNamed(savingsDepositAmountPerPeriodParamName, savingsDeposit.getAmount())) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(savingsDepositAmountPerPeriodParamName); @@ -204,7 +205,7 @@ public class SavingAccountAssembler { actualChanges.put("locale", localeAsInput); savingsDeposit = Money.of(savingsDeposit.getCurrency(), newValue); } - + Integer tenure = account.getTenure(); final String tenureParamName = "tenure"; if (command.isChangeInIntegerParameterNamed(tenureParamName, tenure)) { @@ -213,7 +214,7 @@ public class SavingAccountAssembler { actualChanges.put("locale", localeAsInput); tenure = newValue; } - + LocalDate commencementDate = new LocalDate(account.getProjectedCommencementDate()); final String commencementDateParamName = "commencementDate"; if (command.isChangeInLocalDateParameterNamed("commencementDate", commencementDate)) { @@ -221,7 +222,7 @@ public class SavingAccountAssembler { actualChanges.put(commencementDateParamName, newValue); commencementDate = newValue; } - + TenureTypeEnum tenureTypeEnum = TenureTypeEnum.fromInt(account.getTenureType()); final String tenureTypeParamName = "tenureType"; if (command.isChangeInIntegerParameterNamed(tenureTypeParamName, tenureTypeEnum.getValue())) { @@ -230,7 +231,7 @@ public class SavingAccountAssembler { actualChanges.put("locale", localeAsInput); tenureTypeEnum = TenureTypeEnum.fromInt(newValue); } - + SavingProductType savingProductType = SavingProductType.fromInt(account.getSavingProductType()); SavingFrequencyType savingFrequencyType = SavingFrequencyType.fromInt(account.getFrequency()); @@ -242,7 +243,8 @@ public class SavingAccountAssembler { savingFrequencyType = SavingFrequencyType.fromInt(newValue); } - SavingInterestCalculationMethod savingInterestCalculationMethod = SavingInterestCalculationMethod.fromInt(account.getInterestCalculationMethod()); + SavingInterestCalculationMethod savingInterestCalculationMethod = SavingInterestCalculationMethod.fromInt(account + .getInterestCalculationMethod()); final String interestCalculationMethodParamName = "interestCalculationMethod"; if (command.isChangeInIntegerParameterNamed(interestCalculationMethodParamName, savingInterestCalculationMethod.getValue())) { final Integer newValue = command.integerValueOfParameterNamed(interestCalculationMethodParamName); @@ -259,7 +261,7 @@ public class SavingAccountAssembler { actualChanges.put("locale", localeAsInput); reccuringInterestRate = newValue; } - + BigDecimal savingInterestRate = account.getSavingInterestRate(); final String savingInterestRateParamName = "savingInterestRate"; if (command.isChangeInBigDecimalParameterNamed(savingInterestRateParamName, savingInterestRate)) { @@ -268,7 +270,7 @@ public class SavingAccountAssembler { actualChanges.put("locale", localeAsInput); savingInterestRate = newValue; } - + Boolean isLockinPeriodAllowed = account.isLockinPeriodAllowed(); final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed"; if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, isLockinPeriodAllowed)) { @@ -304,7 +306,7 @@ public class SavingAccountAssembler { actualChanges.put("locale", localeAsInput); payEvery = newValue; } - + SavingsInterestType interestType = SavingsInterestType.fromInt(product.getSavingProductRelatedDetail().getInterestType()); final String interestTypeParamName = "interestType"; if (command.isChangeInIntegerParameterNamed(interestTypeParamName, interestType.getValue())) { @@ -313,7 +315,7 @@ public class SavingAccountAssembler { actualChanges.put("locale", localeAsInput); interestType = SavingsInterestType.fromInt(newValue); } - + Integer interestPostEvery = account.getInterestPostEvery(); final String interestPostEveryParamName = "interestPostEvery"; if (command.isChangeInIntegerParameterNamed(interestPostEveryParamName, interestPostEvery)) { @@ -323,7 +325,7 @@ public class SavingAccountAssembler { interestPostEvery = newValue; } - Integer interestPostFrequency =account.getInterestPostFrequency(); + Integer interestPostFrequency = account.getInterestPostFrequency(); final String interestPostFrequencyParamName = "interestPostFrequency"; if (command.isChangeInIntegerParameterNamed(interestPostFrequencyParamName, interestPostFrequency)) { final Integer newValue = command.integerValueOfParameterNamed(interestPostFrequencyParamName); @@ -334,16 +336,18 @@ public class SavingAccountAssembler { account.modifyAccount(product, externalId, savingsDeposit, reccuringInterestRate, savingInterestRate, tenure, commencementDate, tenureTypeEnum, savingProductType, savingFrequencyType, savingInterestCalculationMethod, isLockinPeriodAllowed, - lockinPeriod, lockinPeriodType, this.reccuringDepositInterestCalculator,payEvery, interestType, interestPostEvery, interestPostFrequency); - + lockinPeriod, lockinPeriodType, this.reccuringDepositInterestCalculator, payEvery, interestType, interestPostEvery, + interestPostFrequency); + SavingScheduleData savingScheduleData = this.savingScheduleAssembler.fromJson(element); for (SavingSchedulePeriodData savingSchedulePeriodData : savingScheduleData.getPeriods()) { final SavingScheduleInstallments installment = new SavingScheduleInstallments(account, savingSchedulePeriodData.getDueDate() - .toDate(), savingSchedulePeriodData.getPeriod(), savingSchedulePeriodData.getDepositDue(), savingSchedulePeriodData.getInterestAccured()); + .toDate(), savingSchedulePeriodData.getPeriod(), savingSchedulePeriodData.getDepositDue(), + savingSchedulePeriodData.getInterestAccured()); account.addSavingScheduleInstallment(installment); } - + return actualChanges; } @@ -353,151 +357,156 @@ public class SavingAccountAssembler { return new DepositLifecycleStateMachineImpl(allowedDepositStatuses); } - public Map approveSavingAccount(JsonCommand command, SavingAccount account) { - - JsonElement element = command.parsedJson(); - Map actualChanges = new LinkedHashMap(20); - final String localeAsInput = command.locale(); + public Map approveSavingAccount(final JsonCommand command, final SavingAccount account) { - LocalDate approvalDate = account.projectedCommencementDate(); - final String commencementDateParamName = "commencementDate"; + JsonElement element = command.parsedJson(); + Map actualChanges = new LinkedHashMap(20); + final String localeAsInput = command.locale(); + + LocalDate approvalDate = account.projectedCommencementDate(); + final String commencementDateParamName = "commencementDate"; if (command.isChangeInLocalDateParameterNamed("commencementDate", approvalDate)) { final LocalDate newValue = command.localDateValueOfParameterNamed(commencementDateParamName); actualChanges.put(commencementDateParamName, newValue); approvalDate = newValue; } - - BigDecimal savingsDepositAmountPerPeriod=account.getSavingsDepositAmountPerPeriod(); - final String savingsDepositAmountPerPeriodParamName = "savingsDepositAmountPerPeriod"; - if (command.isChangeInBigDecimalParameterNamed(savingsDepositAmountPerPeriodParamName, savingsDepositAmountPerPeriod)) { + + BigDecimal savingsDepositAmountPerPeriod = account.getSavingsDepositAmountPerPeriod(); + final String savingsDepositAmountPerPeriodParamName = "savingsDepositAmountPerPeriod"; + if (command.isChangeInBigDecimalParameterNamed(savingsDepositAmountPerPeriodParamName, savingsDepositAmountPerPeriod)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(savingsDepositAmountPerPeriodParamName); actualChanges.put(savingsDepositAmountPerPeriodParamName, newValue); actualChanges.put("locale", localeAsInput); savingsDepositAmountPerPeriod = newValue; } - - BigDecimal recurringInterestRate = account.getReccuringInterestRate(); - final String reccuringInterestRateParamName = "reccuringInterestRate"; + + BigDecimal recurringInterestRate = account.getReccuringInterestRate(); + final String reccuringInterestRateParamName = "reccuringInterestRate"; if (command.isChangeInBigDecimalParameterNamed(reccuringInterestRateParamName, recurringInterestRate)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(reccuringInterestRateParamName); actualChanges.put(reccuringInterestRateParamName, newValue); actualChanges.put("locale", localeAsInput); recurringInterestRate = newValue; } - - BigDecimal savingInterestRate = account.getSavingInterestRate(); - final String savingInterestRateParamName = "savingInterestRate"; + + BigDecimal savingInterestRate = account.getSavingInterestRate(); + final String savingInterestRateParamName = "savingInterestRate"; if (command.isChangeInBigDecimalParameterNamed(savingInterestRateParamName, savingInterestRate)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(savingInterestRateParamName); actualChanges.put(savingInterestRateParamName, newValue); actualChanges.put("locale", localeAsInput); savingInterestRate = newValue; } - - Integer interestType = account.getInterestType(); - final String interestTypeParamName = "interestType"; + + Integer interestType = account.getInterestType(); + final String interestTypeParamName = "interestType"; if (command.isChangeInIntegerParameterNamed(interestTypeParamName, interestType)) { final Integer newValue = command.integerValueOfParameterNamed(interestTypeParamName); actualChanges.put(interestTypeParamName, newValue); actualChanges.put("locale", localeAsInput); interestType = SavingsInterestType.fromInt(newValue).getValue(); } - - Integer tenure = account.getTenure(); - final String tenureParamName = "tenure"; + + Integer tenure = account.getTenure(); + final String tenureParamName = "tenure"; if (command.isChangeInIntegerParameterNamed(tenureParamName, tenure)) { final Integer newValue = command.integerValueOfParameterNamed(tenureParamName); actualChanges.put(tenureParamName, newValue); actualChanges.put("locale", localeAsInput); tenure = newValue; } - - Integer tenureType = account.getTenureType(); - final String tenureTypeParamName = "tenureType"; + + Integer tenureType = account.getTenureType(); + final String tenureTypeParamName = "tenureType"; if (command.isChangeInIntegerParameterNamed(tenureTypeParamName, tenureType)) { final Integer newValue = command.integerValueOfParameterNamed(tenureTypeParamName); actualChanges.put(tenureTypeParamName, newValue); actualChanges.put("locale", localeAsInput); tenureType = TenureTypeEnum.fromInt(newValue).getValue(); } - - Integer frequency = account.getFrequency(); - final String frequencyParamName = "frequency"; + + Integer frequency = account.getFrequency(); + final String frequencyParamName = "frequency"; if (command.isChangeInIntegerParameterNamed(frequencyParamName, frequency)) { final Integer newValue = command.integerValueOfParameterNamed(frequencyParamName); actualChanges.put(frequencyParamName, newValue); actualChanges.put("locale", localeAsInput); frequency = SavingFrequencyType.fromInt(newValue).getValue(); } - - Integer depositEvery = account.getPayEvery(); - final String depositEveryParamName = "depositEvery"; + + Integer depositEvery = account.getPayEvery(); + final String depositEveryParamName = "depositEvery"; if (command.isChangeInIntegerParameterNamed(depositEveryParamName, depositEvery)) { final Integer newValue = command.integerValueOfParameterNamed(depositEveryParamName); actualChanges.put(depositEveryParamName, newValue); actualChanges.put("locale", localeAsInput); depositEvery = newValue; } - - Integer interestPostEvery = account.getInterestPostEvery(); - final String interestPostEveryParamName = "interestPostEvery"; + + Integer interestPostEvery = account.getInterestPostEvery(); + final String interestPostEveryParamName = "interestPostEvery"; if (command.isChangeInIntegerParameterNamed(interestPostEveryParamName, interestPostEvery)) { final Integer newValue = command.integerValueOfParameterNamed(interestPostEveryParamName); actualChanges.put(interestPostEveryParamName, newValue); actualChanges.put("locale", localeAsInput); interestPostEvery = newValue; } - - Integer interestPostFrequency =account.getInterestPostFrequency(); - final String interestPostFrequencyParamName = "interestPostFrequency"; + + Integer interestPostFrequency = account.getInterestPostFrequency(); + final String interestPostFrequencyParamName = "interestPostFrequency"; if (command.isChangeInIntegerParameterNamed(interestPostFrequencyParamName, interestPostFrequency)) { final Integer newValue = command.integerValueOfParameterNamed(interestPostFrequencyParamName); actualChanges.put(interestPostFrequencyParamName, newValue); actualChanges.put("locale", localeAsInput); interestPostFrequency = PeriodFrequencyType.fromInt(newValue).getValue(); } - - account.approveSavingAccount(approvalDate, savingsDepositAmountPerPeriod, recurringInterestRate, savingInterestRate, interestType, - tenure, tenureType, frequency, depositEvery,defaultDepositLifecycleStateMachine(),this.reccuringDepositInterestCalculator, interestPostEvery, interestPostFrequency); - - - /*CalculateSavingScheduleCommand calculateSavingScheduleCommand = new CalculateSavingScheduleCommand(account.getProduct().getId(), savingsDepositAmountPerPeriod, payEvery, - frequency, recurringInterestRate, approvalDate, tenure,tenureType,interestPostEvery,interestPostFrequency,account.getInterestCalculationMethod());*/ - - SavingScheduleData savingScheduleData = this.savingScheduleAssembler.calculateSavingSchedule(element,account); + + account.approveSavingAccount(approvalDate, savingsDepositAmountPerPeriod, recurringInterestRate, savingInterestRate, interestType, + tenure, tenureType, frequency, depositEvery, defaultDepositLifecycleStateMachine(), + this.reccuringDepositInterestCalculator, interestPostEvery, interestPostFrequency); + + /* + * CalculateSavingScheduleCommand calculateSavingScheduleCommand = new + * CalculateSavingScheduleCommand(account.getProduct().getId(), + * savingsDepositAmountPerPeriod, payEvery, frequency, + * recurringInterestRate, approvalDate, + * tenure,tenureType,interestPostEvery + * ,interestPostFrequency,account.getInterestCalculationMethod()); + */ + + SavingScheduleData savingScheduleData = this.savingScheduleAssembler.calculateSavingSchedule(element, account); for (SavingSchedulePeriodData savingSchedulePeriodData : savingScheduleData.getPeriods()) { final SavingScheduleInstallments installment = new SavingScheduleInstallments(account, savingSchedulePeriodData.getDueDate() - .toDate(), savingSchedulePeriodData.getPeriod(), savingSchedulePeriodData.getDepositDue(),savingSchedulePeriodData.getInterestAccured()); + .toDate(), savingSchedulePeriodData.getPeriod(), savingSchedulePeriodData.getDepositDue(), + savingSchedulePeriodData.getInterestAccured()); account.addSavingScheduleInstallment(installment); } - + return actualChanges; - } + } - public void withdrawSavingAccountMoney( JsonCommand command, SavingAccount account) { - - LocalDate transactionDate = command.localDateValueOfParameterNamed("transactionDate"); - BigDecimal withdraAmount = command.bigDecimalValueOfParameterNamed("amount"); - if (withdraAmount.doubleValue() > account.getOutstandingAmount().doubleValue()) { - throw new DepositAccountTransactionsException("deposit.transaction.interest.withdrawal.exceed", "You can Withdraw " - + account.getOutstandingAmount() + " only"); - } - - account.withdrawAmount(withdraAmount, transactionDate); - - } + public void withdrawSavingAccountMoney(final JsonCommand command, final SavingAccount account) { - public void postInterest(SavingAccount account) { - account.postInterest(); - } - - private Boolean isBooleanValueUpdated(Boolean actualValue) { - Boolean isUpdated = false; - if(actualValue != null){ - isUpdated = true; - } - return isUpdated; - } + LocalDate transactionDate = command.localDateValueOfParameterNamed("transactionDate"); + BigDecimal withdraAmount = command.bigDecimalValueOfParameterNamed("amount"); + if (withdraAmount.doubleValue() > account.getOutstandingAmount().doubleValue()) { throw new DepositAccountTransactionsException( + "deposit.transaction.interest.withdrawal.exceed", "You can Withdraw " + account.getOutstandingAmount() + " only"); } + + account.withdrawAmount(withdraAmount, transactionDate); + + } + + public void postInterest(final SavingAccount account) { + account.postInterest(); + } + + private Boolean isBooleanValueUpdated(final Boolean actualValue) { + Boolean isUpdated = false; + if (actualValue != null) { + isUpdated = true; + } + return isUpdated; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingProductRelatedDetailAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingProductRelatedDetailAssembler.java deleted file mode 100644 index 9efff5c73..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingProductRelatedDetailAssembler.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccount.service; - -import org.mifosplatform.portfolio.savingsaccount.command.CalculateSavingScheduleCommand; -import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingProduct; -import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingProductRelatedDetail; -import org.mifosplatform.portfolio.savingsaccountproduct.domain.SavingProductRepository; -import org.mifosplatform.portfolio.savingsaccountproduct.exception.SavingProductNotFoundException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class SavingProductRelatedDetailAssembler { - - private final SavingProductRepository savingProductRepository; - - @Autowired - public SavingProductRelatedDetailAssembler(final SavingProductRepository savingProductRepository) { - this.savingProductRepository = savingProductRepository; - } - - public SavingProductRelatedDetail assembleFrom(final CalculateSavingScheduleCommand command) { - -// final BigDecimal depositAmountForPeriod = command.getDeposit(); -// final BigDecimal depositInterestRate = command.getInterestRate(); -// final LocalDate installmentDate = command.getPaymentsStartingFromDate(); -// final Integer payEvery = command.getPayEvery(); -// final Integer paymentFrequencyType = command.getPaymentFrequencyType(); - - final SavingProduct savingProduct = this.savingProductRepository.findOne(command.getProductId()); - if (savingProduct == null) { throw new SavingProductNotFoundException(command.getProductId()); } - -// final MonetaryCurrency currency = savingProduct.getCurrency(); - - return null; - } - -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/api/SavingProductsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/api/SavingProductsApiResource.java index b62d89ec6..41029b5e2 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/api/SavingProductsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/api/SavingProductsApiResource.java @@ -51,12 +51,12 @@ import org.springframework.stereotype.Component; @Component @Scope("singleton") public class SavingProductsApiResource { - - private final Set SAVINGS_PRODUCT_DATA_PARAMETERS = new HashSet(Arrays.asList("currencyOptions", "id", - "createdOn", "lastModifedOn", "locale", "name", "description", "currencyCode", "digitsAfterDecimal", "interstRate", - "minInterestRate", "maxInterestRate", "savingsDepositAmount", "savingProductType", "tenureType", "tenure", "frequency", - "interestType", "interestCalculationMethod", "minimumBalanceForWithdrawal", "isPartialDepositAllowed", "isLockinPeriodAllowed", - "lockinPeriod", "lockinPeriodType", "currencyOptions", "savingsProductTypeOptions", "tenureTypeOptions", "depositEvery", + + private final Set SAVINGS_PRODUCT_DATA_PARAMETERS = new HashSet(Arrays.asList("currencyOptions", "id", "createdOn", + "lastModifedOn", "locale", "name", "description", "currencyCode", "digitsAfterDecimal", "interstRate", "minInterestRate", + "maxInterestRate", "savingsDepositAmount", "savingProductType", "tenureType", "tenure", "frequency", "interestType", + "interestCalculationMethod", "minimumBalanceForWithdrawal", "isPartialDepositAllowed", "isLockinPeriodAllowed", "lockinPeriod", + "lockinPeriodType", "currencyOptions", "savingsProductTypeOptions", "tenureTypeOptions", "depositEvery", "savingFrequencyOptions", "savingsInterestTypeOptions", "lockinPeriodTypeOptions", "interestCalculationOptions")); private final SavingProductReadPlatformService savingProductReadPlatformService; @@ -66,30 +66,29 @@ public class SavingProductsApiResource { private final DefaultToApiJsonSerializer toApiJsonSerializer; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final ApiRequestParameterHelper apiRequestParameterHelper; - + @Autowired public SavingProductsApiResource(final SavingProductReadPlatformService savingProductReadPlatformService, - final CurrencyReadPlatformService currencyReadPlatformService, - final PlatformSecurityContext context, - final DefaultToApiJsonSerializer toApiJsonSerializer, - final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, - final ApiRequestParameterHelper apiRequestParameterHelper) { - this.savingProductReadPlatformService = savingProductReadPlatformService; - this.currencyReadPlatformService = currencyReadPlatformService; - this.context = context; - this.toApiJsonSerializer = toApiJsonSerializer; - this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; - this.apiRequestParameterHelper = apiRequestParameterHelper; - } + final CurrencyReadPlatformService currencyReadPlatformService, final PlatformSecurityContext context, + final DefaultToApiJsonSerializer toApiJsonSerializer, + final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, + final ApiRequestParameterHelper apiRequestParameterHelper) { + this.savingProductReadPlatformService = savingProductReadPlatformService; + this.currencyReadPlatformService = currencyReadPlatformService; + this.context = context; + this.toApiJsonSerializer = toApiJsonSerializer; + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + this.apiRequestParameterHelper = apiRequestParameterHelper; + } @POST @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String createSavingProduct(final String apiRequestBodyAsJson) { - - final CommandWrapper commandRequest = new CommandWrapperBuilder().createSavingProduct().withJson(apiRequestBodyAsJson).build(); - - final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + + final CommandWrapper commandRequest = new CommandWrapperBuilder().createSavingProduct().withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); @@ -101,25 +100,26 @@ public class SavingProductsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String updateSavingProduct(@PathParam("productId") final Long productId, final String apiRequestBodyAsJson) { - final CommandWrapper commandRequest = new CommandWrapperBuilder().updateSavingProduct(productId).withJson(apiRequestBodyAsJson).build(); - - final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateSavingProduct(productId).withJson(apiRequestBodyAsJson) + .build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); - + } @GET @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String retrieveAllSavingProducts(@Context final UriInfo uriInfo) { - - context.authenticatedUser().validateHasReadPermission(entityType); - + + context.authenticatedUser().validateHasReadPermission(entityType); + Collection products = this.savingProductReadPlatformService.retrieveAllSavingProducts(); - + final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); - + return this.toApiJsonSerializer.serialize(settings, products, SAVINGS_PRODUCT_DATA_PARAMETERS); } @@ -132,7 +132,7 @@ public class SavingProductsApiResource { context.authenticatedUser().validateHasReadPermission(entityType); SavingProductData savingProduct = this.savingProductReadPlatformService.retrieveSavingProduct(productId); - + final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); if (settings.isTemplate()) { @@ -151,15 +151,15 @@ public class SavingProductsApiResource { context.authenticatedUser().validateHasReadPermission(entityType); SavingProductData savingProduct = this.savingProductReadPlatformService.retrieveNewSavingProductDetails(); - + final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); - + savingProduct = handleTemplateRelatedData(savingProduct); - + return this.toApiJsonSerializer.serialize(settings, savingProduct, SAVINGS_PRODUCT_DATA_PARAMETERS); } - private SavingProductData handleTemplateRelatedData(SavingProductData savingProduct) { + private SavingProductData handleTemplateRelatedData(final SavingProductData savingProduct) { Collection currencyOptions = this.currencyReadPlatformService.retrieveAllowedCurrencies(); @@ -196,10 +196,10 @@ public class SavingProductsApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String deleteProduct(@PathParam("productId") final Long productId) { - - final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteSavingProduct(productId).build(); - - final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + + final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteSavingProduct(productId).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/command/SavingProductCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/command/SavingProductCommand.java deleted file mode 100644 index ae81293a0..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/command/SavingProductCommand.java +++ /dev/null @@ -1,228 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccountproduct.command; - -import java.math.BigDecimal; -import java.util.Set; - -public class SavingProductCommand { - - private final Long id; - private final String name; - private final String description; - - private final String currencyCode; - private final Integer digitsAfterDecimal; - private final BigDecimal interestRate; - private final BigDecimal minInterestRate; - private final BigDecimal maxInterestRate; - - private final BigDecimal savingsDepositAmount; - private final Integer depositEvery; - private final Integer savingProductType; - private final Integer tenureType; - private final Integer tenure; - private final Integer frequency; - private final Integer interestType; - private final Integer interestCalculationMethod; - private final BigDecimal minimumBalanceForWithdrawal; - private final boolean isPartialDepositAllowed; - private final boolean isLockinPeriodAllowed; - private final Integer lockinPeriod; - private final Integer lockinPeriodType; - - private final Set modifiedParameters; - - public SavingProductCommand(Set modifiedParameters, Long id, String name, String description, String currencyCode, - Integer digitsAfterDecimal, BigDecimal interestRate, BigDecimal minInterestRate, BigDecimal maxInterestRate, - BigDecimal savingsDepositAmount, Integer depositEvery,Integer savingProductType, Integer tenureType, Integer tenure, Integer frequency, - Integer interestType, Integer interestCalculationMethod, BigDecimal minimumBalanceForWithdrawal, - boolean isPartialDepositAllowed, boolean isLockinPeriodAllowed, Integer lockinPeriod, Integer lockinPeriodType) { - - this.id = id; - this.name = name; - this.description = description; - - this.currencyCode = currencyCode; - this.digitsAfterDecimal = digitsAfterDecimal; - this.interestRate = interestRate; - this.minInterestRate = minInterestRate; - this.maxInterestRate = maxInterestRate; - - this.savingsDepositAmount = savingsDepositAmount; - this.depositEvery = depositEvery; - this.savingProductType = savingProductType; - this.tenureType = tenureType; - this.tenure = tenure; - this.frequency = frequency; - this.interestType = interestType; - this.interestCalculationMethod = interestCalculationMethod; - this.minimumBalanceForWithdrawal = minimumBalanceForWithdrawal; - this.isPartialDepositAllowed = isPartialDepositAllowed; - this.isLockinPeriodAllowed = isLockinPeriodAllowed; - this.lockinPeriod = lockinPeriod; - this.lockinPeriodType = lockinPeriodType; - - this.modifiedParameters = modifiedParameters; - } - - public Long getId() { - return id; - } - - public String getName() { - return name; - } - - public String getDescription() { - return description; - } - - public String getCurrencyCode() { - return currencyCode; - } - - public Integer getDigitsAfterDecimal() { - return digitsAfterDecimal; - } - - public BigDecimal getInterestRate() { - return interestRate; - } - - public BigDecimal getMinInterestRate() { - return minInterestRate; - } - - public BigDecimal getMaxInterestRate() { - return maxInterestRate; - } - - public BigDecimal getSavingsDepositAmount() { - return savingsDepositAmount; - } - - public Integer getDepositEvery() { - return this.depositEvery; - } - - public Integer getSavingProductType() { - return savingProductType; - } - - public Integer getTenureType() { - return tenureType; - } - - public Integer getTenure() { - return tenure; - } - - public Integer getFrequency() { - return frequency; - } - - public Integer getInterestType() { - return interestType; - } - - public Integer getInterestCalculationMethod() { - return interestCalculationMethod; - } - - public BigDecimal getMinimumBalanceForWithdrawal() { - return minimumBalanceForWithdrawal; - } - - public boolean isPartialDepositAllowed() { - return isPartialDepositAllowed; - } - - public boolean isLockinPeriodAllowed() { - return isLockinPeriodAllowed; - } - - public Integer getLockinPeriod() { - return lockinPeriod; - } - - public Integer getLockinPeriodType() { - return lockinPeriodType; - } - - public boolean isNameChanged() { - return this.modifiedParameters.contains("name"); - } - - public boolean isDescriptionChanged() { - return this.modifiedParameters.contains("description"); - } - - public boolean isCurrencyCodeChanged() { - return this.modifiedParameters.contains("currencyCode"); - } - - public boolean isDigitsAfterDecimalChanged() { - return this.modifiedParameters.contains("digitsAfterDecimal"); - } - - public boolean isInterestRateChanged() { - return this.modifiedParameters.contains("interestRate"); - } - - public boolean isSavingsDepositAmountChanged() { - return this.modifiedParameters.contains("savingsDepositAmount"); - } - - public boolean isDepositEveryChanged() { - return this.modifiedParameters.contains("depositEvery"); - } - - public boolean isSavingProductTypeChanged() { - return this.modifiedParameters.contains("savingProductType"); - } - - public boolean isTenureTypeChanged() { - return this.modifiedParameters.contains("tenureType"); - } - - public boolean isTenureChanged() { - return this.modifiedParameters.contains("tenure"); - } - - public boolean isFrequencyChanged() { - return this.modifiedParameters.contains("frequency"); - } - - public boolean isInterestTypeChanged() { - return this.modifiedParameters.contains("interestType"); - } - - public boolean isInterestCalculationMethodChanged() { - return this.modifiedParameters.contains("interestCalculationMethod"); - } - - public boolean isMinimumBalanceForWithdrawalChanged() { - return this.modifiedParameters.contains("minimumBalanceForWithdrawal"); - } - - public boolean isPartialDepositAllowedChanged() { - return this.modifiedParameters.contains("isPartialDepositAllowed"); - } - - public boolean isLockinPeriodAllowedChanged() { - return this.modifiedParameters.contains("isLockinPeriodAllowed"); - } - - public boolean isLockinPeriodChanged() { - return this.modifiedParameters.contains("lockinPeriod"); - } - - public boolean isLockinPeriodTypeChanged() { - return this.modifiedParameters.contains("lockinPeriodType"); - } - -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/data/SavingProductLookup.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/data/SavingProductLookup.java index 6bd1f5e3b..da667f8c7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/data/SavingProductLookup.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/data/SavingProductLookup.java @@ -13,11 +13,11 @@ public class SavingProductLookup implements Serializable { private final String name; public SavingProductLookup() { - this.id=null; - this.name=null; + this.id = null; + this.name = null; } - public SavingProductLookup(Long id, String name) { + public SavingProductLookup(final Long id, final String name) { this.id = id; this.name = name; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingFrequencyType.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingFrequencyType.java index f957d84e5..88c92fa77 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingFrequencyType.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingFrequencyType.java @@ -7,8 +7,12 @@ package org.mifosplatform.portfolio.savingsaccountproduct.domain; public enum SavingFrequencyType { - INVALID(0, "savingFrequencyType.invalid"), DAILY(1, "savingFrequencyType.daily"), MONTHLY(2, "savingFrequencyType.monthly"), QUATERLY( - 3, "savingFrequencyType.quaterly"), HALFYEARLY(4, "savingFrequencyType.halfyearly"), YEARLY(5, "savingFrequencyType.yearly"); + INVALID(0, "savingFrequencyType.invalid"), // + DAILY(1, "savingFrequencyType.daily"), // + MONTHLY(2, "savingFrequencyType.monthly"), // + QUATERLY(3, "savingFrequencyType.quaterly"), // + HALFYEARLY(4, "savingFrequencyType.halfyearly"), // + YEARLY(5, "savingFrequencyType.yearly"); private final Integer value; private final String code; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingInterestCalculationMethod.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingInterestCalculationMethod.java index 503a3cbdc..f0747a96a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingInterestCalculationMethod.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingInterestCalculationMethod.java @@ -7,8 +7,10 @@ package org.mifosplatform.portfolio.savingsaccountproduct.domain; public enum SavingInterestCalculationMethod { - AVERAGEBAL(1, "savinginterest.calculation.method.averagebal"), MINBAL(2, "savinginterest.calculation.method.minbal"), MONTHLYCOLLECTION( - 3, "savinginterest.calculation.method.monthlycllection"), INVALID(0, "savinginterest.calculation.method.invalid"); + INVALID(0, "savinginterest.calculation.method.invalid"), // + AVERAGEBAL(1, "savinginterest.calculation.method.averagebal"), // + MINBAL(2, "savinginterest.calculation.method.minbal"), // + MONTHLYCOLLECTION(3, "savinginterest.calculation.method.monthlycllection"); private final Integer value; private final String code; @@ -46,11 +48,11 @@ public enum SavingInterestCalculationMethod { return savingInterestCalculationMethod; } - public boolean isAverageBalance() { - return this.value.equals(SavingInterestCalculationMethod.AVERAGEBAL.value); - } + public boolean isAverageBalance() { + return this.value.equals(SavingInterestCalculationMethod.AVERAGEBAL.value); + } - public boolean isMonthlyCollection() { - return this.value.equals(SavingInterestCalculationMethod.MONTHLYCOLLECTION.value); - } + public boolean isMonthlyCollection() { + return this.value.equals(SavingInterestCalculationMethod.MONTHLYCOLLECTION.value); + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProduct.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProduct.java index 6d0d26a4d..5397bee6c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProduct.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProduct.java @@ -36,7 +36,7 @@ public class SavingProduct extends AbstractAuditableCustom { private boolean deleted = false; @Embedded - SavingProductRelatedDetail savingProductRelatedDetail; + private final SavingProductRelatedDetail savingProductRelatedDetail; protected SavingProduct() { this.name = null; @@ -45,10 +45,10 @@ public class SavingProduct extends AbstractAuditableCustom { } public SavingProduct(final String name, final String description, final MonetaryCurrency currency, final BigDecimal interestRate, - final BigDecimal minInterestRate, final BigDecimal maxInterestRate, final BigDecimal savingsDepositAmount,Integer depositEvery, - final SavingProductType savingProductType, final TenureTypeEnum tenureType, final Integer tenure, + final BigDecimal minInterestRate, final BigDecimal maxInterestRate, final BigDecimal savingsDepositAmount, + final Integer depositEvery, final SavingProductType savingProductType, final TenureTypeEnum tenureType, final Integer tenure, final SavingFrequencyType savingFrequencyType, final SavingsInterestType savingsInterestType, - SavingInterestCalculationMethod savingInterestCalculationMethod, final BigDecimal minimumBalanceForWithdrawal, + final SavingInterestCalculationMethod savingInterestCalculationMethod, final BigDecimal minimumBalanceForWithdrawal, final boolean isPartialDepositAllowed, final boolean isLockinPeriodAllowed, final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType) { @@ -98,15 +98,15 @@ public class SavingProduct extends AbstractAuditableCustom { public Map update(final JsonCommand command) { - final Map actualChanges = new LinkedHashMap(20); - - final String nameParamName = "name"; + final Map actualChanges = new LinkedHashMap(20); + + final String nameParamName = "name"; if (command.isChangeInStringParameterNamed(nameParamName, this.name)) { final String newValue = command.stringValueOfParameterNamed(nameParamName); actualChanges.put(nameParamName, newValue); this.name = newValue; } - + final String descriptionParamName = "description"; if (command.isChangeInStringParameterNamed(descriptionParamName, this.description)) { final String newValue = command.stringValueOfParameterNamed(descriptionParamName); @@ -117,25 +117,26 @@ public class SavingProduct extends AbstractAuditableCustom { return this.savingProductRelatedDetail.update(command, actualChanges); } - public static SavingProduct assembleFromJson(JsonCommand command, MonetaryCurrency currency, SavingProductType savingProductType, TenureTypeEnum tenureType, - SavingFrequencyType savingFrequencyType, SavingsInterestType interestType, SavingInterestCalculationMethod savingInterestCalculationMethod, - PeriodFrequencyType lockinPeriodType) { + public static SavingProduct assembleFromJson(final JsonCommand command, final MonetaryCurrency currency, + final SavingProductType savingProductType, final TenureTypeEnum tenureType, final SavingFrequencyType savingFrequencyType, + final SavingsInterestType interestType, final SavingInterestCalculationMethod savingInterestCalculationMethod, + final PeriodFrequencyType lockinPeriodType) { - final String name = command.stringValueOfParameterNamed("name"); - final String description = command.stringValueOfParameterNamed("description"); - final BigDecimal interestRate = command.bigDecimalValueOfParameterNamed("interestRate"); - final BigDecimal minInterestRate = command.bigDecimalValueOfParameterNamed("minInterestRate"); - final BigDecimal maxInterestRate = command.bigDecimalValueOfParameterNamed("maxInterestRate"); - final BigDecimal savingsDepositAmount = command.bigDecimalValueOfParameterNamed("savingsDepositAmount"); - final Integer tenure = command.integerValueOfParameterNamed("tenure"); - final BigDecimal minimumBalanceForWithdrawal = command.bigDecimalValueOfParameterNamed("minimumBalanceForWithdrawal"); - final boolean isPartialDepositAllowed = command.booleanPrimitiveValueOfParameterNamed("isPartialDepositAllowed"); - final boolean isLockinPeriodAllowed = command.booleanPrimitiveValueOfParameterNamed("isLockinPeriodAllowed"); + final String name = command.stringValueOfParameterNamed("name"); + final String description = command.stringValueOfParameterNamed("description"); + final BigDecimal interestRate = command.bigDecimalValueOfParameterNamed("interestRate"); + final BigDecimal minInterestRate = command.bigDecimalValueOfParameterNamed("minInterestRate"); + final BigDecimal maxInterestRate = command.bigDecimalValueOfParameterNamed("maxInterestRate"); + final BigDecimal savingsDepositAmount = command.bigDecimalValueOfParameterNamed("savingsDepositAmount"); + final Integer tenure = command.integerValueOfParameterNamed("tenure"); + final BigDecimal minimumBalanceForWithdrawal = command.bigDecimalValueOfParameterNamed("minimumBalanceForWithdrawal"); + final boolean isPartialDepositAllowed = command.booleanPrimitiveValueOfParameterNamed("isPartialDepositAllowed"); + final boolean isLockinPeriodAllowed = command.booleanPrimitiveValueOfParameterNamed("isLockinPeriodAllowed"); final Integer lockinPeriod = command.integerValueOfParameterNamed("lockinPeriod"); final Integer depositEvery = command.integerValueOfParameterNamed("depositEvery"); - - return new SavingProduct(name, description, currency, interestRate, minInterestRate, maxInterestRate, savingsDepositAmount, depositEvery, savingProductType, - tenureType, tenure, savingFrequencyType, interestType, savingInterestCalculationMethod, minimumBalanceForWithdrawal, isPartialDepositAllowed, - isLockinPeriodAllowed, lockinPeriod, lockinPeriodType); - } + + return new SavingProduct(name, description, currency, interestRate, minInterestRate, maxInterestRate, savingsDepositAmount, + depositEvery, savingProductType, tenureType, tenure, savingFrequencyType, interestType, savingInterestCalculationMethod, + minimumBalanceForWithdrawal, isPartialDepositAllowed, isLockinPeriodAllowed, lockinPeriod, lockinPeriodType); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductRelatedDetail.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductRelatedDetail.java index 4583d833d..678c4d044 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductRelatedDetail.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingProductRelatedDetail.java @@ -36,7 +36,7 @@ public class SavingProductRelatedDetail { @Column(name = "savings_deposit_amount", scale = 6, precision = 19, nullable = false) private BigDecimal savingsDepositAmount; - + @Column(name = "deposit_every") private Integer depositEvery; @@ -79,17 +79,18 @@ public class SavingProductRelatedDetail { } public SavingProductRelatedDetail(final MonetaryCurrency currency, final BigDecimal interestRate, final BigDecimal minInterestRate, - final BigDecimal maxInterestRate, final BigDecimal savingsDepositAmount,final Integer depositEvery, final SavingProductType savingProductType, - final TenureTypeEnum tenureType, final Integer tenure, final SavingFrequencyType frequency, - final SavingsInterestType interestType, final SavingInterestCalculationMethod interestCalculationMethod, - final BigDecimal minimumBalanceForWithdrawal, final boolean isPartialDepositAllowed, final boolean isLockinPeriodAllowed, - final Integer lockinPeriod, final PeriodFrequencyType lockinPeriodType) { + final BigDecimal maxInterestRate, final BigDecimal savingsDepositAmount, final Integer depositEvery, + final SavingProductType savingProductType, final TenureTypeEnum tenureType, final Integer tenure, + final SavingFrequencyType frequency, final SavingsInterestType interestType, + final SavingInterestCalculationMethod interestCalculationMethod, final BigDecimal minimumBalanceForWithdrawal, + final boolean isPartialDepositAllowed, final boolean isLockinPeriodAllowed, final Integer lockinPeriod, + final PeriodFrequencyType lockinPeriodType) { this.currency = currency; this.interestRate = interestRate; this.minInterestRate = minInterestRate; this.maxInterestRate = maxInterestRate; this.savingsDepositAmount = savingsDepositAmount; - this.depositEvery=depositEvery; + this.depositEvery = depositEvery; this.savingProductType = savingProductType.getValue(); this.tenureType = tenureType.getValue(); this.tenure = tenure; @@ -115,12 +116,12 @@ public class SavingProductRelatedDetail { return BigDecimal.valueOf(Double.valueOf(this.savingsDepositAmount.stripTrailingZeros().toString())); } - public Map update(final JsonCommand command, final Map actualChanges) { - - final String localeAsInput = command.locale(); - - Integer digitsAfterDecimal = this.currency.getDigitsAfterDecimal(); - final String digitsAfterDecimalParamName = "digitsAfterDecimal"; + public Map update(final JsonCommand command, final Map actualChanges) { + + final String localeAsInput = command.locale(); + + Integer digitsAfterDecimal = this.currency.getDigitsAfterDecimal(); + final String digitsAfterDecimalParamName = "digitsAfterDecimal"; if (command.isChangeInIntegerParameterNamed(digitsAfterDecimalParamName, digitsAfterDecimal)) { final Integer newValue = command.integerValueOfParameterNamed(digitsAfterDecimalParamName); actualChanges.put(digitsAfterDecimalParamName, newValue); @@ -137,7 +138,7 @@ public class SavingProductRelatedDetail { currencyCode = newValue; this.currency = new MonetaryCurrency(currencyCode, this.currency.getDigitsAfterDecimal()); } - + final String interestRateParamName = "interestRate"; if (command.isChangeInBigDecimalParameterNamed(interestRateParamName, this.interestRate)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(interestRateParamName); @@ -153,7 +154,7 @@ public class SavingProductRelatedDetail { actualChanges.put("locale", localeAsInput); this.savingsDepositAmount = newValue; } - + final String depositEveryParamName = "depositEvery"; if (command.isChangeInIntegerParameterNamed(depositEveryParamName, this.depositEvery)) { final Integer newValue = command.integerValueOfParameterNamed(depositEveryParamName); @@ -161,8 +162,7 @@ public class SavingProductRelatedDetail { actualChanges.put("locale", localeAsInput); this.depositEvery = newValue; } - - + final String savingProductTypeParamName = "savingProductType"; if (command.isChangeInIntegerParameterNamed(savingProductTypeParamName, this.savingProductType)) { final Integer newValue = command.integerValueOfParameterNamed(savingProductTypeParamName); @@ -170,7 +170,7 @@ public class SavingProductRelatedDetail { actualChanges.put("locale", localeAsInput); this.savingProductType = SavingProductType.fromInt(newValue).getValue(); } - + final String tenureTypeParamName = "tenureType"; if (command.isChangeInIntegerParameterNamed(tenureTypeParamName, this.tenureType)) { final Integer newValue = command.integerValueOfParameterNamed(tenureTypeParamName); @@ -186,7 +186,7 @@ public class SavingProductRelatedDetail { actualChanges.put("locale", localeAsInput); this.tenure = newValue; } - + final String frequencyParamName = "frequency"; if (command.isChangeInIntegerParameterNamed(frequencyParamName, this.frequency)) { final Integer newValue = command.integerValueOfParameterNamed(frequencyParamName); @@ -194,7 +194,7 @@ public class SavingProductRelatedDetail { actualChanges.put("locale", localeAsInput); this.frequency = SavingFrequencyType.fromInt(newValue).getValue(); } - + final String interestTypeParamName = "interestType"; if (command.isChangeInIntegerParameterNamed(interestTypeParamName, this.interestType)) { final Integer newValue = command.integerValueOfParameterNamed(interestTypeParamName); @@ -202,7 +202,7 @@ public class SavingProductRelatedDetail { actualChanges.put("locale", localeAsInput); this.interestType = SavingsInterestType.fromInt(newValue).getValue(); } - + final String interestCalculationMethodParamName = "interestCalculationMethod"; if (command.isChangeInIntegerParameterNamed(interestCalculationMethodParamName, this.interestCalculationMethod)) { final Integer newValue = command.integerValueOfParameterNamed(interestCalculationMethodParamName); @@ -221,37 +221,36 @@ public class SavingProductRelatedDetail { final String isPartialDepositAllowedParamName = "isPartialDepositAllowed"; if (command.isChangeInBooleanParameterNamed(isPartialDepositAllowedParamName, this.isPartialDepositAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(isPartialDepositAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(isPartialDepositAllowedParamName); actualChanges.put(isPartialDepositAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); this.isPartialDepositAllowed = newValue; } - + final String isLockinPeriodAllowedParamName = "isLockinPeriodAllowed"; if (command.isChangeInBooleanParameterNamed(isLockinPeriodAllowedParamName, this.isLockinPeriodAllowed)) { - final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName); + final Boolean newValue = command.booleanObjectValueOfParameterNamed(isLockinPeriodAllowedParamName); actualChanges.put(isLockinPeriodAllowedParamName, newValue); actualChanges.put("locale", localeAsInput); this.isLockinPeriodAllowed = newValue; } - - final String lockinPeriodParamName = "lockinPeriod"; + + final String lockinPeriodParamName = "lockinPeriod"; if (command.isChangeInIntegerParameterNamed(lockinPeriodParamName, this.lockinPeriod)) { final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodParamName); actualChanges.put(lockinPeriodParamName, newValue); actualChanges.put("locale", localeAsInput); this.lockinPeriod = newValue; } - - - final String lockinPeriodTypeParamName = "lockinPeriodType"; + + final String lockinPeriodTypeParamName = "lockinPeriodType"; if (command.isChangeInIntegerParameterNamed(lockinPeriodTypeParamName, this.lockinPeriodType)) { final Integer newValue = command.integerValueOfParameterNamed(lockinPeriodTypeParamName); actualChanges.put(lockinPeriodTypeParamName, newValue); actualChanges.put("locale", localeAsInput); this.lockinPeriodType = PeriodFrequencyType.fromInt(newValue).getValue(); } - + return actualChanges; } @@ -261,10 +260,10 @@ public class SavingProductRelatedDetail { } public Integer getDepositEvery() { - return this.depositEvery; - } + return this.depositEvery; + } - public Integer getSavingProductType() { + public Integer getSavingProductType() { return savingProductType; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingsInterestType.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingsInterestType.java index 1a73e20d2..eb1a3950d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingsInterestType.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/domain/SavingsInterestType.java @@ -7,7 +7,9 @@ package org.mifosplatform.portfolio.savingsaccountproduct.domain; public enum SavingsInterestType { - INVALID(0, "savingsInterestType.invalid"), SIMPLE(1, "savingsInterestType.simple"), COMPOUNDING(2, "savingsInterestType.compounding"); + INVALID(0, "savingsInterestType.invalid"), // + SIMPLE(1, "savingsInterestType.simple"), // + COMPOUNDING(2, "savingsInterestType.compounding"); private final Integer value; private final String code; @@ -41,5 +43,4 @@ public enum SavingsInterestType { } return savingsInterestType; } - -} +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/exception/SavingProductNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/exception/SavingProductNotFoundException.java index eaeb3d66d..45f5d3ec6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/exception/SavingProductNotFoundException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/exception/SavingProductNotFoundException.java @@ -9,7 +9,7 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceN public class SavingProductNotFoundException extends AbstractPlatformResourceNotFoundException { - public SavingProductNotFoundException(Long id) { + public SavingProductNotFoundException(final Long id) { super("error.msg.savingproduct.id.invalid", "Saving product with identifier " + id + " does not exist", id); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/exception/SavingsProductNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/exception/SavingsProductNotFoundException.java index c3d6b90fe..b29ea2ad6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/exception/SavingsProductNotFoundException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/exception/SavingsProductNotFoundException.java @@ -9,7 +9,7 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceN public class SavingsProductNotFoundException extends AbstractPlatformResourceNotFoundException { - public SavingsProductNotFoundException(Long id) { + public SavingsProductNotFoundException(final Long id) { super("error.msg.product.id.invalid", "Product with identifier " + id + " does not exist", id); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/handler/CreateSavingProductCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/handler/CreateSavingProductCommandHandler.java index 7ab5f81c3..be7bd0b4e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/handler/CreateSavingProductCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/handler/CreateSavingProductCommandHandler.java @@ -8,18 +8,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service -public class CreateSavingProductCommandHandler implements NewCommandSourceHandler{ - - private final SavingProductWritePlatformService savingProductWritePlatformService; - - @Autowired - public CreateSavingProductCommandHandler(final SavingProductWritePlatformService savingProductWritePlatformService) { - this.savingProductWritePlatformService = savingProductWritePlatformService; - } +public class CreateSavingProductCommandHandler implements NewCommandSourceHandler { - @Override - public CommandProcessingResult processCommand(JsonCommand command) { - return this.savingProductWritePlatformService.createSavingProduct(command); - } + private final SavingProductWritePlatformService savingProductWritePlatformService; -} + @Autowired + public CreateSavingProductCommandHandler(final SavingProductWritePlatformService savingProductWritePlatformService) { + this.savingProductWritePlatformService = savingProductWritePlatformService; + } + + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.savingProductWritePlatformService.createSavingProduct(command); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/handler/DeleteSavingProductCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/handler/DeleteSavingProductCommandHandler.java index 307ed6b05..f1d6b0391 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/handler/DeleteSavingProductCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/handler/DeleteSavingProductCommandHandler.java @@ -9,17 +9,16 @@ import org.springframework.stereotype.Service; @Service public class DeleteSavingProductCommandHandler implements NewCommandSourceHandler { - - private final SavingProductWritePlatformService savingProductWritePlatformService; - - @Autowired - public DeleteSavingProductCommandHandler(final SavingProductWritePlatformService savingProductWritePlatformService) { - this.savingProductWritePlatformService = savingProductWritePlatformService; - } - - @Override - public CommandProcessingResult processCommand(JsonCommand command) { - return this.savingProductWritePlatformService.deleteSavingProduct(command.entityId()); - } -} + private final SavingProductWritePlatformService savingProductWritePlatformService; + + @Autowired + public DeleteSavingProductCommandHandler(final SavingProductWritePlatformService savingProductWritePlatformService) { + this.savingProductWritePlatformService = savingProductWritePlatformService; + } + + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.savingProductWritePlatformService.deleteSavingProduct(command.entityId()); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/handler/UpdateSavingProductCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/handler/UpdateSavingProductCommandHandler.java index a3b5942ff..b25f42831 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/handler/UpdateSavingProductCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/handler/UpdateSavingProductCommandHandler.java @@ -9,17 +9,16 @@ import org.springframework.stereotype.Service; @Service public class UpdateSavingProductCommandHandler implements NewCommandSourceHandler { - - private final SavingProductWritePlatformService savingProductWritePlatformService; - - @Autowired - public UpdateSavingProductCommandHandler(final SavingProductWritePlatformService savingProductWritePlatformService) { - this.savingProductWritePlatformService = savingProductWritePlatformService; - } - @Override - public CommandProcessingResult processCommand(JsonCommand command) { - return this.savingProductWritePlatformService.updateSavingProduct(command.entityId(), command); - } + private final SavingProductWritePlatformService savingProductWritePlatformService; -} + @Autowired + public UpdateSavingProductCommandHandler(final SavingProductWritePlatformService savingProductWritePlatformService) { + this.savingProductWritePlatformService = savingProductWritePlatformService; + } + + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.savingProductWritePlatformService.updateSavingProduct(command.entityId(), command); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/serialization/SavingProductCommandFromApiJsonDeserializer.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/serialization/SavingProductCommandFromApiJsonDeserializer.java index 6bcc54083..be4f7f283 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/serialization/SavingProductCommandFromApiJsonDeserializer.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/serialization/SavingProductCommandFromApiJsonDeserializer.java @@ -24,185 +24,191 @@ import com.google.gson.reflect.TypeToken; @Component public class SavingProductCommandFromApiJsonDeserializer { - - Set supportedParams = new HashSet(Arrays.asList("locale", "name", "description", "currencyCode", + + private final Set supportedParams = new HashSet(Arrays.asList("locale", "name", "description", "currencyCode", "digitsAfterDecimal", "interestRate", "minInterestRate", "maxInterestRate", "savingsDepositAmount", "savingProductType", "tenureType", "tenure", "frequency", "interestType", "interestCalculationMethod", "minimumBalanceForWithdrawal", "isPartialDepositAllowed", "isLockinPeriodAllowed", "lockinPeriod", "lockinPeriodType", "depositEvery")); - - private final FromJsonHelper fromApiJsonHelper; - - @Autowired - public SavingProductCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) { - this.fromApiJsonHelper = fromApiJsonHelper; - } - public void validateForCreate(String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + private final FromJsonHelper fromApiJsonHelper; + + @Autowired + public SavingProductCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) { + this.fromApiJsonHelper = fromApiJsonHelper; + } + + public void validateForCreate(final String json) { + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams); - + List dataValidationErrors = new ArrayList(); - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("product"); - final JsonElement element = fromApiJsonHelper.parse(json); - - final String name = fromApiJsonHelper.extractStringNamed("name", element); + DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("product"); + final JsonElement element = fromApiJsonHelper.parse(json); + + final String name = fromApiJsonHelper.extractStringNamed("name", element); baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(100); - + final String description = fromApiJsonHelper.extractStringNamed("description", element); baseDataValidator.reset().parameter("description").value(description).notExceedingLengthOf(500); - + final String currencyCode = fromApiJsonHelper.extractStringNamed("currencyCode", element); baseDataValidator.reset().parameter("currencyCode").value(currencyCode).notBlank(); - + final Integer digitsAfterDecimal = fromApiJsonHelper.extractIntegerNamed("digitsAfterDecimal", element, Locale.getDefault()); baseDataValidator.reset().parameter("digitsAfterDecimal").value(digitsAfterDecimal).notNull().inMinMaxRange(0, 6); - + final BigDecimal interestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("interestRate", element); baseDataValidator.reset().parameter("interestRate").value(interestRate).notNull().zeroOrPositiveAmount(); - + final BigDecimal minInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minInterestRate", element); baseDataValidator.reset().parameter("minInterestRate").value(minInterestRate).notNull().zeroOrPositiveAmount(); - + final BigDecimal maxInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maxInterestRate", element); baseDataValidator.reset().parameter("maxInterestRate").value(maxInterestRate).notNull().zeroOrPositiveAmount(); - - baseDataValidator.reset().parameter("minInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(minInterestRate,maxInterestRate); - baseDataValidator.reset().parameter("interestRate").comapareMinAndMaxOfTwoBigDecmimalNos(interestRate,maxInterestRate); - baseDataValidator.reset().parameter("minInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(minInterestRate,interestRate); - + + baseDataValidator.reset().parameter("minInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(minInterestRate, maxInterestRate); + baseDataValidator.reset().parameter("interestRate").comapareMinAndMaxOfTwoBigDecmimalNos(interestRate, maxInterestRate); + baseDataValidator.reset().parameter("minInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(minInterestRate, interestRate); + final BigDecimal savingsDepositAmount = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("savingsDepositAmount", element); baseDataValidator.reset().parameter("savingsDepositAmount").value(savingsDepositAmount).notNull().zeroOrPositiveAmount(); - + final Integer savingProductType = fromApiJsonHelper.extractIntegerNamed("savingProductType", element, Locale.getDefault()); baseDataValidator.reset().parameter("savingProductType").value(savingProductType).notNull(); - + final Integer tenureType = fromApiJsonHelper.extractIntegerNamed("tenureType", element, Locale.getDefault()); baseDataValidator.reset().parameter("tenureType").value(tenureType).notNull(); - + final Integer tenure = fromApiJsonHelper.extractIntegerNamed("tenure", element, Locale.getDefault()); baseDataValidator.reset().parameter("tenure").value(tenure).notNull(); - + final Integer frequency = fromApiJsonHelper.extractIntegerNamed("frequency", element, Locale.getDefault()); baseDataValidator.reset().parameter("frequency").value(frequency).notNull(); - + final Integer interestType = fromApiJsonHelper.extractIntegerNamed("interestType", element, Locale.getDefault()); baseDataValidator.reset().parameter("interestType").value(interestType).notNull(); - - final Integer interestCalculationMethod = fromApiJsonHelper.extractIntegerNamed("interestCalculationMethod", element, Locale.getDefault()); + + final Integer interestCalculationMethod = fromApiJsonHelper.extractIntegerNamed("interestCalculationMethod", element, + Locale.getDefault()); baseDataValidator.reset().parameter("interestCalculationMethod").value(interestCalculationMethod).notNull(); - - final BigDecimal minimumBalanceForWithdrawal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalanceForWithdrawal", element); - baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(minimumBalanceForWithdrawal).notNull().zeroOrPositiveAmount(); - + + final BigDecimal minimumBalanceForWithdrawal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalanceForWithdrawal", + element); + baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(minimumBalanceForWithdrawal).notNull() + .zeroOrPositiveAmount(); + final Boolean isPartialDepositAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isPartialDepositAllowed", element); baseDataValidator.reset().parameter("isPartialDepositAllowed").value(isPartialDepositAllowedCommandValue) - .trueOrFalseRequired(isBooleanValueUpdated(isPartialDepositAllowedCommandValue)).notNull(); - - final Boolean isLockinPeriodAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element); - baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(isLockinPeriodAllowedCommandValue).trueOrFalseRequired(isBooleanValueUpdated(isLockinPeriodAllowedCommandValue)); - - final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault()); - baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).notNull().zeroOrPositiveAmount(); - - final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault()); - baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).notNull().inMinMaxRange(1, 3); - - throwExceptionIfValidationWarningsExist(dataValidationErrors); - - } + .trueOrFalseRequired(isBooleanValueUpdated(isPartialDepositAllowedCommandValue)).notNull(); - public void validateForUpdate(String json) { - - if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + final Boolean isLockinPeriodAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element); + baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(isLockinPeriodAllowedCommandValue) + .trueOrFalseRequired(isBooleanValueUpdated(isLockinPeriodAllowedCommandValue)); + + final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault()); + baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).notNull().zeroOrPositiveAmount(); + + final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault()); + baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).notNull().inMinMaxRange(1, 3); + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + + } + + public void validateForUpdate(final String json) { + + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParams); - + List dataValidationErrors = new ArrayList(); - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("product"); - final JsonElement element = fromApiJsonHelper.parse(json); - - final String name = fromApiJsonHelper.extractStringNamed("name", element); + DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("product"); + final JsonElement element = fromApiJsonHelper.parse(json); + + final String name = fromApiJsonHelper.extractStringNamed("name", element); baseDataValidator.reset().parameter("name").value(name).ignoreIfNull().notBlank().notExceedingLengthOf(100); - + final String description = fromApiJsonHelper.extractStringNamed("description", element); baseDataValidator.reset().parameter("description").value(description).notExceedingLengthOf(500); - + final String currencyCode = fromApiJsonHelper.extractStringNamed("currencyCode", element); baseDataValidator.reset().parameter("currencyCode").value(currencyCode).ignoreIfNull().notBlank(); - + final Integer digitsAfterDecimal = fromApiJsonHelper.extractIntegerNamed("digitsAfterDecimal", element, Locale.getDefault()); baseDataValidator.reset().parameter("digitsAfterDecimal").value(digitsAfterDecimal).ignoreIfNull().inMinMaxRange(0, 6); - + final BigDecimal interestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("interestRate", element); baseDataValidator.reset().parameter("interestRate").value(interestRate).ignoreIfNull().zeroOrPositiveAmount(); - + final BigDecimal minInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minInterestRate", element); baseDataValidator.reset().parameter("minInterestRate").value(minInterestRate).ignoreIfNull().zeroOrPositiveAmount(); - + final BigDecimal maxInterestRate = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("maxInterestRate", element); baseDataValidator.reset().parameter("maxInterestRate").value(maxInterestRate).ignoreIfNull().zeroOrPositiveAmount(); - - baseDataValidator.reset().parameter("minInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(minInterestRate,maxInterestRate); - baseDataValidator.reset().parameter("interestRate").comapareMinAndMaxOfTwoBigDecmimalNos(interestRate,maxInterestRate); - baseDataValidator.reset().parameter("minInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(minInterestRate,interestRate); - + + baseDataValidator.reset().parameter("minInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(minInterestRate, maxInterestRate); + baseDataValidator.reset().parameter("interestRate").comapareMinAndMaxOfTwoBigDecmimalNos(interestRate, maxInterestRate); + baseDataValidator.reset().parameter("minInterestRate").comapareMinAndMaxOfTwoBigDecmimalNos(minInterestRate, interestRate); + final BigDecimal savingsDepositAmount = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("savingsDepositAmount", element); baseDataValidator.reset().parameter("savingsDepositAmount").value(savingsDepositAmount).ignoreIfNull().zeroOrPositiveAmount(); - + final Integer savingProductType = fromApiJsonHelper.extractIntegerNamed("savingProductType", element, Locale.getDefault()); baseDataValidator.reset().parameter("savingProductType").value(savingProductType).ignoreIfNull(); - + final Integer tenureType = fromApiJsonHelper.extractIntegerNamed("tenureType", element, Locale.getDefault()); baseDataValidator.reset().parameter("tenureType").value(tenureType).ignoreIfNull(); - + final Integer tenure = fromApiJsonHelper.extractIntegerNamed("tenure", element, Locale.getDefault()); baseDataValidator.reset().parameter("tenure").value(tenure).ignoreIfNull().integerGreaterThanZero(); - + final Integer frequency = fromApiJsonHelper.extractIntegerNamed("frequency", element, Locale.getDefault()); baseDataValidator.reset().parameter("frequency").value(frequency).ignoreIfNull(); - + final Integer interestType = fromApiJsonHelper.extractIntegerNamed("interestType", element, Locale.getDefault()); baseDataValidator.reset().parameter("interestType").value(interestType).ignoreIfNull(); - - final Integer interestCalculationMethod = fromApiJsonHelper.extractIntegerNamed("interestCalculationMethod", element, Locale.getDefault()); + + final Integer interestCalculationMethod = fromApiJsonHelper.extractIntegerNamed("interestCalculationMethod", element, + Locale.getDefault()); baseDataValidator.reset().parameter("interestCalculationMethod").value(interestCalculationMethod).ignoreIfNull(); - - final BigDecimal minimumBalanceForWithdrawal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalanceForWithdrawal", element); - baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(minimumBalanceForWithdrawal).ignoreIfNull().zeroOrPositiveAmount(); - + + final BigDecimal minimumBalanceForWithdrawal = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("minimumBalanceForWithdrawal", + element); + baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(minimumBalanceForWithdrawal).ignoreIfNull() + .zeroOrPositiveAmount(); + final Boolean isPartialDepositAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isPartialDepositAllowed", element); baseDataValidator.reset().parameter("isPartialDepositAllowed").value(isPartialDepositAllowedCommandValue) - .trueOrFalseRequired(isBooleanValueUpdated(isPartialDepositAllowedCommandValue)).ignoreIfNull(); - + .trueOrFalseRequired(isBooleanValueUpdated(isPartialDepositAllowedCommandValue)).ignoreIfNull(); + final Boolean isLockinPeriodAllowedCommandValue = fromApiJsonHelper.extractBooleanNamed("isLockinPeriodAllowed", element); - baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(isLockinPeriodAllowedCommandValue) - .trueOrFalseRequired(isBooleanValueUpdated(isLockinPeriodAllowedCommandValue)).ignoreIfNull(); - - final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault()); - baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).ignoreIfNull().zeroOrPositiveAmount(); - - final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault()); - baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).ignoreIfNull().inMinMaxRange(1, 3); - + baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(isLockinPeriodAllowedCommandValue) + .trueOrFalseRequired(isBooleanValueUpdated(isLockinPeriodAllowedCommandValue)).ignoreIfNull(); + + final Integer lockinPeriod = fromApiJsonHelper.extractIntegerNamed("lockinPeriod", element, Locale.getDefault()); + baseDataValidator.reset().parameter("lockinPeriod").value(lockinPeriod).ignoreIfNull().zeroOrPositiveAmount(); + + final Integer lockinPeriodType = fromApiJsonHelper.extractIntegerNamed("lockinPeriodType", element, Locale.getDefault()); + baseDataValidator.reset().parameter("lockinPeriodType").value(lockinPeriodType).ignoreIfNull().inMinMaxRange(1, 3); + throwExceptionIfValidationWarningsExist(dataValidationErrors); - - } - - private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { + + } + + private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } } - - private Boolean isBooleanValueUpdated(Boolean actualValue) { - Boolean isUpdated = false; - if(actualValue != null){ - isUpdated = true; - } - return isUpdated; - } -} + private Boolean isBooleanValueUpdated(final Boolean actualValue) { + Boolean isUpdated = false; + if (actualValue != null) { + isUpdated = true; + } + return isUpdated; + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductCommandValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductCommandValidator.java deleted file mode 100644 index 7d1f58f9e..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductCommandValidator.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.mifosplatform.portfolio.savingsaccountproduct.service; - -import java.util.ArrayList; -import java.util.List; - -import org.mifosplatform.infrastructure.core.data.ApiParameterError; -import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; -import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; -import org.mifosplatform.portfolio.savingsaccountproduct.command.SavingProductCommand; - -public class SavingProductCommandValidator { - - private final SavingProductCommand command; - - public SavingProductCommandValidator(final SavingProductCommand command) { - this.command = command; - } - - public void validateForUpdate() { - - List dataValidationErrors = new ArrayList(); - - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("savingsproduct"); - baseDataValidator.reset().parameter("id").value(command.getId()).notNull(); - baseDataValidator.reset().parameter("name").value(command.getName()).ignoreIfNull().notBlank(); - baseDataValidator.reset().parameter("description").value(command.getDescription()).ignoreIfNull().notExceedingLengthOf(500); - baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).ignoreIfNull().notBlank(); - baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).ignoreIfNull().inMinMaxRange(0, 6); - baseDataValidator.reset().parameter("interestRate").value(command.getInterestRate()).ignoreIfNull().notBlank(); - baseDataValidator.reset().parameter("minInterestRate").value(command.getMinInterestRate()).ignoreIfNull().notBlank(); - baseDataValidator.reset().parameter("maxInterestRate").value(command.getMaxInterestRate()).ignoreIfNull().notBlank(); - baseDataValidator.reset().parameter("minInterestRate") - .comapareMinAndMaxOfTwoBigDecmimalNos(command.getMinInterestRate(), command.getMaxInterestRate()); - baseDataValidator.reset().parameter("interestRate") - .comapareMinAndMaxOfTwoBigDecmimalNos(command.getInterestRate(), command.getMaxInterestRate()); - baseDataValidator.reset().parameter("minInterestRate") - .comapareMinAndMaxOfTwoBigDecmimalNos(command.getMinInterestRate(), command.getInterestRate()); - baseDataValidator.reset().parameter("savingsDepositAmount").value(command.getSavingsDepositAmount()).ignoreIfNull() - .zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("savingProductType").value(command.getSavingProductType()).ignoreIfNull(); - baseDataValidator.reset().parameter("tenureType").value(command.getTenureType()).ignoreIfNull(); - baseDataValidator.reset().parameter("tenure").value(command.getTenure()).ignoreIfNull(); - baseDataValidator.reset().parameter("frequency").value(command.getFrequency()).ignoreIfNull(); - baseDataValidator.reset().parameter("interestType").value(command.getInterestType()).ignoreIfNull(); - baseDataValidator.reset().parameter("interestCalculationMethod").value(command.getInterestCalculationMethod()).ignoreIfNull(); - baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(command.getMinimumBalanceForWithdrawal()).ignoreIfNull() - .zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("isPartialDepositAllowed").value(command.isPartialDepositAllowed()).ignoreIfNull(); - baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(command.isLockinPeriodAllowed()).ignoreIfNull(); - baseDataValidator.reset().parameter("lockinPeriod").value(command.getLockinPeriod()).ignoreIfNull(); - baseDataValidator.reset().parameter("lockinPeriodType").value(command.getLockinPeriodType()).ignoreIfNull(); - - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); } - } - - public void validateForCreate() { - - List dataValidationErrors = new ArrayList(); - - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("product"); - baseDataValidator.reset().parameter("name").value(command.getName()).notBlank(); - baseDataValidator.reset().parameter("description").value(command.getDescription()).notExceedingLengthOf(500); - baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank(); - baseDataValidator.reset().parameter("digitsAfterDecimal").value(command.getDigitsAfterDecimal()).notNull().inMinMaxRange(0, 6); - baseDataValidator.reset().parameter("interestRate").value(command.getInterestRate()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("minInterestRate").value(command.getMinInterestRate()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("maxInterestRate").value(command.getMaxInterestRate()).notNull().zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("minInterestRate") - .comapareMinAndMaxOfTwoBigDecmimalNos(command.getMinInterestRate(), command.getMaxInterestRate()); - baseDataValidator.reset().parameter("interestRate") - .comapareMinAndMaxOfTwoBigDecmimalNos(command.getInterestRate(), command.getMaxInterestRate()); - baseDataValidator.reset().parameter("minInterestRate") - .comapareMinAndMaxOfTwoBigDecmimalNos(command.getMinInterestRate(), command.getInterestRate()); - baseDataValidator.reset().parameter("savingsDepositAmount").value(command.getSavingsDepositAmount()).notNull() - .zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("savingProductType").value(command.getSavingProductType()).notNull(); - baseDataValidator.reset().parameter("tenureType").value(command.getTenureType()).notNull(); - baseDataValidator.reset().parameter("tenure").value(command.getTenure()).notNull(); - baseDataValidator.reset().parameter("frequency").value(command.getFrequency()).notNull(); - baseDataValidator.reset().parameter("interestType").value(command.getInterestType()).notNull(); - baseDataValidator.reset().parameter("interestCalculationMethod").value(command.getInterestCalculationMethod()).notNull(); - baseDataValidator.reset().parameter("minimumBalanceForWithdrawal").value(command.getMinimumBalanceForWithdrawal()).notNull() - .zeroOrPositiveAmount(); - baseDataValidator.reset().parameter("isPartialDepositAllowed").value(command.isPartialDepositAllowed()) - .trueOrFalseRequired(command.isPartialDepositAllowedChanged()).notNull(); - baseDataValidator.reset().parameter("isLockinPeriodAllowed").value(command.isLockinPeriodAllowed()) - .trueOrFalseRequired(command.isLockinPeriodAllowedChanged()).notNull(); - baseDataValidator.reset().parameter("lockinPeriod").value(command.getLockinPeriod()).notNull(); - baseDataValidator.reset().parameter("lockinPeriodType").value(command.getLockinPeriodType()).notNull(); - - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); } - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformService.java index da1926677..e4eab781c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformService.java @@ -15,4 +15,4 @@ public interface SavingProductWritePlatformService { CommandProcessingResult updateSavingProduct(Long productId, JsonCommand command); CommandProcessingResult deleteSavingProduct(Long productId); -} +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformServiceJpaRepositoryImpl.java index 87917f7ad..4b8ecd688 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformServiceJpaRepositoryImpl.java @@ -37,8 +37,7 @@ public class SavingProductWritePlatformServiceJpaRepositoryImpl implements Savin @Autowired public SavingProductWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, - final SavingProductRepository savingProductRepository, - final SavingProductCommandFromApiJsonDeserializer fromApiJsonDeserializer) { + final SavingProductRepository savingProductRepository, final SavingProductCommandFromApiJsonDeserializer fromApiJsonDeserializer) { this.context = context; this.savingProductRepository = savingProductRepository; this.fromApiJsonDeserializer = fromApiJsonDeserializer; @@ -50,7 +49,7 @@ public class SavingProductWritePlatformServiceJpaRepositoryImpl implements Savin this.context.authenticatedUser(); this.fromApiJsonDeserializer.validateForCreate(command.json()); - + final Integer savingProductTypeCommandValue = command.integerValueOfParameterNamed("savingProductType"); SavingProductType savingProductType = SavingProductType.fromInt(savingProductTypeCommandValue); final Integer tenureTypeCommandValue = command.integerValueOfParameterNamed("tenureType"); @@ -62,28 +61,25 @@ public class SavingProductWritePlatformServiceJpaRepositoryImpl implements Savin final Integer lockinPeriodTypeCommandValue = command.integerValueOfParameterNamed("lockinPeriodType"); PeriodFrequencyType lockinPeriodType = PeriodFrequencyType.fromInt(lockinPeriodTypeCommandValue); final Integer interestCalculationMethodCommandValue = command.integerValueOfParameterNamed("interestCalculationMethod"); - SavingInterestCalculationMethod savingInterestCalculationMethod = SavingInterestCalculationMethod.fromInt(interestCalculationMethodCommandValue); + SavingInterestCalculationMethod savingInterestCalculationMethod = SavingInterestCalculationMethod + .fromInt(interestCalculationMethodCommandValue); final String currencyCode = command.stringValueOfParameterNamed("currencyCode"); final Integer digitsAfterDecimal = command.integerValueOfParameterNamed("digitsAfterDecimal"); MonetaryCurrency currency = new MonetaryCurrency(currencyCode, digitsAfterDecimal); - - if ( savingProductType.equals(SavingProductType.INVALID) || - tenureType.equals(TenureTypeEnum.INVALID) || - savingFrequencyType.equals(SavingFrequencyType.INVALID) || - interestType.equals(SavingsInterestType.INVALID) || - lockinPeriodType.equals(PeriodFrequencyType.INVALID)|| - savingInterestCalculationMethod.equals(SavingInterestCalculationMethod.INVALID) - ) { - throw new NoAuthorizationException("Please select a valid types"); - } - - SavingProduct product = SavingProduct.assembleFromJson(command, currency, savingProductType, tenureType, savingFrequencyType, - interestType, savingInterestCalculationMethod, lockinPeriodType); + + if (savingProductType.equals(SavingProductType.INVALID) || tenureType.equals(TenureTypeEnum.INVALID) + || savingFrequencyType.equals(SavingFrequencyType.INVALID) || interestType.equals(SavingsInterestType.INVALID) + || lockinPeriodType.equals(PeriodFrequencyType.INVALID) + || savingInterestCalculationMethod.equals(SavingInterestCalculationMethod.INVALID)) { throw new NoAuthorizationException( + "Please select a valid types"); } + + SavingProduct product = SavingProduct.assembleFromJson(command, currency, savingProductType, tenureType, savingFrequencyType, + interestType, savingInterestCalculationMethod, lockinPeriodType); this.savingProductRepository.save(product); return new CommandProcessingResultBuilder() // - .withEntityId(product.getId()) // - .build(); + .withEntityId(product.getId()) // + .build(); } @Transactional @@ -93,23 +89,22 @@ public class SavingProductWritePlatformServiceJpaRepositoryImpl implements Savin this.context.authenticatedUser(); this.fromApiJsonDeserializer.validateForUpdate(command.json()); - SavingProduct product = this.savingProductRepository.findOne(productId); - - if (product == null) { throw new SavingProductNotFoundException(productId); } - - Map changes = product.update(command); - + final SavingProduct product = this.savingProductRepository.findOne(productId); + + if (product == null || product.isDeleted()) { throw new SavingProductNotFoundException(productId); } + + final Map changes = product.update(command); + this.savingProductRepository.save(product); - + return new CommandProcessingResultBuilder() // - .withEntityId(product.getId()) // - .with(changes) - .build(); + .withEntityId(product.getId()) // + .with(changes).build(); } @Transactional @Override - public CommandProcessingResult deleteSavingProduct(Long productId) { + public CommandProcessingResult deleteSavingProduct(final Long productId) { this.context.authenticatedUser(); SavingProduct product = this.savingProductRepository.findOne(productId); @@ -117,8 +112,7 @@ public class SavingProductWritePlatformServiceJpaRepositoryImpl implements Savin product.delete(); this.savingProductRepository.save(product); return new CommandProcessingResultBuilder() // - .withEntityId(product.getId()) // - .build(); + .withEntityId(product.getId()) // + .build(); } - } \ No newline at end of file