You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by pt...@apache.org on 2021/11/26 15:41:00 UTC
[fineract] branch develop updated: FINERACT-1053:Client-AccountNumber-Length
This is an automated email from the ASF dual-hosted git repository.
ptuomola pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
The following commit(s) were added to refs/heads/develop by this push:
new 8dc5789 FINERACT-1053:Client-AccountNumber-Length
8dc5789 is described below
commit 8dc5789607dfa51a9186e1971998550df8e85374
Author: rrpawar96 <rr...@gmail.com>
AuthorDate: Thu Nov 25 17:50:12 2021 +0530
FINERACT-1053:Client-AccountNumber-Length
---
.../client/domain/AccountNumberGenerator.java | 25 +++++++++++++++++++++-
...iguration_for_variable_length_acoountNumber.sql | 20 +++++++++++++++++
.../common/GlobalConfigurationHelper.java | 14 +++++++++---
3 files changed, 55 insertions(+), 4 deletions(-)
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 0372bcd..6a3bb31 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<String, String> propertyMap = new HashMap<>();
@@ -81,7 +90,21 @@ public class AccountNumberGenerator {
}
private String generateAccountNumber(Map<String, String> 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 0000000..45bad58
--- /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 04ecd27..99f08bf 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<HashMap> expectedGlobalConfigurations = getAllDefaultGlobalConfigurations();
ArrayList<HashMap> 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<String, Object> 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;
}