FINERACT-1053:Client-AccountNumber-Length

This commit is contained in:
rrpawar96
2021-11-26 23:40:55 +08:00
committed by Petri Tuomola
parent 70e3b4e0db
commit 8dc5789607
3 changed files with 55 additions and 4 deletions
@@ -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;
@@ -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');
@@ -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;
}