syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [25/43] syncope git commit: [SYNCOPE-885] leverage on ICondition wizard mechanism
Date Wed, 20 Jul 2016 14:58:19 GMT
[SYNCOPE-885] leverage on ICondition wizard mechanism


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/0414964f
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/0414964f
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/0414964f

Branch: refs/heads/2_0_NO_JAXB
Commit: 0414964f00c29befa5dd347254707fc65c119fb7
Parents: 2526c45
Author: fmartelli <fabio.martelli@gmail.com>
Authored: Wed Jul 13 17:46:33 2016 +0200
Committer: fmartelli <fabio.martelli@gmail.com>
Committed: Wed Jul 13 17:46:33 2016 +0200

----------------------------------------------------------------------
 .../console/wizards/any/AbstractAttrs.java      | 102 ++++++++++---------
 .../client/console/wizards/any/Groups.java      |  12 ++-
 .../client/console/wizards/any/Resources.java   |  18 +++-
 .../client/console/wizards/any/Roles.java       |  12 ++-
 .../client/console/wizards/any/VirAttrs.java    |   2 +-
 .../resources/AbstractConnConfPanel.java        |  14 ++-
 .../wizards/resources/ConnectorConfPanel.java   |   2 +-
 .../resources/ResourceConnConfPanel.java        |   2 +-
 .../syncope/fit/console/TopologyITCase.java     |   3 -
 9 files changed, 102 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/0414964f/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/AbstractAttrs.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/AbstractAttrs.java
b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/AbstractAttrs.java
index 5d3453b..47a3dca 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/AbstractAttrs.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/AbstractAttrs.java
@@ -41,13 +41,15 @@ import org.apache.syncope.common.lib.to.MembershipTO;
 import org.apache.syncope.common.lib.types.SchemaType;
 import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.core.util.lang.PropertyResolver;
+import org.apache.wicket.extensions.wizard.WizardModel.ICondition;
 import org.apache.wicket.extensions.wizard.WizardStep;
 import org.apache.wicket.markup.head.IHeaderResponse;
 import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
 import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.util.ListModel;
 
