You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by GitBox <gi...@apache.org> on 2018/09/26 05:56:53 UTC

[GitHub] ShruthiRajaram closed pull request #446: FINERACT-546 - remove group from center fix

ShruthiRajaram closed pull request #446: FINERACT-546 - remove group from center fix
URL: https://github.com/apache/fineract/pull/446
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CenterIntegrationTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CenterIntegrationTest.java
index d923ee570..93631f47c 100644
--- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CenterIntegrationTest.java
+++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CenterIntegrationTest.java
@@ -132,19 +132,19 @@ public void testCenterUpdate() {
         String newName = "TestCenterUpdateNew" + new Timestamp(new java.util.Date().getTime());
         String newExternalId = Utils.randomStringGenerator("newID_", 7, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
         int newStaffId = StaffHelper.createStaff(requestSpec, responseSpec);
-        int[] associateGroupMembers = generateGroupMembers(2, officeId);
+        int[] groupMembersForLink = generateGroupMembers(2, officeId);
 
-        int[] associateResponse = CenterHelper.associateGroups(resourceId, associateGroupMembers, requestSpec, responseSpec);
+        int[] associateResponse = CenterHelper.associateGroups(resourceId, groupMembersForLink, requestSpec, responseSpec);
         Arrays.sort(associateResponse);
-        Arrays.sort(associateGroupMembers);
-        Assert.assertArrayEquals(associateResponse, associateGroupMembers);
+        Arrays.sort(groupMembersForLink);
+        Assert.assertArrayEquals(associateResponse, groupMembersForLink);
 
         int[] newGroupMembers = new int[5];
         for (int i = 0; i < 5; i++) {
             if (i < 3) {
                 newGroupMembers[i] = groupMembers[i];
             } else {
-                newGroupMembers[i] = associateGroupMembers[i % 3];
+                newGroupMembers[i] = groupMembersForLink[i % 3];
             }
         }
 
@@ -164,6 +164,12 @@ public void testCenterUpdate() {
         Assert.assertEquals(newExternalId, center.getExternalId());
         Assert.assertEquals((Integer)newStaffId, center.getStaffId());
         Assert.assertArrayEquals(newGroupMembers, center.getGroupMembers());
+        
+        //Reversing group association to test disassociateGroups command
+        int[] disAssociateResponse = CenterHelper.disassociateGroups(resourceId, groupMembersForLink, requestSpec, responseSpec);
+        Arrays.sort(disAssociateResponse);
+        Arrays.sort(groupMembersForLink);
+        Assert.assertArrayEquals(disAssociateResponse, groupMembersForLink);
     }
 
     @Test
diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CenterHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CenterHelper.java
index 425064466..b64c4b4e7 100644
--- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CenterHelper.java
+++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CenterHelper.java
@@ -113,11 +113,21 @@ public static int createCenter(final String name, final int officeId, final Stri
 
     public static int[] associateGroups(final int id, final int[] groupMembers, final RequestSpecification requestSpec,
             final ResponseSpecification responseSpec) {
-        final String ASSOCIATE_GROUP_CENTER_URL = CENTERS_URL + "/" + id + "?command=associateGroups&" + Utils.TENANT_IDENTIFIER;
+        return linkGroupsToCenterCommand(id, groupMembers, requestSpec, responseSpec, "associateGroups");
+    }
+
+    public static int[] disassociateGroups(final int id, final int[] groupMembers, final RequestSpecification requestSpec,
+            final ResponseSpecification responseSpec) {
+        return linkGroupsToCenterCommand(id, groupMembers, requestSpec, responseSpec, "disassociateGroups");
+    }
+
+    private static int[] linkGroupsToCenterCommand(final int id, final int[] groupMembers, final RequestSpecification requestSpec,
+            final ResponseSpecification responseSpec, String command) {
+        final String CENTER_GROUP_LINK_URL = CENTERS_URL + "/" + id + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
         HashMap groupMemberHashMap = new HashMap();
         groupMemberHashMap.put("groupMembers", groupMembers);
-        System.out.println("---------------------------------ASSOCIATING GROUPS AT " + id + "--------------------------------------------");
-        HashMap hash = Utils.performServerPost(requestSpec, responseSpec, ASSOCIATE_GROUP_CENTER_URL,
+        System.out.println("---------------------------------" + command + " GROUPS AT " + id + "--------------------------------------------");
+        HashMap hash = Utils.performServerPost(requestSpec, responseSpec, CENTER_GROUP_LINK_URL,
                 new Gson().toJson(groupMemberHashMap), "changes");
         System.out.println(hash);
         ArrayList<String> arr = (ArrayList<String>) hash.get("groupMembers");
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/Group.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/Group.java
index c3a14ae7d..36ac48b64 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/Group.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/domain/Group.java
@@ -26,6 +26,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
@@ -41,15 +42,16 @@
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
 
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.fineract.infrastructure.codes.domain.CodeValue;
 import org.apache.fineract.infrastructure.core.api.JsonCommand;
 import org.apache.fineract.infrastructure.core.data.ApiParameterError;
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
 import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
 import org.apache.fineract.infrastructure.core.service.DateUtils;
-import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
 import org.apache.fineract.infrastructure.security.service.RandomPasswordGenerator;
 import org.apache.fineract.organisation.office.domain.Office;
 import org.apache.fineract.organisation.staff.domain.Staff;
@@ -540,7 +542,22 @@ public boolean hasActiveGroups() {
     }
 
     public boolean hasGroupAsMember(final Group group) {
-        return this.groupMembers.contains(group);
+    	if (CollectionUtils.isEmpty(this.groupMembers))
+    	{
+    		return false;
+    	}
+    	List<Long> groupIds = this.groupMembers.stream().map(Group::getId)
+        		.collect(Collectors.toList());
+    	System.out.println("########### " + groupIds + "; group id = " + group.getId());
+        return groupIds.contains(group.getId());
+    }
+
+    public boolean hasGroupAsParent(final Group group) {
+    	if (group.getParent() != null)
+    	{
+    		return this.getId().equals(group.getParent().getId());
+    	}
+    	return false;
     }
 
     public boolean hasStaff() {
@@ -580,10 +597,8 @@ public boolean hasStaff() {
 
         final List<String> differences = new ArrayList<>();
         for (final Group group : groupMembersSet) {
-            if (hasGroupAsMember(group)) {
-                this.groupMembers.remove(group);
+            if (hasGroupAsParent(group)) {
                 differences.add(group.getId().toString());
-    			group.resetHierarchy();
             } else {
                 throw new GroupNotExistsInCenterException(group.getId(), getId());
             }
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java
index 2616c27cb..dd1afbc2d 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java
@@ -884,7 +884,13 @@ public CommandProcessingResult disassociateGroupsToCenter(final Long centerId, f
 
         final List<String> changes = centerForUpdate.disassociateGroups(groupMembers);
         if (!changes.isEmpty()) {
-            actualChanges.put(GroupingTypesApiConstants.clientMembersParamName, changes);
+        	changes.stream().forEach(groupId -> {
+        		Group group = this.groupRepository.findOneWithNotFoundDetection(Long.parseLong(groupId));
+        		group.setParent(null);
+        		group.resetHierarchy();
+        		this.groupRepository.saveAndFlush(group);
+        	});
+            actualChanges.put(GroupingTypesApiConstants.groupMembersParamName, changes);
         }
 
         this.groupRepository.saveAndFlush(centerForUpdate);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services