[SYNCOPE-1326] Fix Wizard behavior
authorMarco Di Sabatino Di Diodoro <marco.disabatino@tirasa.net>
Fri, 22 Jun 2018 14:01:29 +0000 (16:01 +0200)
committerMarco Di Sabatino Di Diodoro <marco.disabatino@tirasa.net>
Fri, 22 Jun 2018 15:21:54 +0000 (17:21 +0200)
client/console/src/main/java/org/apache/syncope/client/console/wizards/any/AnyWizardBuilder.java
client/console/src/main/java/org/apache/syncope/client/console/wizards/any/GroupWizardBuilder.java
client/console/src/main/java/org/apache/syncope/client/console/wizards/any/UserWizardBuilder.java

index 2ac9b60..ec3ff78 100644 (file)
@@ -18,7 +18,9 @@
  */
 package org.apache.syncope.client.console.wizards.any;
 
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import org.apache.syncope.client.console.layout.AbstractAnyFormLayout;
 import org.apache.syncope.client.console.layout.AnyForm;
 import org.apache.syncope.client.console.layout.AnyObjectFormLayoutInfo;
@@ -27,6 +29,7 @@ import org.apache.syncope.client.console.layout.UserFormLayoutInfo;
 import org.apache.syncope.client.console.wizards.AjaxWizard;
 import org.apache.syncope.client.console.wizards.AjaxWizardBuilder;
 import org.apache.syncope.common.lib.to.AnyTO;
+import org.apache.syncope.common.lib.to.AttrTO;
 import org.apache.syncope.common.lib.to.GroupTO;
 import org.apache.syncope.common.lib.to.UserTO;
 import org.apache.wicket.PageReference;
@@ -171,4 +174,11 @@ public abstract class AnyWizardBuilder<A extends AnyTO> extends AjaxWizardBuilde
                     pageRef);
         }
     }
+
+    protected Set<AttrTO> cleanEmptyPlainAttrs(final Set<AttrTO> plainAttrs) {
+        Set<AttrTO> newPlainAttrs = new HashSet<>(plainAttrs);
+        plainAttrs.clear();
+        plainAttrs.removeIf(attr -> attr.getValues().isEmpty());
+        return newPlainAttrs;
+    }
 }
index 2e0d47f..ea4c22e 100644 (file)
@@ -91,6 +91,8 @@ public class GroupWizardBuilder extends AnyWizardBuilder<GroupTO> implements Gro
         if (inner.getKey() == null) {
             result = groupRestClient.create(inner);
         } else {
+            inner.getPlainAttrs().clear();
+            inner.getPlainAttrs().addAll(cleanEmptyPlainAttrs(inner.getPlainAttrs()));
             GroupPatch patch = AnyOperations.diff(inner, getOriginalItem().getInnerObject(), false);
             GroupTO originaObj = getOriginalItem().getInnerObject();
 
index 2a932af..12fd4d9 100644 (file)
@@ -82,6 +82,7 @@ public class UserWizardBuilder extends AnyWizardBuilder<UserTO> implements UserF
                     ? UserWrapper.class.cast(modelObject).isStorePasswordInSyncope()
                     : StringUtils.isNotBlank(inner.getPassword()));
         } else {
+            inner.getPlainAttrs().addAll(cleanEmptyPlainAttrs(inner.getPlainAttrs()));
             UserPatch patch = AnyOperations.diff(inner, getOriginalItem().getInnerObject(), false);
 
             if (StringUtils.isNotBlank(inner.getPassword())) {