-public abstract class AbstractAttrs<S extends AbstractSchemaTO> extends WizardStep
{
+public abstract class AbstractAttrs<S extends AbstractSchemaTO> extends WizardStep
implements ICondition {
 
     private static final long serialVersionUID = -5387344116983102292L;
 
@@ -65,64 +67,58 @@ public abstract class AbstractAttrs<S extends AbstractSchemaTO>
extends WizardSt
 
     protected final Map<String, Map<String, S>> membershipSchemas = new LinkedHashMap<>();
 
-    protected final LoadableDetachableModel<List<AttrTO>> attrTOs;
+    protected final IModel<List<AttrTO>> attrTOs;
 
-    protected final LoadableDetachableModel<List<MembershipTO>> membershipTOs;
+    protected final IModel<List<MembershipTO>> membershipTOs;
+
+    private final List<String> anyTypeClasses;
 
     public AbstractAttrs(final AnyTO anyTO, final List<String> anyTypeClasses, final
List<String> whichAttrs) {
         super();
+        this.anyTypeClasses = anyTypeClasses;
+        this.attrTOs = new ListModel<>(Collections.<AttrTO>emptyList());
+        this.membershipTOs = new ListModel<>(Collections.<MembershipTO>emptyList());
+
         this.setOutputMarkupId(true);
 
         this.anyTO = anyTO;
         this.whichAttrs = whichAttrs;
+    }
 
-        this.attrTOs = new LoadableDetachableModel<List<AttrTO>>() {
-
-            private static final long serialVersionUID = 5275935387613157437L;
+    private List<AttrTO> loadAttrTOs() {
+        setSchemas(CollectionUtils.collect(anyTypeClassRestClient.list(anyTO.getAuxClasses()),
+                EntityTOUtils.<AnyTypeClassTO>keyTransformer(), new ArrayList<>(anyTypeClasses)));
+        setAttrs();
+        return AbstractAttrs.this.getAttrsFromTO();
+    }
 
-            @Override
-            protected List<AttrTO> load() {
-                setSchemas(CollectionUtils.collect(anyTypeClassRestClient.list(anyTO.getAuxClasses()),
-                        EntityTOUtils.<AnyTypeClassTO>keyTransformer(), new ArrayList<>(anyTypeClasses)));
-                setAttrs();
-                return AbstractAttrs.this.getAttrsFromTO();
-            }
-        };
-
-        this.membershipTOs = new LoadableDetachableModel<List<MembershipTO>>()
{
-
-            private static final long serialVersionUID = 5275935387613157437L;
-
-            @Override
-            @SuppressWarnings("unchecked")
-            protected List<MembershipTO> load() {
-                List<MembershipTO> memberships = new ArrayList<>();
-                try {
-                    membershipSchemas.clear();
-
-                    for (MembershipTO membership : (List<MembershipTO>) PropertyResolver.getPropertyField(
-                            "memberships", anyTO).get(anyTO)) {
-                        setSchemas(membership.getGroupKey(), CollectionUtils.collect(
-                                anyTypeClassRestClient.list(getMembershipAuxClasses(membership,
anyTO.getType())),
-                                EntityTOUtils.<AnyTypeClassTO>keyTransformer(),
-                                new ArrayList<String>()));
-                        setAttrs(membership);
-
-                        if (AbstractAttrs.this instanceof PlainAttrs && !membership.getPlainAttrs().isEmpty())
{
-                            memberships.add(membership);
-                        } else if (AbstractAttrs.this instanceof DerAttrs && !membership.getDerAttrs().isEmpty())
{
-                            memberships.add(membership);
-                        } else if (AbstractAttrs.this instanceof VirAttrs && !membership.getVirAttrs().isEmpty())
{
-                            memberships.add(membership);
-                        }
-                    }
-                } catch (WicketRuntimeException | IllegalArgumentException | IllegalAccessException
ex) {
-                    // ignore
+    @SuppressWarnings("unchecked")
+    private List<MembershipTO> loadMembershipAttrTOs() {
+        List<MembershipTO> memberships = new ArrayList<>();
+        try {
+            membershipSchemas.clear();
+
+            for (MembershipTO membership : (List<MembershipTO>) PropertyResolver.getPropertyField(
+                    "memberships", anyTO).get(anyTO)) {
+                setSchemas(membership.getGroupKey(), CollectionUtils.collect(
+                        anyTypeClassRestClient.list(getMembershipAuxClasses(membership, anyTO.getType())),
+                        EntityTOUtils.<AnyTypeClassTO>keyTransformer(),
+                        new ArrayList<String>()));
+                setAttrs(membership);
+
+                if (AbstractAttrs.this instanceof PlainAttrs && !membership.getPlainAttrs().isEmpty())
{
+                    memberships.add(membership);
+                } else if (AbstractAttrs.this instanceof DerAttrs && !membership.getDerAttrs().isEmpty())
{
+                    memberships.add(membership);
+                } else if (AbstractAttrs.this instanceof VirAttrs && !membership.getVirAttrs().isEmpty())
{
+                    memberships.add(membership);
                 }
-
-                return memberships;
             }
-        };
+        } catch (WicketRuntimeException | IllegalArgumentException | IllegalAccessException
ex) {
+            // ignore
+        }
+
+        return memberships;
     }
 
     protected boolean reoderSchemas() {
@@ -200,7 +196,7 @@ public abstract class AbstractAttrs<S extends AbstractSchemaTO>
extends WizardSt
                 && org.apache.cxf.common.util.CollectionUtils.isEmpty(membershipTOs.getObject()))
{
             response.render(OnDomReadyHeaderItem.forScript(
                     String.format("$('#emptyPlaceholder').append(\"%s\"); $('#attributes').hide();",
-                            getString("attribute.empty.list"))));
+                    getString("attribute.empty.list"))));
         }
     }
 
@@ -221,6 +217,13 @@ public abstract class AbstractAttrs<S extends AbstractSchemaTO>
extends WizardSt
         }
     }
 
+    @Override
+    public boolean evaluate() {
+        this.attrTOs.setObject(loadAttrTOs());
+        this.membershipTOs.setObject(loadMembershipAttrTOs());
+        return CollectionUtils.isNotEmpty(attrTOs.getObject()) || CollectionUtils.isNotEmpty(membershipTOs.getObject());
+    }
+
     protected static class AttrComparator implements Comparator<AttrTO> {
 
         @Override
@@ -243,6 +246,5 @@ public abstract class AbstractAttrs<S extends AbstractSchemaTO>
extends WizardSt
         public Schemas(final String id) {
             super(id);
         }
-
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/0414964f/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Groups.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Groups.java
b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Groups.java
index 2e17763..fcc5da0 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Groups.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Groups.java
@@ -41,13 +41,16 @@ import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.util.ListModel;
 import org.apache.wicket.util.lang.Args;
 import org.apache.syncope.common.lib.to.GroupableRelatableTO;
+import org.apache.wicket.extensions.wizard.WizardModel.ICondition;
 
-public class Groups extends WizardStep {
+public class Groups extends WizardStep implements ICondition {
 
     private static final long serialVersionUID = 552437609667518888L;
 
     private final GroupRestClient groupRestClient = new GroupRestClient();
 
+    private final List<GroupTO> allGroups;
+
     public <T extends AnyTO> Groups(final T anyTO, final boolean templateMode) {
         super();
         setOutputMarkupId(true);
@@ -111,7 +114,7 @@ public class Groups extends WizardStep {
             }
         }).hideLabel().setOutputMarkupId(true));
 
-        List<GroupTO> allGroups = groupRestClient.search(
+        allGroups = groupRestClient.search(
                 templateMode ? "/" : anyTO.getRealm(), null, -1, -1, new SortParam<>("name",
true), null);
 
         final Map<String, GroupTO> allGroupsByKey = new LinkedHashMap<>(allGroups.size());
@@ -136,4 +139,9 @@ public class Groups extends WizardStep {
         }, new ArrayList<String>()))).
                 hideLabel().setEnabled(false).setOutputMarkupId(true));
     }
