You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2012/10/25 18:08:08 UTC

svn commit: r1402200 - in /incubator/syncope/branches/1_0_X: client/src/main/java/org/apache/syncope/client/mod/ client/src/main/java/org/apache/syncope/client/util/ core/src/main/java/org/apache/syncope/core/rest/data/ core/src/test/java/org/apache/sy...

Author: ilgrosso
Date: Thu Oct 25 16:08:07 2012
New Revision: 1402200

URL: http://svn.apache.org/viewvc?rev=1402200&view=rev
Log:
[SYNCOPE-228] Aligned with other client convention, when null means 'don't change anything'

Modified:
    incubator/syncope/branches/1_0_X/client/src/main/java/org/apache/syncope/client/mod/RoleMod.java
    incubator/syncope/branches/1_0_X/client/src/main/java/org/apache/syncope/client/util/AttributableOperations.java
    incubator/syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java
    incubator/syncope/branches/1_0_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java

Modified: incubator/syncope/branches/1_0_X/client/src/main/java/org/apache/syncope/client/mod/RoleMod.java
URL: http://svn.apache.org/viewvc/incubator/syncope/branches/1_0_X/client/src/main/java/org/apache/syncope/client/mod/RoleMod.java?rev=1402200&r1=1402199&r2=1402200&view=diff
==============================================================================
--- incubator/syncope/branches/1_0_X/client/src/main/java/org/apache/syncope/client/mod/RoleMod.java (original)
+++ incubator/syncope/branches/1_0_X/client/src/main/java/org/apache/syncope/client/mod/RoleMod.java Thu Oct 25 16:08:07 2012
@@ -18,7 +18,6 @@
  */
 package org.apache.syncope.client.mod;
 
-import java.util.ArrayList;
 import java.util.List;
 import org.codehaus.jackson.annotate.JsonIgnore;
 
@@ -44,12 +43,6 @@ public class RoleMod extends AbstractAtt
 
     private ReferenceMod accountPolicy;
 
-    public RoleMod() {
-        super();
-
-        entitlements = new ArrayList<String>();
-    }
-
     public Boolean getInheritAttributes() {
         return inheritAttributes;
     }
@@ -82,23 +75,12 @@ public class RoleMod extends AbstractAtt
         this.name = name;
     }
 
