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/03/28 15:35:45 UTC

svn commit: r1306317 - in /incubator/syncope/trunk: client/src/main/java/org/syncope/client/to/ client/src/main/java/org/syncope/client/util/ console/src/main/java/org/syncope/console/pages/ core/src/test/java/org/syncope/core/rest/

Author: ilgrosso
Date: Wed Mar 28 13:35:45 2012
New Revision: 1306317

URL: http://svn.apache.org/viewvc?rev=1306317&view=rev
Log:
[SYNCOPE-49] Collections.unmodifiableMap() applied to all proper get*Map() client methods

Modified:
    incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/AbstractAttributableTO.java
    incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/ConnInstanceTO.java
    incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/ConnObjectTO.java
    incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/UserTO.java
    incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/WorkflowFormTO.java
    incubator/syncope/trunk/client/src/main/java/org/syncope/client/util/ConnConfPropUtils.java
    incubator/syncope/trunk/console/src/main/java/org/syncope/console/pages/ApprovalModalPage.java
    incubator/syncope/trunk/core/src/test/java/org/syncope/core/rest/UserTestITCase.java

Modified: incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/AbstractAttributableTO.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/AbstractAttributableTO.java?rev=1306317&r1=1306316&r2=1306317&view=diff
==============================================================================
--- incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/AbstractAttributableTO.java (original)
+++ incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/AbstractAttributableTO.java Wed Mar 28 13:35:45 2012
@@ -19,6 +19,7 @@
 package org.syncope.client.to;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -56,9 +57,16 @@ public abstract class AbstractAttributab
 
     @JsonIgnore
     public Map<String, AttributeTO> getDerivedAttributeMap() {
-        Map<String, AttributeTO> result = new HashMap<String, AttributeTO>(derivedAttributes.size());
-        for (AttributeTO attributeTO : derivedAttributes) {
-            result.put(attributeTO.getSchema(), attributeTO);
+        Map<String, AttributeTO> result;
+
+        if (derivedAttributes == null) {
+            result = Collections.EMPTY_MAP;
+        } else {
+            result = new HashMap<String, AttributeTO>(derivedAttributes.size());
+            for (AttributeTO attributeTO : derivedAttributes) {
+                result.put(attributeTO.getSchema(), attributeTO);
+            }
+            result = Collections.unmodifiableMap(result);
         }
 
         return result;
@@ -66,9 +74,16 @@ public abstract class AbstractAttributab
 
     @JsonIgnore
     public Map<String, AttributeTO> getVirtualAttributeMap() {
-        Map<String, AttributeTO> result = new HashMap<String, AttributeTO>(virtualAttributes.size());
-        for (AttributeTO attributeTO : virtualAttributes) {
-            result.put(attributeTO.getSchema(), attributeTO);
+        Map<String, AttributeTO> result;
+
+        if (derivedAttributes == null) {
+            result = Collections.EMPTY_MAP;
+        } else {
+            result = new HashMap<String, AttributeTO>(virtualAttributes.size());
+            for (AttributeTO attributeTO : virtualAttributes) {
+                result.put(attributeTO.getSchema(), attributeTO);
+            }
+            result = Collections.unmodifiableMap(result);
         }
 
         return result;

Modified: incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/ConnInstanceTO.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/ConnInstanceTO.java?rev=1306317&r1=1306316&r2=1306317&view=diff
==============================================================================
--- incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/ConnInstanceTO.java (original)
+++ incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/ConnInstanceTO.java Wed Mar 28 13:35:45 2012
@@ -18,6 +18,7 @@
  */
 package org.syncope.client.to;
 
+import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -83,9 +84,16 @@ public class ConnInstanceTO extends Abst
 
     @JsonIgnore
     public Map<String, ConnConfProperty> getConfigurationMap() {
-        Map<String, ConnConfProperty> result = new HashMap<String, ConnConfProperty>();
-        for (ConnConfProperty prop : getConfiguration()) {
-            result.put(prop.getSchema().getName(), prop);
+        Map<String, ConnConfProperty> result;
+
+        if (getConfiguration() == null) {
+            result = Collections.EMPTY_MAP;
+        } else {
+            result = new HashMap<String, ConnConfProperty>();
+            for (ConnConfProperty prop : getConfiguration()) {
+                result.put(prop.getSchema().getName(), prop);
+            }
+            result = Collections.unmodifiableMap(result);
         }
 
         return result;
@@ -100,10 +108,9 @@ public class ConnInstanceTO extends Abst
     }
 
     public void setConfiguration(Set<ConnConfProperty> configuration) {
-        if (configuration == null || configuration.isEmpty()) {
-            this.configuration.clear();
-        } else {
-            this.configuration = configuration;
+        this.configuration.clear();
+        if (configuration != null && !configuration.isEmpty()) {
+            this.configuration.addAll(configuration);
         }
     }
 

Modified: incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/ConnObjectTO.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/ConnObjectTO.java?rev=1306317&r1=1306316&r2=1306317&view=diff
==============================================================================
--- incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/ConnObjectTO.java (original)
+++ incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/ConnObjectTO.java Wed Mar 28 13:35:45 2012
@@ -19,6 +19,7 @@
 package org.syncope.client.to;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -55,9 +56,16 @@ public class ConnObjectTO extends Abstra
 
     @JsonIgnore
     public Map<String, AttributeTO> getAttributeMap() {
-        Map<String, AttributeTO> result = new HashMap<String, AttributeTO>(attributes.size());
-        for (AttributeTO attributeTO : attributes) {
-            result.put(attributeTO.getSchema(), attributeTO);
+        Map<String, AttributeTO> result;
+
+        if (attributes == null) {
+            result = Collections.EMPTY_MAP;
+        } else {
+            result = new HashMap<String, AttributeTO>(attributes.size());
+            for (AttributeTO attributeTO : attributes) {
+                result.put(attributeTO.getSchema(), attributeTO);
+            }
+            result = Collections.unmodifiableMap(result);
         }
 
         return result;

Modified: incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/UserTO.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/UserTO.java?rev=1306317&r1=1306316&r2=1306317&view=diff
==============================================================================
--- incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/UserTO.java (original)
+++ incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/UserTO.java Wed Mar 28 13:35:45 2012
@@ -20,6 +20,7 @@ package org.syncope.client.to;
 
 import java.lang.reflect.Field;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -87,10 +88,16 @@ public class UserTO extends AbstractAttr
 
     @JsonIgnore
     public Map<Long, MembershipTO> getMembershipMap() {
-        Map<Long, MembershipTO> result = new HashMap<Long, MembershipTO>(getMemberships().size());
+        Map<Long, MembershipTO> result;
 
-        for (MembershipTO membership : getMemberships()) {
-            result.put(membership.getRoleId(), membership);
+        if (getMemberships() == null) {
+            result = Collections.EMPTY_MAP;
+        } else {
+            result = new HashMap<Long, MembershipTO>(getMemberships().size());
+            for (MembershipTO membership : getMemberships()) {
+                result.put(membership.getRoleId(), membership);
+            }
+            result = Collections.unmodifiableMap(result);
         }
 
         return result;

Modified: incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/WorkflowFormTO.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/WorkflowFormTO.java?rev=1306317&r1=1306316&r2=1306317&view=diff
==============================================================================
--- incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/WorkflowFormTO.java (original)
+++ incubator/syncope/trunk/client/src/main/java/org/syncope/client/to/WorkflowFormTO.java Wed Mar 28 13:35:45 2012
@@ -20,6 +20,7 @@ package org.syncope.client.to;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -120,13 +121,20 @@ public class WorkflowFormTO extends Abst
     }
 
     @JsonIgnore
-    public Map<String, WorkflowFormPropertyTO> getPropertiesAsMap() {
-        Map<String, WorkflowFormPropertyTO> props = new HashMap<String, WorkflowFormPropertyTO>();
-        for (WorkflowFormPropertyTO prop : getProperties()) {
-            props.put(prop.getId(), prop);
+    public Map<String, WorkflowFormPropertyTO> getPropertyMap() {
+        Map<String, WorkflowFormPropertyTO> result;
+
+        if (getProperties() == null) {
+            result = Collections.EMPTY_MAP;
+        } else {
+            result = new HashMap<String, WorkflowFormPropertyTO>();
+            for (WorkflowFormPropertyTO prop : getProperties()) {
+                result.put(prop.getId(), prop);
+            }
+            result = Collections.unmodifiableMap(result);
         }
 
-        return props;
+        return result;
     }
 
     @JsonIgnore

Modified: incubator/syncope/trunk/client/src/main/java/org/syncope/client/util/ConnConfPropUtils.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/client/src/main/java/org/syncope/client/util/ConnConfPropUtils.java?rev=1306317&r1=1306316&r2=1306317&view=diff
==============================================================================
--- incubator/syncope/trunk/client/src/main/java/org/syncope/client/util/ConnConfPropUtils.java (original)
+++ incubator/syncope/trunk/client/src/main/java/org/syncope/client/util/ConnConfPropUtils.java Wed Mar 28 13:35:45 2012
@@ -18,6 +18,7 @@
  */
 package org.syncope.client.util;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -34,20 +35,26 @@ public final class ConnConfPropUtils {
     private ConnConfPropUtils() {
     }
 
-    public static Set<ConnConfProperty> joinConnInstanceProperties(final Map<String, ConnConfProperty> connectorProp,
-            final Map<String, ConnConfProperty> resourceProp) {
+    public static Set<ConnConfProperty> joinConnInstanceProperties(
+            final Map<String, ConnConfProperty> connectorProp, final Map<String, ConnConfProperty> resourceProp) {
 
         connectorProp.putAll(resourceProp);
         return new HashSet<ConnConfProperty>(connectorProp.values());
     }
 
     public static Map<String, ConnConfProperty> getConnConfPropertyMap(final Set<ConnConfProperty> properties) {
-
-        final Map<String, ConnConfProperty> prop = new HashMap<String, ConnConfProperty>();
-        for (Iterator<ConnConfProperty> item = properties.iterator(); item.hasNext();) {
-            ConnConfProperty property = item.next();
-            prop.put(property.getSchema().getName(), property);
+        Map<String, ConnConfProperty> result;
+        if (properties == null) {
+            result = Collections.EMPTY_MAP;
+        } else {
+            result = new HashMap<String, ConnConfProperty>();
+            for (Iterator<ConnConfProperty> item = properties.iterator(); item.hasNext();) {
+                ConnConfProperty property = item.next();
+                result.put(property.getSchema().getName(), property);
+            }
+            result = Collections.unmodifiableMap(result);
         }
-        return prop;
+
+        return result;
     }
 }

Modified: incubator/syncope/trunk/console/src/main/java/org/syncope/console/pages/ApprovalModalPage.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/console/src/main/java/org/syncope/console/pages/ApprovalModalPage.java?rev=1306317&r1=1306316&r2=1306317&view=diff
==============================================================================
--- incubator/syncope/trunk/console/src/main/java/org/syncope/console/pages/ApprovalModalPage.java (original)
+++ incubator/syncope/trunk/console/src/main/java/org/syncope/console/pages/ApprovalModalPage.java Wed Mar 28 13:35:45 2012
@@ -88,9 +88,9 @@ public class ApprovalModalPage extends B
                 FieldPanel field;
                 switch (prop.getType()) {
                     case Boolean:
-                        field = new AjaxDropDownChoicePanel("value", label.getDefaultModelObjectAsString(), new Model(
-                                Boolean.valueOf(prop.getValue()))).setChoices(Arrays
-                                .asList(new String[] { "Yes", "No" }));
+                        field = new AjaxDropDownChoicePanel("value", label.getDefaultModelObjectAsString(),
+                                new Model(Boolean.valueOf(prop.getValue()))).setChoices(Arrays.asList(
+                                new String[]{"Yes", "No"}));
                         break;
 
                     case Date:
@@ -111,11 +111,11 @@ public class ApprovalModalPage extends B
                         break;
 
                     case Enum:
-                        MapChoiceRenderer<String, String> enumCR = new MapChoiceRenderer<String, String>(prop
-                                .getEnumValues());
+                        MapChoiceRenderer<String, String> enumCR =
+                                new MapChoiceRenderer<String, String>(prop.getEnumValues());
 
-                        field = new AjaxDropDownChoicePanel("value", label.getDefaultModelObjectAsString(), new Model(
-                                prop.getValue())).setChoiceRenderer(enumCR).setChoices(new Model() {
+                        field = new AjaxDropDownChoicePanel("value", label.getDefaultModelObjectAsString(),
+                                new Model(prop.getValue())).setChoiceRenderer(enumCR).setChoices(new Model() {
 
                             private static final long serialVersionUID = -858521070366432018L;
 
@@ -127,8 +127,8 @@ public class ApprovalModalPage extends B
                         break;
 
                     case Long:
-                        field = new AjaxNumberFieldPanel("value", label.getDefaultModelObjectAsString(), new Model(Long
-                                .valueOf(prop.getValue())), Long.class);
+                        field = new AjaxNumberFieldPanel("value", label.getDefaultModelObjectAsString(),
+                                new Model(Long.valueOf(prop.getValue())), Long.class);
                         break;
 
                     case String:
@@ -153,7 +153,7 @@ public class ApprovalModalPage extends B
             @Override
             protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
 
-                Map<String, WorkflowFormPropertyTO> props = formTO.getPropertiesAsMap();
+                Map<String, WorkflowFormPropertyTO> props = formTO.getPropertyMap();
 
                 for (int i = 0; i < propView.size(); i++) {
                     ListItem<WorkflowFormPropertyTO> item = (ListItem<WorkflowFormPropertyTO>) propView.get(i);
@@ -166,7 +166,7 @@ public class ApprovalModalPage extends B
                     if (item.getModelObject().isWritable()) {
                         switch (item.getModelObject().getType()) {
                             case Boolean:
-                                props.get(item.getModelObject().getId()).setValue(String.valueOf(input.equals("0")));
+                                props.get(item.getModelObject().getId()).setValue(String.valueOf("0".equals(input)));
                                 break;
 
                             case Date:

Modified: incubator/syncope/trunk/core/src/test/java/org/syncope/core/rest/UserTestITCase.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/test/java/org/syncope/core/rest/UserTestITCase.java?rev=1306317&r1=1306316&r2=1306317&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/test/java/org/syncope/core/rest/UserTestITCase.java (original)
+++ incubator/syncope/trunk/core/src/test/java/org/syncope/core/rest/UserTestITCase.java Wed Mar 28 13:35:45 2012
@@ -650,7 +650,7 @@ public class UserTestITCase extends Abst
         assertNotNull(form.getOwner());
 
         // 5. reject user
-        Map<String, WorkflowFormPropertyTO> props = form.getPropertiesAsMap();
+        Map<String, WorkflowFormPropertyTO> props = form.getPropertyMap();
         props.get("approve").setValue(Boolean.FALSE.toString());
         props.get("rejectReason").setValue("I don't like him.");
         form.setProperties(props.values());
@@ -707,7 +707,7 @@ public class UserTestITCase extends Abst
         assertNotNull(form.getOwner());
 
         // 5. approve user (and verify that propagation occurred)
-        Map<String, WorkflowFormPropertyTO> props = form.getPropertiesAsMap();
+        Map<String, WorkflowFormPropertyTO> props = form.getPropertyMap();
         props.get("approve").setValue(Boolean.TRUE.toString());
         form.setProperties(props.values());
         userTO = restTemplate.postForObject(BASE_URL + "user/workflow/form/submit", form, UserTO.class);