+
+    @Override
+    public boolean evaluate() {
+        return CollectionUtils.isNotEmpty(allGroups);
+    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/0414964f/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Resources.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Resources.java
b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Resources.java
index c22b094..bcbd629 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Resources.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Resources.java
@@ -19,6 +19,7 @@
 package org.apache.syncope.client.console.wizards.any;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.syncope.client.console.rest.ResourceRestClient;
@@ -26,16 +27,20 @@ import org.apache.syncope.client.console.wicket.markup.html.form.AjaxPalettePane
 import org.apache.syncope.common.lib.EntityTOUtils;
 import org.apache.syncope.common.lib.to.AnyTO;
 import org.apache.syncope.common.lib.to.ResourceTO;
+import org.apache.wicket.extensions.wizard.WizardModel;
 import org.apache.wicket.extensions.wizard.WizardStep;
 import org.apache.wicket.model.PropertyModel;
 import org.apache.wicket.model.util.ListModel;
 
-public class Resources extends WizardStep {
+public class Resources extends WizardStep implements WizardModel.ICondition {
 
     private static final long serialVersionUID = 552437609667518888L;
 
+    private final ListModel<String> available;
+
     public <T extends AnyTO> Resources(final T entityTO) {
         this.setOutputMarkupId(true);
+        this.available = new ListModel<>(Collections.<String>emptyList());
 
         add(new AjaxPalettePanel.Builder<String>().build("resources",
                 new PropertyModel<List<String>>(entityTO, "resources") {
@@ -52,8 +57,13 @@ public class Resources extends WizardStep {
                 entityTO.getResources().clear();
                 entityTO.getResources().addAll(object);
             }
-        }, new ListModel<>(CollectionUtils.collect(new ResourceRestClient().list(),
-                        EntityTOUtils.<ResourceTO>keyTransformer(), new ArrayList<String>()))).
-                hideLabel().setOutputMarkupId(true));
+        }, available).hideLabel().setOutputMarkupId(true));
+    }
+
+    @Override
+    public boolean evaluate() {
+        available.setObject(CollectionUtils.collect(new ResourceRestClient().list(),
+                EntityTOUtils.<ResourceTO>keyTransformer(), new ArrayList<String>()));
+        return CollectionUtils.isNotEmpty(available.getObject());
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/0414964f/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Roles.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Roles.java
b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Roles.java
index 7133b16..9bee784 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Roles.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/Roles.java
@@ -28,18 +28,21 @@ import org.apache.syncope.common.lib.EntityTOUtils;
 import org.apache.syncope.common.lib.to.AnyTO;
 import org.apache.syncope.common.lib.to.RoleTO;
 import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.wicket.extensions.wizard.WizardModel.ICondition;
 import org.apache.wicket.extensions.wizard.WizardStep;
 import org.apache.wicket.model.PropertyModel;
 import org.apache.wicket.model.util.ListModel;
 
-public class Roles extends WizardStep {
+public class Roles extends WizardStep implements ICondition {
 
     private static final long serialVersionUID = 552437609667518888L;
 
+    private final List<String> allRoles;
+
     public <T extends AnyTO> Roles(final UserTO entityTO) {
         this.setOutputMarkupId(true);
 
-        List<String> allRoles = CollectionUtils.collect(new RoleRestClient().list(),
+        allRoles = CollectionUtils.collect(new RoleRestClient().list(),
                 EntityTOUtils.<RoleTO>keyTransformer(), new ArrayList<String>());
         Collections.sort(allRoles);
 
@@ -51,4 +54,9 @@ public class Roles extends WizardStep {
                 new PropertyModel<List<String>>(entityTO, "dynRoles"),
                 new ListModel<>(allRoles)).hideLabel().setEnabled(false).setOutputMarkupId(true));
     }
+
+    @Override
+    public boolean evaluate() {
+        return CollectionUtils.isNotEmpty(allRoles);
+    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/0414964f/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/VirAttrs.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/VirAttrs.java
b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/VirAttrs.java
index 5b43072..27bc7f3 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/VirAttrs.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/any/VirAttrs.java
@@ -89,7 +89,7 @@ public class VirAttrs extends AbstractAttrs<VirSchemaTO> {
 
                     @Override
                     public WebMarkupContainer getPanel(final String panelId) {
-                        return new VirAttrs.VirSchemas(panelId, new ListModel<AttrTO>(getAttrsFromTO(membershipTO)));
+                        return new VirAttrs.VirSchemas(panelId, new ListModel<>(getAttrsFromTO(membershipTO)));
                     }
                 }), Model.of(-1)).setOutputMarkupId(true));
             }

