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

ilgrosso pushed a commit to branch 3_0_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/3_0_X by this push:
     new 81961d3936 [SYNCOPE-1846] Multiple Relationships in the same wizard 
instance  (#930)
81961d3936 is described below

commit 81961d3936b92d07afb64c8a0f0a0e65bc04d52c
Author: Matteo Tatoni <[email protected]>
AuthorDate: Tue Dec 10 07:56:51 2024 +0100

    [SYNCOPE-1846] Multiple Relationships in the same wizard instance  (#930)
---
 .../console/panels/RelationshipViewPanel.java      |  5 ++-
 .../client/console/wizards/any/Relationships.java  |  5 +--
 .../apache/syncope/fit/console/UsersITCase.java    | 45 ++++++++++++++++------
 3 files changed, 37 insertions(+), 18 deletions(-)

diff --git 
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/RelationshipViewPanel.java
 
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/RelationshipViewPanel.java
index cbda4895d9..d979d2f96d 100644
--- 
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/RelationshipViewPanel.java
+++ 
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/RelationshipViewPanel.java
@@ -75,6 +75,7 @@ public final class RelationshipViewPanel extends 
WizardMgtPanel<RelationshipTO>
                     @Override
                     public void onClick(final AjaxRequestTarget target, final 
RelationshipTO modelObject) {
                         relationships.remove(modelObject);
+                        relationshipsList.remove(relationshipItem);
                         target.add(RelationshipViewPanel.this);
                     }
                 }, ActionLink.ActionType.DELETE, 
AnyEntitlement.UPDATE.getFor(anyTO.getType()), true).hideLabel();
@@ -133,12 +134,12 @@ public final class RelationshipViewPanel extends 
WizardMgtPanel<RelationshipTO>
 
         row.add(new Label("relationship", relationshipTO.getType()));
         Label leftEnd = new Label("left_end", isLeftRelation
-                ? String.format("%s %s", anyTO.getType() , anyName)
+                ? String.format("%s %s", anyTO.getType(), anyName)
                 : String.format("%s %s", relationshipTO.getOtherEndType(), 
relationshipTO.getOtherEndName()));
 
         Label rightEnd = new Label("right_end", isLeftRelation
                 ? String.format("%s %s", relationshipTO.getOtherEndType(), 
relationshipTO.getOtherEndName())
-                : String.format("%s %s", anyTO.getType() , anyName));
+                : String.format("%s %s", anyTO.getType(), anyName));
 
         if (anyTO.getKey() != null && 
anyTO.getKey().equals(relationshipTO.getOtherEndKey())) {
             setBold(leftEnd, rightEnd);
diff --git 
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/Relationships.java
 
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/Relationships.java
index 385713dd8f..f017a2d857 100644
--- 
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/Relationships.java
+++ 
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wizards/any/Relationships.java
@@ -91,8 +91,6 @@ public class Relationships extends WizardStep implements 
ICondition {
 
     protected final AnyTO anyTO;
 
-    protected final Specification specification;
-
     protected final PageReference pageRef;
 
     public Relationships(final AnyWrapper<?> modelObject, final PageReference 
pageRef) {
@@ -110,7 +108,6 @@ public class Relationships extends WizardStep implements 
ICondition {
         }
 
         this.anyTO = modelObject.getInnerObject();
-        this.specification = new Specification();
         this.pageRef = pageRef;
 
         // ------------------------
@@ -148,7 +145,7 @@ public class Relationships extends WizardStep implements 
ICondition {
             public void onClick(final AjaxRequestTarget target, final 
RelationshipTO ignore) {
                 Fragment addFragment = new Fragment("relationships", 
"addFragment", Relationships.this);
                 addOrReplace(addFragment);
-                addFragment.add(specification.setRenderBodyOnly(true));
+                addFragment.add(new Specification().setRenderBodyOnly(true));
                 target.add(Relationships.this);
             }
         }, ActionType.CREATE, 
AnyEntitlement.UPDATE.getFor(anyTO.getType())).hideLabel();
diff --git 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/UsersITCase.java
 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/UsersITCase.java
index 38a8357509..77a93e17d9 100644
--- 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/UsersITCase.java
+++ 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/UsersITCase.java
@@ -155,17 +155,36 @@ public class UsersITCase extends AbstractConsoleITCase {
         assertNotNull(formTester);
         formTester.submit("buttons:next");
 
-        TESTER.executeAjaxEvent(TAB_PANEL
-                + 
"outerObjectsRepeater:0:outer:form:content:form:view:relationships:actions:"
-                + "actionRepeater:0:action:action", Constants.ON_CLICK);
+        // Add first RELATIONSHIP
+        addRelationship("Canon MF 8030cn");
+        component = TESTER.getComponentFromLastRenderedPage(TAB_PANEL + 
"outerObjectsRepeater:0:outer"
+                + 
":form:content:form:view:relationships:relationships:container:content:relationships:0:right_end");
+        assertNotNull(component);
+        assertEquals("PRINTER Canon MF 8030cn", 
component.getDefaultModel().getObject());
+
+        // Add second RELATIONSHIP
+        addRelationship("HP LJ 1300n");
+        component = TESTER.getComponentFromLastRenderedPage(TAB_PANEL + 
"outerObjectsRepeater:0:outer"
+                + 
":form:content:form:view:relationships:relationships:container:content:relationships:1:right_end");
+        assertNotNull(component);
+        assertEquals("PRINTER HP LJ 1300n", 
component.getDefaultModel().getObject());
 
         formTester = TESTER.newFormTester(TAB_PANEL + 
"outerObjectsRepeater:0:outer:form:content:form");
         assertNotNull(formTester);
+        formTester.submit("buttons:cancel");
+    }
 
-        
formTester.setValue("view:relationships:specification:type:dropDownChoiceField",
 "1");
-        TESTER.executeAjaxEvent(TAB_PANEL
-                + 
"outerObjectsRepeater:0:outer:form:content:form:view:relationships:"
+    // issue SYNCOPE-1846
+    private void addRelationship(final String printerName) {
+        TESTER.executeAjaxEvent(TAB_PANEL + 
"outerObjectsRepeater:0:outer:form:content:form:view:relationships:actions:"
+                + "actionRepeater:0:action:action", Constants.ON_CLICK);
+        FormTester formTester = TESTER.newFormTester(TAB_PANEL + 
"outerObjectsRepeater:0:outer:form:content:form");
+        assertNotNull(formTester);
+
+        
formTester.setValue("view:relationships:specification:type:dropDownChoiceField",
 "neighborhood");
+        TESTER.executeAjaxEvent(TAB_PANEL + 
"outerObjectsRepeater:0:outer:form:content:form:view:relationships:"
                 + "specification:type:dropDownChoiceField", 
Constants.ON_CHANGE);
+         
formTester.setValue("view:relationships:specification:type:dropDownChoiceField",
 "neighborhood");
         // The ON_CHANGE above should enable this component, but it doesn't; 
doing it by hand
         Component otherType = findComponentById(
                 TAB_PANEL + 
"outerObjectsRepeater:0:outer:form:content:form:view:relationships:specification",
@@ -174,17 +193,19 @@ public class UsersITCase extends AbstractConsoleITCase {
         otherType.setEnabled(true);
 
         
formTester.setValue("view:relationships:specification:otherType:dropDownChoiceField",
 "PRINTER");
-        TESTER.executeAjaxEvent(TAB_PANEL
-                + 
"outerObjectsRepeater:0:outer:form:content:form:view:relationships:"
+        TESTER.executeAjaxEvent(TAB_PANEL + 
"outerObjectsRepeater:0:outer:form:content:form:view:relationships:"
                 + "specification:otherType:dropDownChoiceField", 
Constants.ON_CHANGE);
 
-        component = findComponentByProp("name", TAB_PANEL + 
"outerObjectsRepeater:"
+        Component component = findComponentByProp("name", TAB_PANEL + 
"outerObjectsRepeater:"
                 + 
"0:outer:form:content:form:view:relationships:specification:searchPanelContainer:searchPanel:"
                 + 
"searchResultPanel:container:content:searchContainer:resultTable:tablePanel:groupForm:checkgroup:"
-                + "dataTable:body:rows:1:cells:2:cell", "Canon MF 8030cn");
+                + "dataTable:body:rows:1:cells:2:cell", printerName);
         assertNotNull(component);
-
-        formTester.submit("buttons:cancel");
+        TESTER.executeAjaxEvent(component, Constants.ON_CLICK);
+        TESTER.clickLink(TAB_PANEL + 
"outerObjectsRepeater:0:outer:form:content:form:view:relationships:specification:"
+                + "searchPanelContainer:searchPanel:searchResultPanel:"
+                + 
"outerObjectsRepeater:1:outer:container:content:togglePanelContainer:container:"
+                + "actions:actions:actionRepeater:0:action:action");
     }
 
     @Test

Reply via email to