syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmarte...@apache.org
Subject syncope git commit: [SYNCOPE-801] provides fix for provision rules management
Date Fri, 22 Apr 2016 09:21:01 GMT
Repository: syncope
Updated Branches:
  refs/heads/master 0139df768 -> daecdbbc0


[SYNCOPE-801] provides fix for provision rules management


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

Branch: refs/heads/master
Commit: daecdbbc02f6b9011b8b3e721d6c8ec89abf9169
Parents: 0139df7
Author: fmartelli <fabio.martelli@gmail.com>
Authored: Fri Apr 22 11:20:45 2016 +0200
Committer: fmartelli <fabio.martelli@gmail.com>
Committed: Fri Apr 22 11:20:45 2016 +0200

----------------------------------------------------------------------
 .../console/topology/TopologyTogglePanel.java   | 17 ++++--
 .../resources/ResourceProvisionPanel.java       | 56 ++++++++++++++++++++
 .../resources/ResourceWizardBuilder.java        | 40 ++------------
 .../syncope/fit/console/TopologyITCase.java     |  9 ++--
 4 files changed, 75 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/daecdbbc/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyTogglePanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyTogglePanel.java
b/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyTogglePanel.java
index 77ef7b9..3ecbf11 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyTogglePanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/topology/TopologyTogglePanel.java
@@ -67,6 +67,8 @@ public class TopologyTogglePanel extends TogglePanel<Serializable>
{
 
     protected final BaseModal<Serializable> taskModal;
 
+    protected final BaseModal<Serializable> provisionModal;
+
     public TopologyTogglePanel(final String id, final PageReference pageRef) {
         super(id);
         this.pageRef = pageRef;
@@ -79,6 +81,11 @@ public class TopologyTogglePanel extends TogglePanel<Serializable>
{
         taskModal.size(Modal.Size.Large);
         addOuterObject(taskModal);
 
+        provisionModal = new BaseModal<>("outer");
+        provisionModal.size(Modal.Size.Large);
+        provisionModal.addSumbitButton();
+        addOuterObject(provisionModal);
+
         container = new WebMarkupContainer("container");
         container.setOutputMarkupPlaceholderTag(true);
         addInnerObject(container);
@@ -307,16 +314,16 @@ public class TopologyTogglePanel extends TogglePanel<Serializable>
{
                 ResourceTO modelObject = resourceRestClient.read(node.getKey().toString());
 
                 IModel<ResourceTO> model = new CompoundPropertyModel<>(modelObject);
-                taskModal.setFormModel(model);
+                provisionModal.setFormModel(model);
 
-                target.add(taskModal.setContent(new ResourceProvisionPanel(taskModal, modelObject,
pageRef)));
+                target.add(provisionModal.setContent(new ResourceProvisionPanel(provisionModal,
modelObject, pageRef)));
 
-                taskModal.header(new Model<>(MessageFormat.format(getString("resource.edit"),
node.getKey())));
+                provisionModal.header(new Model<>(MessageFormat.format(getString("resource.edit"),
node.getKey())));
 
                 MetaDataRoleAuthorizationStrategy.
-                        authorize(taskModal.getForm(), ENABLE, StandardEntitlement.RESOURCE_UPDATE);
+                        authorize(provisionModal.getForm(), ENABLE, StandardEntitlement.RESOURCE_UPDATE);
 
-                taskModal.show(true);
+                provisionModal.show(true);
             }
         };
         MetaDataRoleAuthorizationStrategy.authorize(edit, ENABLE, StandardEntitlement.RESOURCE_UPDATE);

http://git-wip-us.apache.org/repos/asf/syncope/blob/daecdbbc/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceProvisionPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceProvisionPanel.java
b/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceProvisionPanel.java
index 5aa7d74..97680bd 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceProvisionPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceProvisionPanel.java
@@ -19,32 +19,46 @@
 package org.apache.syncope.client.console.wizards.resources;
 
 import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
+import org.apache.commons.collections4.IterableUtils;
 import org.apache.commons.collections4.IteratorUtils;
 import org.apache.commons.collections4.Predicate;
 import org.apache.commons.lang3.SerializationUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.client.console.SyncopeConsoleSession;
+import org.apache.syncope.client.console.commons.Constants;
 import org.apache.syncope.client.console.panels.AbstractModalPanel;
 import org.apache.syncope.client.console.panels.ListViewPanel;
+import org.apache.syncope.client.console.rest.ResourceRestClient;
 import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
 import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
 import org.apache.syncope.client.console.wizards.AjaxWizard;
 import org.apache.syncope.client.console.wizards.WizardMgtPanel;
+import org.apache.syncope.common.lib.to.MappingItemTO;
 import org.apache.syncope.common.lib.to.ProvisionTO;
 import org.apache.syncope.common.lib.to.ResourceTO;
 import org.apache.syncope.common.lib.types.StandardEntitlement;
 import org.apache.wicket.PageReference;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.event.Broadcast;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.model.StringResourceModel;
 
 public class ResourceProvisionPanel extends AbstractModalPanel<Serializable> {
 
     private static final long serialVersionUID = -7982691107029848579L;
 
+    private final ResourceTO resourceTO;
+
     public ResourceProvisionPanel(
             final BaseModal<Serializable> modal,
             final ResourceTO resourceTO,
             final PageReference pageRef) {
         super(modal, pageRef);
+        this.resourceTO = resourceTO;
+
         setOutputMarkupId(true);
 
         final ProvisionWizardBuilder wizard = new ProvisionWizardBuilder(resourceTO, pageRef);
@@ -127,4 +141,46 @@ public class ResourceProvisionPanel extends AbstractModalPanel<Serializable>
{
 
         add(list);
     }
+
+    @Override
+    public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
+        try {
+            boolean connObjectKeyError = false;
+
+            final Collection<ProvisionTO> provisions = new ArrayList<>(resourceTO.getProvisions());
+
+            for (ProvisionTO provision : provisions) {
+                if (provision != null) {
+                    if (provision.getMapping() == null || provision.getMapping().getItems().isEmpty())
{
+                        resourceTO.getProvisions().remove(provision);
+                    } else {
+                        long uConnObjectKeyCount = IterableUtils.countMatches(
+                                provision.getMapping().getItems(), new Predicate<MappingItemTO>()
{
+
+                            @Override
+                            public boolean evaluate(final MappingItemTO item) {
+                                return item.isConnObjectKey();
+                            }
+                        });
+
+                        connObjectKeyError = uConnObjectKeyCount != 1;
+                    }
+                }
+            }
+
+            final ResourceTO res;
+            if (connObjectKeyError) {
+                throw new RuntimeException(new StringResourceModel("connObjectKeyValidation").getString());
+            } else {
+                new ResourceRestClient().update(resourceTO);
+                res = resourceTO;
+            }
+            info(getString(Constants.OPERATION_SUCCEEDED));
+            modal.close(target);
+        } catch (Exception e) {
+            LOG.error("While creating or updating {}", resourceTO, e);
+            error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
+        }
+        SyncopeConsoleSession.get().getNotificationPanel().refresh(target);
+    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/daecdbbc/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceWizardBuilder.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceWizardBuilder.java
b/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceWizardBuilder.java
index 195dbf8..a990fd7 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceWizardBuilder.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ResourceWizardBuilder.java
@@ -19,24 +19,17 @@
 package org.apache.syncope.client.console.wizards.resources;
 
 import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
 import org.apache.syncope.client.console.SyncopeConsoleSession;
 import org.apache.syncope.client.console.commons.Constants;
 import org.apache.syncope.client.console.rest.ConnectorRestClient;
 import org.apache.syncope.client.console.rest.ResourceRestClient;
 import org.apache.syncope.client.console.topology.TopologyNode;
 import org.apache.syncope.client.console.wizards.AjaxWizard;
-import org.apache.syncope.common.lib.to.MappingItemTO;
-import org.apache.syncope.common.lib.to.ProvisionTO;
 import org.apache.syncope.common.lib.to.ResourceTO;
 import org.apache.wicket.PageReference;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.extensions.wizard.WizardModel;
 import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.model.StringResourceModel;
 
 /**
  * Resource wizard builder.
@@ -95,39 +88,12 @@ public class ResourceWizardBuilder extends AbstractResourceWizardBuilder<Resourc
     @Override
     protected ResourceTO onApplyInternal(final Serializable modelObject) {
         final ResourceTO resourceTO = ResourceTO.class.cast(modelObject);
-        boolean connObjectKeyError = false;
-
-        final Collection<ProvisionTO> provisions = new ArrayList<>(resourceTO.getProvisions());
-
-        for (ProvisionTO provision : provisions) {
-            if (provision != null) {
-                if (provision.getMapping() == null || provision.getMapping().getItems().isEmpty())
{
-                    resourceTO.getProvisions().remove(provision);
-                } else {
-                    long uConnObjectKeyCount = IterableUtils.countMatches(
-                            provision.getMapping().getItems(), new Predicate<MappingItemTO>()
{
-
-                        @Override
-                        public boolean evaluate(final MappingItemTO item) {
-                            return item.isConnObjectKey();
-                        }
-                    });
-
-                    connObjectKeyError = uConnObjectKeyCount != 1;
-                }
-            }
-        }
-
-        final ResourceTO res;
-        if (connObjectKeyError) {
-            throw new RuntimeException(new StringResourceModel("connObjectKeyValidation").getString());
-        } else if (createFlag) {
-            res = resourceRestClient.create(resourceTO);
+        if (createFlag) {
+            return resourceRestClient.create(resourceTO);
         } else {
             resourceRestClient.update(resourceTO);
-            res = resourceTO;
+            return resourceTO;
         }
-        return res;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/syncope/blob/daecdbbc/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 ba28f31..1a3a410 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
@@ -79,15 +79,14 @@ public class TopologyITCase extends AbstractConsoleITCase {
         wicketTester.executeAjaxEvent(component.getPageRelativePath() + ":res", Constants.ON_CLICK);
         wicketTester.clickLink("body:toggle:container:content:togglePanelContainer:container:actions:provision");
 
-        
-        wicketTester.clickLink("body:toggle:outerObjectsRepeater:1:outer:form:content:provision:container:"
+        wicketTester.clickLink("body:toggle:outerObjectsRepeater:2:outer:form:content:provision:container:"
                 + "content:group:beans:0:actions:panelMapping:mappingLink");
 
-        FormTester formTester = wicketTester.newFormTester("body:toggle:outerObjectsRepeater:1:outer:form:content:"
-                + "provision:container:content:wizard:form");
+        FormTester formTester = wicketTester.newFormTester(
+                "body:toggle:outerObjectsRepeater:2:outer:form:content:provision:container:content:wizard:form");
         formTester.submit("buttons:next");
 
-        wicketTester.assertComponent("body:toggle:outerObjectsRepeater:1:outer:form:content:provision:"
+        wicketTester.assertComponent("body:toggle:outerObjectsRepeater:2:outer:form:content:provision:"
                 + "container:content:wizard:form:view:mapping:mappingContainer:mappings:1",
WebMarkupContainer.class);
     }
 


Mime
View raw message