http://git-wip-us.apache.org/repos/asf/syncope/blob/0414964f/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/AbstractConnConfPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/AbstractConnConfPanel.java
b/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/AbstractConnConfPanel.java
index 215c275..c1c73f4 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/AbstractConnConfPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/AbstractConnConfPanel.java
@@ -19,6 +19,7 @@
 package org.apache.syncope.client.console.wizards.resources;
 
 import java.util.List;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.client.console.SyncopeConsoleSession;
 import org.apache.syncope.client.console.commons.Constants;
@@ -29,16 +30,22 @@ import org.apache.syncope.common.lib.types.ConnConfProperty;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.ajax.markup.html.form.AjaxButton;
 import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton;
+import org.apache.wicket.extensions.wizard.WizardModel;
 import org.apache.wicket.extensions.wizard.WizardStep;
 import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
 import org.apache.wicket.model.ResourceModel;
 
-public abstract class AbstractConnConfPanel<T extends AbstractBaseBean> extends WizardStep
{
+public abstract class AbstractConnConfPanel<T extends AbstractBaseBean>
+        extends WizardStep
+        implements WizardModel.ICondition {
 
     private static final long serialVersionUID = -2025535531121434050L;
 
+    protected LoadableDetachableModel<List<ConnConfProperty>> model;
+
     protected final WebMarkupContainer propertiesContainer;
 
     protected final AjaxButton check;
@@ -80,4 +87,9 @@ public abstract class AbstractConnConfPanel<T extends AbstractBaseBean>
extends
     protected abstract Pair<Boolean, String> check(final AjaxRequestTarget taget);
 
     protected abstract List<ConnConfProperty> getConnProperties(final T instance);
+
+    @Override
+    public boolean evaluate() {
+        return model != null && CollectionUtils.isNotEmpty(model.getObject());
+    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/0414964f/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ConnectorConfPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ConnectorConfPanel.java
b/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ConnectorConfPanel.java
index 56bfd7f..21d494d 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ConnectorConfPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ConnectorConfPanel.java
@@ -40,7 +40,7 @@ public abstract class ConnectorConfPanel extends AbstractConnConfPanel<ConnInsta
         super(connInstanceTO);
         this.bundles = bundles;
 
-        LoadableDetachableModel<List<ConnConfProperty>> model = new LoadableDetachableModel<List<ConnConfProperty>>()
{
+        model = new LoadableDetachableModel<List<ConnConfProperty>>() {
 
             private static final long serialVersionUID = -2965284931860212687L;
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/0414964f/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceConnConfPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceConnConfPanel.java
b/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceConnConfPanel.java
index ab200e0..0869da9 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceConnConfPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceConnConfPanel.java
@@ -43,7 +43,7 @@ public abstract class ResourceConnConfPanel extends AbstractConnConfPanel<Resour
         super(resourceTO);
         this.createFlag = createFlag;
 
-        LoadableDetachableModel<List<ConnConfProperty>> model = new LoadableDetachableModel<List<ConnConfProperty>>()
{
+        model = new LoadableDetachableModel<List<ConnConfProperty>>() {
 
             private static final long serialVersionUID = -2965284931860212687L;
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/0414964f/fit/core-reference/src/test/java/org/apache/syncope/fit/console/TopologyITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/TopologyITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/TopologyITCase.java
index 45a7a6e..96af22e 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/TopologyITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/TopologyITCase.java
@@ -183,9 +183,6 @@ public class TopologyITCase extends AbstractConsoleITCase {
         formTester = TESTER.newFormTester("body:toggle:outerObjectsRepeater:0:outer:form:content:form");
         formTester.submit("buttons:next");
 
-        formTester = TESTER.newFormTester("body:toggle:outerObjectsRepeater:0:outer:form:content:form");
-        formTester.submit("buttons:next");
-
         // click on finish to create the external resource 
         TESTER.cleanupFeedbackMessages();
         // ajax event required to retrieve AjaxRequestTarget (used into finish custom event)


Mime
View raw message