-    public boolean addEntitlement(final String entitlement) {
-        return entitlements.add(entitlement);
-    }
-
-    public boolean removeEntitlement(final String entitlement) {
-        return entitlements.remove(entitlement);
-    }
-
     public List<String> getEntitlements() {
         return entitlements;
     }
 
     public void setEntitlements(final List<String> entitlements) {
-        this.entitlements.clear();
-        if (entitlements != null && !entitlements.isEmpty()) {
-            this.entitlements.addAll(entitlements);
-        }
+        this.entitlements = entitlements;
     }
 
     public ReferenceMod getPasswordPolicy() {

Modified: incubator/syncope/branches/1_0_X/client/src/main/java/org/apache/syncope/client/util/AttributableOperations.java
URL: http://svn.apache.org/viewvc/incubator/syncope/branches/1_0_X/client/src/main/java/org/apache/syncope/client/util/AttributableOperations.java?rev=1402200&r1=1402199&r2=1402200&view=diff
==============================================================================
--- incubator/syncope/branches/1_0_X/client/src/main/java/org/apache/syncope/client/util/AttributableOperations.java (original)
+++ incubator/syncope/branches/1_0_X/client/src/main/java/org/apache/syncope/client/util/AttributableOperations.java Thu Oct 25 16:08:07 2012
@@ -306,7 +306,9 @@ public final class AttributableOperation
         // 4. entitlements
         Set<String> updatedEnts = new HashSet<String>(updated.getEntitlements());
         Set<String> originalEnts = new HashSet<String>(original.getEntitlements());
-        if (!updatedEnts.equals(originalEnts)) {
+        if (updatedEnts.equals(originalEnts)) {
+            result.setEntitlements(null);
+        } else {
             result.setEntitlements(updated.getEntitlements());
         }
 

Modified: incubator/syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java
URL: http://svn.apache.org/viewvc/incubator/syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java?rev=1402200&r1=1402199&r2=1402200&view=diff
==============================================================================
--- incubator/syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java (original)
+++ incubator/syncope/branches/1_0_X/core/src/main/java/org/apache/syncope/core/rest/data/RoleDataBinder.java Thu Oct 25 16:08:07 2012
@@ -19,10 +19,6 @@
 package org.apache.syncope.core.rest.data;
 
 import java.util.List;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.apache.syncope.core.util.AttributableUtil;
-import org.springframework.http.HttpStatus;
-import org.springframework.stereotype.Component;
 import org.apache.syncope.client.mod.RoleMod;
 import org.apache.syncope.client.to.RoleTO;
 import org.apache.syncope.client.validation.SyncopeClientCompositeErrorException;
@@ -36,8 +32,12 @@ import org.apache.syncope.core.persisten
 import org.apache.syncope.core.persistence.beans.role.SyncopeRole;
 import org.apache.syncope.core.persistence.dao.EntitlementDAO;
 import org.apache.syncope.core.propagation.PropagationByResource;
+import org.apache.syncope.core.util.AttributableUtil;
 import org.apache.syncope.types.AttributableType;
 import org.apache.syncope.types.SyncopeClientExceptionType;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Component;
 
 @Component
 public class RoleDataBinder extends AbstractAttributableDataBinder {
@@ -159,14 +159,15 @@ public class RoleDataBinder extends Abst
         }
 
         // entitlements
-        role.getEntitlements().clear();
-        Entitlement entitlement;
-        for (String entitlementName : roleMod.getEntitlements()) {
-            entitlement = entitlementDAO.find(entitlementName);
-            if (entitlement == null) {
-                LOG.warn("Ignoring invalid entitlement {}", entitlementName);
-            } else {
-                role.addEntitlement(entitlement);
+        if (roleMod.getEntitlements() != null) {
+            role.getEntitlements().clear();
+            for (String entitlementName : roleMod.getEntitlements()) {
+                Entitlement entitlement = entitlementDAO.find(entitlementName);
+                if (entitlement == null) {
+                    LOG.warn("Ignoring invalid entitlement {}", entitlementName);
+                } else {
+                    role.addEntitlement(entitlement);
+                }
             }
         }
 

Modified: incubator/syncope/branches/1_0_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
URL: http://svn.apache.org/viewvc/incubator/syncope/branches/1_0_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java?rev=1402200&r1=1402199&r2=1402200&view=diff
==============================================================================
--- incubator/syncope/branches/1_0_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java (original)
+++ incubator/syncope/branches/1_0_X/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java Thu Oct 25 16:08:07 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.syncope.core.rest;
 
+import java.util.ArrayList;
 import static org.junit.Assert.*;
 
 import java.util.Arrays;
@@ -316,4 +317,46 @@ public class RoleTestITCase extends Abst
         assertEquals("renamed", actual.getName());
         assertEquals(0L, actual.getParent());
     }
+
+    @Test
+    public void issueSYNCOPE228() {
+        RoleTO roleTO = new RoleTO();
+        roleTO.setName("issueSYNCOPE228");
+        roleTO.setParent(8L);
+        roleTO.setInheritAccountPolicy(false);
+        roleTO.setAccountPolicy(6L);
+        roleTO.setInheritPasswordPolicy(true);
+        roleTO.setPasswordPolicy(2L);
+
+        AttributeTO icon = new AttributeTO();
+        icon.setSchema("icon");
+        icon.addValue("anIcon");
+        roleTO.addAttribute(icon);
+
+        roleTO.addEntitlement("USER_READ");
+        roleTO.addEntitlement("SCHEMA_READ");
+
+        roleTO = restTemplate.postForObject(BASE_URL + "role/create", roleTO, RoleTO.class);
+        assertNotNull(roleTO);
+        assertNotNull(roleTO.getEntitlements());
+        assertFalse(roleTO.getEntitlements().isEmpty());
+
+        List<String> entitlements = roleTO.getEntitlements();
+
+        RoleMod roleMod = new RoleMod();
+        roleMod.setId(roleTO.getId());
+        roleMod.setInheritDerivedAttributes(Boolean.TRUE);
+
+        roleTO = restTemplate.postForObject(BASE_URL + "role/update", roleMod, RoleTO.class);
+        assertNotNull(roleTO);
+        assertEquals(entitlements, roleTO.getEntitlements());
+
+        roleMod = new RoleMod();
+        roleMod.setId(roleTO.getId());
+        roleMod.setEntitlements(new ArrayList<String>());
+
+        roleTO = restTemplate.postForObject(BASE_URL + "role/update", roleMod, RoleTO.class);
+        assertNotNull(roleTO);
+        assertTrue(roleTO.getEntitlements().isEmpty());
+    }
 }