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

andreapatricelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/master by this push:
     new b0c423a  fixes default value initialization in enduser, wizard builder 
instantiated from class specified in configuration param
b0c423a is described below

commit b0c423af80d5df8d26163a7ac290e551e8fbd3ed
Author: Andrea Patricelli <[email protected]>
AuthorDate: Fri Jun 7 12:14:47 2019 +0200

    fixes default value initialization in enduser, wizard builder instantiated 
from class specified in configuration param
---
 .../apache/syncope/client/enduser/pages/Self.java   | 21 ++++++++++++---------
 .../client/enduser/wizards/any/AbstractAttrs.java   |  4 ++++
 .../client/enduser/wizards/any/PlainAttrs.java      |  8 +++++++-
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git 
a/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/pages/Self.java
 
b/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/pages/Self.java
index 686f2e2..67bd151 100644
--- 
a/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/pages/Self.java
+++ 
b/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/pages/Self.java
@@ -23,9 +23,9 @@ import 
org.apache.syncope.client.enduser.SyncopeEnduserSession;
 import org.apache.syncope.client.enduser.SyncopeWebApplication;
 import org.apache.syncope.client.enduser.layout.FormLayoutInfoUtils;
 import org.apache.syncope.client.enduser.layout.UserFormLayoutInfo;
-import org.apache.syncope.client.enduser.wizards.any.UserWizardBuilder;
 import org.apache.syncope.client.ui.commons.Constants;
 import org.apache.syncope.client.ui.commons.wizards.AjaxWizard;
+import org.apache.syncope.client.ui.commons.wizards.AjaxWizardBuilder;
 import org.apache.syncope.client.ui.commons.wizards.any.AnyWrapper;
 import org.apache.syncope.client.ui.commons.wizards.any.UserWrapper;
 import org.apache.syncope.common.keymaster.client.api.ConfParamOps;
@@ -45,7 +45,7 @@ public class Self extends BaseEnduserWebPage implements 
IEventSource {
     @SpringBean
     private ConfParamOps confParamOps;
 
-    private UserWizardBuilder userWizardBuilder;
+    private AjaxWizardBuilder<AnyWrapper<UserTO>> wizardBuilder;
 
     protected static final String WIZARD_ID = "wizard";
 
@@ -97,16 +97,19 @@ public class Self extends BaseEnduserWebPage implements 
IEventSource {
                 "enduser.form.layout.info",
                 FormLayoutInfoUtils.getDefaultValue(),
                 String.class);
-        userWizardBuilder = new UserWizardBuilder(
-                null,
-                userTO,
-                
SyncopeEnduserSession.get().getService(SyncopeService.class).platform().getUserClasses(),
+
+        final UserFormLayoutInfo formLayoutInfo =
                 StringUtils.isBlank(formLayoutConfParam)
                 ? new UserFormLayoutInfo()
-                : FormLayoutInfoUtils.fromJsonString(formLayoutConfParam),
+                : FormLayoutInfoUtils.fromJsonString(formLayoutConfParam);
+
+        wizardBuilder = (AjaxWizardBuilder<AnyWrapper<UserTO>>) 
FormLayoutInfoUtils.instantiate(
+                userTO,
+                
SyncopeEnduserSession.get().getService(SyncopeService.class).platform().getUserClasses(),
+                formLayoutInfo,
                 this.getPageReference());
-        userWizardBuilder.setItem(new UserWrapper(userTO));
-        return userWizardBuilder.build(WIZARD_ID, mode);
+        wizardBuilder.setItem(new UserWrapper(userTO));
+        return wizardBuilder.build(WIZARD_ID, mode);
     }
 
     private UserTO buildNewUserTO(final PageParameters parameters) {
diff --git 
a/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/wizards/any/AbstractAttrs.java
 
b/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/wizards/any/AbstractAttrs.java
index 7e64f40..061756b 100644
--- 
a/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/wizards/any/AbstractAttrs.java
+++ 
b/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/wizards/any/AbstractAttrs.java
@@ -136,6 +136,10 @@ public abstract class AbstractAttrs<S extends SchemaTO> 
extends WizardStep imple
         return whichAttrs.get(schemaName) == null ? false : 
whichAttrs.get(schemaName).isReadonly();
     }
 
+    protected List<String> getDefaultValues(final String schema) {
+        return getDefaultValues(schema, null);
+    }
+    
     protected List<String> getDefaultValues(final String schema, final String 
groupName) {
         String schemaName = 
(org.apache.commons.lang3.StringUtils.isBlank(groupName)
                 ? org.apache.commons.lang3.StringUtils.EMPTY
diff --git 
a/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/wizards/any/PlainAttrs.java
 
b/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/wizards/any/PlainAttrs.java
index ee5dcae..d0189fc 100644
--- 
a/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/wizards/any/PlainAttrs.java
+++ 
b/client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/wizards/any/PlainAttrs.java
@@ -406,7 +406,7 @@ public class PlainAttrs extends 
AbstractAttrs<PlainSchemaTO> {
                     Attr attrTO = item.getModelObject();
 
                     // set default values, if any
-                    if (attrTO.getValues().stream().anyMatch(value -> 
StringUtils.isNotBlank(value))) {
+                    if (attrTO.getValues().stream().noneMatch(value -> 
StringUtils.isNotBlank(value))) {
                         attrTO.getValues().clear();
                         
attrTO.getValues().addAll(getDefaultValues(attrTO.getSchema(), groupName));
                     }
@@ -453,6 +453,12 @@ public class PlainAttrs extends 
AbstractAttrs<PlainSchemaTO> {
                 protected void populateItem(final ListItem<Attr> item) {
                     Attr attrTO = item.getModelObject();
 
+                    // set default values, if any
+                    if (attrTO.getValues().stream().noneMatch(value -> 
StringUtils.isNotBlank(value))) {
+                        attrTO.getValues().clear();
+                        
attrTO.getValues().addAll(getDefaultValues(attrTO.getSchema()));
+                    }
+
                     AbstractFieldPanel<?> panel = 
getFieldPanel(schemas.get(attrTO.getSchema()));
                     if (schemas.get(attrTO.getSchema()).isMultivalue()) {
                         panel = new MultiFieldPanel.Builder<>(

Reply via email to