Skip to content

Commit

Permalink
[SYNCOPE-1846] Multiple Relationships in the same wizard instance (#930)
Browse files Browse the repository at this point in the history
  • Loading branch information
TatoniMatteo authored Dec 10, 2024
1 parent ea308a3 commit 81961d3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected void populateItem(final ListItem<RelationshipTO> relationshipItem) {
@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();
Expand Down Expand Up @@ -133,12 +134,12 @@ private void buildRowLabels(

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -110,7 +108,6 @@ public Relationships(final AnyWrapper<?> modelObject, final PageReference pageRe
}

this.anyTO = modelObject.getInnerObject();
this.specification = new Specification();
this.pageRef = pageRef;

// ------------------------
Expand Down Expand Up @@ -148,7 +145,7 @@ protected Fragment getViewFragment() {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,36 @@ public void editRelationships() {
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",
Expand All @@ -174,17 +193,19 @@ public void editRelationships() {
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
Expand Down

0 comments on commit 81961d3

Please sign in to comment.