From 8dc5789607dfa51a9186e1971998550df8e85374 Mon Sep 17 00:00:00 2001 From: rrpawar96 Date: Thu, 25 Nov 2021 17:50:12 +0530 Subject: [PATCH] FINERACT-1053:Client-AccountNumber-Length --- .../client/domain/AccountNumberGenerator.java | 25 ++++++++++++++++++- ...tion_for_variable_length_acoountNumber.sql | 20 +++++++++++++++ .../common/GlobalConfigurationHelper.java | 14 ++++++++--- 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 fineract-provider/src/main/resources/sql/migrations/core_db/V378__configuration_for_variable_length_acoountNumber.sql diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/AccountNumberGenerator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/AccountNumberGenerator.java index 0372bcd66..6a3bb31fc 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/AccountNumberGenerator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/AccountNumberGenerator.java @@ -24,10 +24,13 @@ import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormat; import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormatEnumerations.AccountNumberPrefixType; import org.apache.fineract.infrastructure.codes.domain.CodeValue; +import org.apache.fineract.infrastructure.configuration.data.GlobalConfigurationPropertyData; +import org.apache.fineract.infrastructure.configuration.service.ConfigurationReadPlatformService; import org.apache.fineract.portfolio.group.domain.Group; import org.apache.fineract.portfolio.loanaccount.domain.Loan; import org.apache.fineract.portfolio.savings.domain.SavingsAccount; import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccount; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -45,6 +48,12 @@ public class AccountNumberGenerator { private static final String LOAN_PRODUCT_SHORT_NAME = "loanProductShortName"; private static final String SAVINGS_PRODUCT_SHORT_NAME = "savingsProductShortName"; private static final String SHARE_PRODUCT_SHORT_NAME = "sharesProductShortName"; + private final ConfigurationReadPlatformService configurationReadPlatformService; + + @Autowired + public AccountNumberGenerator(final ConfigurationReadPlatformService configurationReadPlatformService) { + this.configurationReadPlatformService = configurationReadPlatformService; + } public String generate(Client client, AccountNumberFormat accountNumberFormat) { Map propertyMap = new HashMap<>(); @@ -81,7 +90,21 @@ public class AccountNumberGenerator { } private String generateAccountNumber(Map propertyMap, AccountNumberFormat accountNumberFormat) { - String accountNumber = StringUtils.leftPad(propertyMap.get(ID), AccountNumberGenerator.maxLength, '0'); + int accountMaxLength = AccountNumberGenerator.maxLength; + + // find if the custom length is defined + final GlobalConfigurationPropertyData customLength = this.configurationReadPlatformService + .retrieveGlobalConfiguration("custom-account-number-length"); + + if (customLength.isEnabled()) { + // if it is enabled, and has the value, get it from the repository. + if (customLength.getValue() != null) { + accountMaxLength = customLength.getValue().intValue(); + } + + } + + String accountNumber = StringUtils.leftPad(propertyMap.get(ID), accountMaxLength, '0'); if (accountNumberFormat != null && accountNumberFormat.getPrefixEnum() != null) { AccountNumberPrefixType accountNumberPrefixType = AccountNumberPrefixType.fromInt(accountNumberFormat.getPrefixEnum()); String prefix = null; diff --git a/fineract-provider/src/main/resources/sql/migrations/core_db/V378__configuration_for_variable_length_acoountNumber.sql b/fineract-provider/src/main/resources/sql/migrations/core_db/V378__configuration_for_variable_length_acoountNumber.sql new file mode 100644 index 000000000..45bad58b1 --- /dev/null +++ b/fineract-provider/src/main/resources/sql/migrations/core_db/V378__configuration_for_variable_length_acoountNumber.sql @@ -0,0 +1,20 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. +-- + +INSERT INTO c_configuration ( name, description) VALUES ( 'custom-account-number-length', 'if enabled, the value if this configuration will set accounnumber length'); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/GlobalConfigurationHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/GlobalConfigurationHelper.java index 04ecd2772..99f08bf2f 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/GlobalConfigurationHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/GlobalConfigurationHelper.java @@ -89,9 +89,9 @@ public class GlobalConfigurationHelper { ArrayList expectedGlobalConfigurations = getAllDefaultGlobalConfigurations(); ArrayList actualGlobalConfigurations = getAllGlobalConfigurations(requestSpec, responseSpec); - // There are currently 35 global configurations. - Assertions.assertEquals(35, expectedGlobalConfigurations.size()); - Assertions.assertEquals(35, actualGlobalConfigurations.size()); + // There are currently 36 global configurations. + Assertions.assertEquals(36, expectedGlobalConfigurations.size()); + Assertions.assertEquals(36, actualGlobalConfigurations.size()); for (int i = 0; i < expectedGlobalConfigurations.size(); i++) { @@ -407,6 +407,14 @@ public class GlobalConfigurationHelper { isAllowedBackDatedTransactionsBeforeInterestPostingDateForDays.put("trapDoor", false); defaults.add(isAllowedBackDatedTransactionsBeforeInterestPostingDateForDays); + HashMap isClientAccountNumberLengthModify = new HashMap<>(); + isClientAccountNumberLengthModify.put("id", 40); + isClientAccountNumberLengthModify.put("name", "custom-account-number-length"); + isClientAccountNumberLengthModify.put("value", 0); + isClientAccountNumberLengthModify.put("enabled", false); + isClientAccountNumberLengthModify.put("trapDoor", false); + defaults.add(isClientAccountNumberLengthModify); + return defaults; }