This is an automated email from the ASF dual-hosted git repository.

adamsaghy 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 bad50aaa4d FINERACT-2237: Fix GSIM account creation to generate single 
parent for multiple clients
bad50aaa4d is described below

commit bad50aaa4de4f7aacdaedb30d5a57dd01b02f0d9
Author: Abhinav Cillanki <[email protected]>
AuthorDate: Sat Apr 5 11:34:35 2025 +0530

    FINERACT-2237: Fix GSIM account creation to generate single parent for 
multiple clients
---
 ...ocessWritePlatformServiceJpaRepositoryImpl.java | 11 +++-
 .../portfolio/savings/domain/GSIMRepositoy.java    |  3 +
 .../GroupSavingsIntegrationTest.java               | 65 +++++++++++++++++++---
 .../integrationtests/common/GroupHelper.java       | 11 ++++
 4 files changed, 81 insertions(+), 9 deletions(-)

diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java
index 2645cfccae..c7fb7d249e 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java
@@ -168,7 +168,9 @@ public class 
SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
 
                     Group group = 
this.groupRepositoryWrapper.findOneWithNotFoundDetection(groupId);
 
-                    if 
(command.booleanObjectValueOfParameterNamed("isParentAccount") != null) {
+                    if 
(command.booleanObjectValueOfParameterNamed("isParentAccount") != null
+                            && 
("1".equals(command.stringValueOfParameterNamed("isParentAccount"))
+                                    || 
command.booleanObjectValueOfParameterNamed("isParentAccount"))) {
                         // empty table check
                         if (gsimRepository.count() != 0) {
                             // Parent-Not an empty table
@@ -193,7 +195,12 @@ public class 
SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
                     } else {
                         if (gsimRepository.count() != 0) {
                             // Child-Not an empty table check
-                            gsimAccount = 
gsimRepository.findOneByIsAcceptingChildAndApplicationId(true, applicationId);
+                            if (applicationId.compareTo(BigDecimal.ZERO) == 0) 
{
+                                gsimAccount = 
gsimRepository.findOneByIsAcceptingChildAndApplicationIdAndGroupId(true, 
applicationId,
+                                        groupId);
+                            } else {
+                                gsimAccount = 
gsimRepository.findOneByIsAcceptingChildAndApplicationId(true, applicationId);
+                            }
                             accountNumber = gsimAccount.getAccountNumber() + 
(gsimAccount.getChildAccountsCount() + 1);
                             account.updateAccountNo(accountNumber);
                             
this.gsimWritePlatformService.incrementChildAccountCount(gsimAccount);
diff --git 
a/fineract-savings/src/main/java/org/apache/fineract/portfolio/savings/domain/GSIMRepositoy.java
 
b/fineract-savings/src/main/java/org/apache/fineract/portfolio/savings/domain/GSIMRepositoy.java
index 3000ada17a..a62350eee6 100644
--- 
a/fineract-savings/src/main/java/org/apache/fineract/portfolio/savings/domain/GSIMRepositoy.java
+++ 
b/fineract-savings/src/main/java/org/apache/fineract/portfolio/savings/domain/GSIMRepositoy.java
@@ -31,4 +31,7 @@ public interface GSIMRepositoy
     GroupSavingsIndividualMonitoring 
findOneByIsAcceptingChildAndApplicationId(boolean acceptingChild, BigDecimal 
applicationId);
 
     GroupSavingsIndividualMonitoring findOneByAccountNumber(String 
accountNumber);
+
+    GroupSavingsIndividualMonitoring 
findOneByIsAcceptingChildAndApplicationIdAndGroupId(boolean acceptingChild, 
BigDecimal applicationId,
+            Long groupId);
 }
diff --git 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/GroupSavingsIntegrationTest.java
 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/GroupSavingsIntegrationTest.java
index adee98f18f..0d62177e5b 100644
--- 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/GroupSavingsIntegrationTest.java
+++ 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/GroupSavingsIntegrationTest.java
@@ -179,6 +179,57 @@ public class GroupSavingsIntegrationTest {
 
     }
 
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testGsimSavingsAccount_WithTwoClients_ChildCountTwo() {
+
+        // Initialize the helper for savings account operations
+        this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, 
this.responseSpec);
+
+        // Create two clients: one designated as the parent and one as the 
child
+        final Integer parentClientID = 
ClientHelper.createClient(this.requestSpec, this.responseSpec);
+        Assertions.assertNotNull(parentClientID);
+
+        final Integer childClientID = 
ClientHelper.createClient(this.requestSpec, this.responseSpec);
+        Assertions.assertNotNull(childClientID);
+
+        // Create a group and associate both clients with it
+        Integer groupID = GroupHelper.createGroup(this.requestSpec, 
this.responseSpec, true);
+        Assertions.assertNotNull(groupID);
+
+        // obtain the latest application ID of the gsim accounts
+        // BigDecimal applicationId = 
GroupHelper.getLastApplicationIdOfGsimSavingAccount(this.requestSpec,
+        // this.responseSpec, groupID).add(BigDecimal.ONE);
+
+        groupID = GroupHelper.associateClient(this.requestSpec, 
this.responseSpec, groupID.toString(), parentClientID.toString());
+        Assertions.assertNotNull(groupID);
+        groupID = GroupHelper.associateClient(this.requestSpec, 
this.responseSpec, groupID.toString(), childClientID.toString());
+        Assertions.assertNotNull(groupID);
+
+        // Create a savings product necessary for the GSIM application
+        final String minBalanceForInterestCalculation = null;
+        final String minRequiredBalance = null;
+        final String enforceMinRequiredBalance = "false";
+        final Integer savingsProductID = 
createSavingsProduct(this.requestSpec, this.responseSpec, 
MINIMUM_OPENING_BALANCE,
+                minBalanceForInterestCalculation, minRequiredBalance, 
enforceMinRequiredBalance);
+        Assertions.assertNotNull(savingsProductID);
+
+        // Prepare the client array with two entries:
+        // one for the parent client (isParent = true) and one for the child 
client (isParent = false)
+        List<Map<String, Object>> clientArray = new ArrayList<>();
+        clientArray.add(clientArray(parentClientID, groupID, savingsProductID, 
"08 January 2013", true));
+        clientArray.add(clientArray(childClientID, groupID, savingsProductID, 
"08 January 2013", false));
+
+        // Apply for a GSIM savings account with both clients under the same 
application
+        final Integer gsimID = 
this.savingsAccountHelper.applyForGsimApplication(clientArray);
+        Assertions.assertNotNull(gsimID);
+
+        // get child account count
+        final Integer childAccountCount = 
GroupHelper.getChildAccountCount(this.requestSpec, this.responseSpec, groupID);
+        assertEquals(childAccountCount, 2);
+
+    }
+
     @SuppressWarnings("unchecked")
     @Test
     public void testSavingsAccount_DELETE_APPLICATION() {
@@ -254,7 +305,7 @@ public class GroupSavingsIntegrationTest {
         Assertions.assertNotNull(savingsProductID);
 
         List<Map<String, Object>> clientArray = new ArrayList<>();
-        clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 
January 2013"));
+        clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 
January 2013", true));
 
         final Integer gsimID = 
this.savingsAccountHelper.applyForGsimApplication(clientArray);
 
@@ -306,7 +357,7 @@ public class GroupSavingsIntegrationTest {
         Assertions.assertNotNull(savingsProductID);
 
         List<Map<String, Object>> clientArray = new ArrayList<>();
-        clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 
January 2013"));
+        clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 
January 2013", true));
         LOG.info("client Array : {} ", clientArray);
 
         final Integer savingsId = 
this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, 
ACCOUNT_TYPE_GROUP);
@@ -365,7 +416,7 @@ public class GroupSavingsIntegrationTest {
         Assertions.assertNotNull(savingsProductID);
 
         List<Map<String, Object>> clientArray = new ArrayList<>();
-        clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 
January 2013"));
+        clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 
January 2013", true));
 
         final Integer gsimID = 
this.savingsAccountHelper.applyForGsimApplication(clientArray);
 
@@ -414,7 +465,7 @@ public class GroupSavingsIntegrationTest {
         Assertions.assertNotNull(savingsProductID);
 
         List<Map<String, Object>> clientArray = new ArrayList<>();
-        clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 
January 2013"));
+        clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 
January 2013", true));
 
         final Integer gsimID = 
this.savingsAccountHelper.applyForGsimApplication(clientArray);
 
@@ -448,7 +499,7 @@ public class GroupSavingsIntegrationTest {
         Assertions.assertNotNull(savingsProductID);
 
         List<Map<String, Object>> clientArray = new ArrayList<>();
-        clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 
January 2013"));
+        clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 
January 2013", true));
         final Integer gsimID = 
this.savingsAccountHelper.applyForGsimApplication(clientArray);
 
         final List<String> retrievedGsimId = 
GroupHelper.verifyRetrieveGsimAccounts(this.requestSpec, this.responseSpec, 
groupID);
@@ -797,7 +848,7 @@ public class GroupSavingsIntegrationTest {
     }
 
     private Map<String, Object> clientArray(final Integer clientId, final 
Integer groupId, final Integer productId,
-            final String submittedOnDate) {
+            final String submittedOnDate, final boolean isParent) {
         Map<String, Object> map = new HashMap<>();
         map.put("clientId", clientId);
         map.put("groupId", groupId);
@@ -805,7 +856,7 @@ public class GroupSavingsIntegrationTest {
         map.put("submittedOnDate", submittedOnDate);
         map.put("dateFormat", CommonConstants.DATE_FORMAT);
         map.put("locale", "en");
-        map.put("isParentAccount", "1");
+        map.put("isParentAccount", isParent);
         map.put("isGSIM", "true");
         return map;
     }
diff --git 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/GroupHelper.java
 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/GroupHelper.java
index eb6e9d1195..b6cabe3956 100644
--- 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/GroupHelper.java
+++ 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/GroupHelper.java
@@ -407,6 +407,17 @@ public class GroupHelper {
         return list;
     }
 
+    public static Integer getChildAccountCount(final RequestSpecification 
requestSpec, final ResponseSpecification responseSpec,
+            final Integer groupID) {
+        List<Object> list;
+        LOG.info("------------------------------GET CHILD ACCOUNT 
COUNT------------------------------------\n");
+        final String GROUP_URL = "/fineract-provider/api/v1/groups/" + groupID 
+ "/gsimaccounts?" + Utils.TENANT_IDENTIFIER;
+        list = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, 
"childGSIMAccounts");
+
+        return ((ArrayList) list.get(0)).size();
+
+    }
+
     public static String randomNameGenerator(final String prefix, final int 
lenOfRandomSuffix) {
         return Utils.uniqueRandomStringGenerator(prefix, lenOfRandomSuffix);
     }

Reply via email to