ilgrosso commented on code in PR #924:
URL: https://github.com/apache/syncope/pull/924#discussion_r1865442685


##########
common/idrepo/lib/src/main/java/org/apache/syncope/common/lib/to/End.java:
##########


Review Comment:
   Enums are generally in the `types` subpackage, so you should move this there.
   However, I think it's better to place the enum directly inside the 
`RelationshipTO` class.



##########
client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/RelationshipViewPanel.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.client.console.panels;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
+import 
org.apache.syncope.client.console.wicket.markup.html.form.ActionLinksTogglePanel;
+import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
+import org.apache.syncope.client.console.wizards.WizardMgtPanel;
+import org.apache.syncope.client.ui.commons.Constants;
+import org.apache.syncope.common.lib.to.AnyObjectTO;
+import org.apache.syncope.common.lib.to.AnyTO;
+import org.apache.syncope.common.lib.to.End;
+import org.apache.syncope.common.lib.to.RelationshipTO;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.AnyEntitlement;
+import org.apache.wicket.AttributeModifier;
+import org.apache.wicket.PageReference;
+import org.apache.wicket.ajax.AjaxEventBehavior;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.model.ResourceModel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class RelationshipViewPanel extends 
WizardMgtPanel<RelationshipTO> {
+
+    private static final long serialVersionUID = -7510529471158257903L;
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(RelationshipViewPanel.class);
+
+    private ActionLinksTogglePanel<RelationshipTO> togglePanel;
+
+    private final ListView<RelationshipTO> relationshipsList;
+
+    private RelationshipViewPanel(
+            final String id,
+            final List<RelationshipTO> relationships,
+            final AnyTO anyTO,
+            final boolean reuseItem,
+            final boolean wizardInModal) {
+        super(id, wizardInModal);
+        addInnerObject(getHeader());
+        relationshipsList = new ListView<>("relationships", relationships) {
+
+            private static final long serialVersionUID = 4983556433071042668L;
+
+            @Override
+            protected void populateItem(final ListItem<RelationshipTO> 
relationshipItem) {
+                RelationshipTO relationshipTO = 
relationshipItem.getModelObject();
+                buildRowLabels(relationshipItem, relationshipTO, anyTO);
+
+                ActionsPanel<RelationshipTO> action = new 
ActionsPanel<>("action", new Model<>(relationshipTO));
+                action.add(new ActionLink<>() {

Review Comment:
   `serialVersionUID` missing, add



##########
client/idrepo/console/src/main/resources/org/apache/syncope/client/console/panels/RelationshipViewPanel.html:
##########
@@ -0,0 +1,66 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<html xmlns="http://www.w3.org/1999/xhtml"; 
xmlns:wicket="http://wicket.apache.org";>
+  <head>
+    <title>Relationship view panel</title>
+  </head>
+  <body>
+    <wicket:extend>
+      <div class="col-xs-12">
+        <div class="card-body table-responsive no-padding">
+          <table class="table table-hover">
+            <tbody>
+              <tr wicket:id="header">
+                <th><span wicket:id="header_left_type" style="text-align: 
center"/></th>
+                <th><span wicket:id="header_left_name" style="text-align: 
center"/></th>
+                <th><span wicket:id="header_relationship" style="text-align: 
center"/></th>
+                <th><span wicket:id="header_right_name" style="text-align: 
center"/></th>
+                <th><span wicket:id="header_right_type" style="text-align: 
center"/></th>
+                <th/>
+              </tr>
+              <tr wicket:id="relationships">
+                <td class="col_width list_view_panel_labels" 
style="text-align: center">
+                  <span wicket:id="left_type"/>
+                </td>
+                <td class="col_width list_view_panel_labels" 
style="text-align: center">
+                  <span wicket:id="left_name"/>
+                </td>
+                <td class="col_width list_view_panel_labels" 
style="text-align: center">
+                  <span wicket:id="relationship"/>
+                </td>
+                <td class="col_width list_view_panel_labels" 
style="text-align: center">
+                  <span wicket:id="right_name"/>
+                </td>
+                <td class="col_width list_view_panel_labels" 
style="text-align: center">
+                  <span wicket:id="right_type"/>
+                </td>
+                <td>
+                  <div class="listview-actions">
+                    <span wicket:id="action">[actions]</span>
+                  </div>
+                </td>
+              </tr>
+            </tbody>
+          </table>
+        </div>
+      </div>
+    </wicket:extend>
+  </body>
+</html>

Review Comment:
   Missing newline at the end of the file



##########
client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/RelationshipViewPanel.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.client.console.panels;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
+import 
org.apache.syncope.client.console.wicket.markup.html.form.ActionLinksTogglePanel;
+import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
+import org.apache.syncope.client.console.wizards.WizardMgtPanel;
+import org.apache.syncope.client.ui.commons.Constants;
+import org.apache.syncope.common.lib.to.AnyObjectTO;
+import org.apache.syncope.common.lib.to.AnyTO;
+import org.apache.syncope.common.lib.to.End;
+import org.apache.syncope.common.lib.to.RelationshipTO;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.AnyEntitlement;
+import org.apache.wicket.AttributeModifier;
+import org.apache.wicket.PageReference;
+import org.apache.wicket.ajax.AjaxEventBehavior;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.model.ResourceModel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class RelationshipViewPanel extends 
WizardMgtPanel<RelationshipTO> {
+
+    private static final long serialVersionUID = -7510529471158257903L;
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(RelationshipViewPanel.class);
+
+    private ActionLinksTogglePanel<RelationshipTO> togglePanel;
+
+    private final ListView<RelationshipTO> relationshipsList;
+
+    private RelationshipViewPanel(
+            final String id,
+            final List<RelationshipTO> relationships,
+            final AnyTO anyTO,
+            final boolean reuseItem,
+            final boolean wizardInModal) {
+        super(id, wizardInModal);
+        addInnerObject(getHeader());
+        relationshipsList = new ListView<>("relationships", relationships) {
+
+            private static final long serialVersionUID = 4983556433071042668L;
+
+            @Override
+            protected void populateItem(final ListItem<RelationshipTO> 
relationshipItem) {
+                RelationshipTO relationshipTO = 
relationshipItem.getModelObject();
+                buildRowLabels(relationshipItem, relationshipTO, anyTO);
+
+                ActionsPanel<RelationshipTO> action = new 
ActionsPanel<>("action", new Model<>(relationshipTO));
+                action.add(new ActionLink<>() {
+                    @Override
+                    public void onClick(final AjaxRequestTarget target, final 
RelationshipTO modelObject) {
+                        relationships.remove(modelObject);
+                        target.add(RelationshipViewPanel.this);
+                    }
+                }, ActionLink.ActionType.DELETE, 
AnyEntitlement.UPDATE.getFor(anyTO.getType()), true).hideLabel();
+
+                if (togglePanel != null) {
+                    relationshipItem.add(new AttributeModifier("style", 
"cursor: pointer;"));
+                    relationshipItem.add(new 
AjaxEventBehavior(Constants.ON_CLICK) {
+
+                        private static final long serialVersionUID = 
-9027652037484739586L;
+
+                        @Override
+                        protected String findIndicatorId() {
+                            return StringUtils.EMPTY;
+                        }
+
+                        @Override
+                        protected void onEvent(final AjaxRequestTarget target) 
{
+                            togglePanel.toggleWithContent(target, action, 
relationshipTO);
+                        }
+                    });
+                }
+
+                if (togglePanel == null) {
+                    relationshipItem.add(action);
+                } else {
+                    relationshipItem.add(new ActionsPanel<>("action", new 
Model<>(relationshipTO))
+                            .setVisible(false)
+                            .setEnabled(false));
+                }
+            }
+        };
+        relationshipsList.setOutputMarkupId(true);
+        relationshipsList.setReuseItems(reuseItem);
+        relationshipsList.setRenderBodyOnly(true);
+
+        addInnerObject(relationshipsList);
+
+    }
+
+    private WebMarkupContainer getHeader() {
+        WebMarkupContainer headerContainer = new WebMarkupContainer("header");
+        headerContainer.add(new Label("header_left_type", 
getString("left.type")));
+        headerContainer.add(new Label("header_left_name", new 
ResourceModel("left.name")));
+        headerContainer.add(new Label("header_relationship", new 
ResourceModel("relationship")));
+        headerContainer.add(new Label("header_right_name", new 
ResourceModel("right.name")));
+        headerContainer.add(new Label("header_right_type", new 
ResourceModel("right.type")));
+        return headerContainer;
+    }
+
+    private void buildRowLabels(
+            final ListItem<RelationshipTO> row,
+            final RelationshipTO relationshipTO,
+            final AnyTO anyTO) {
+        boolean isLeftRelation = relationshipTO.getEnd().equals(End.LEFT);

Review Comment:
   Use `==` with enum values



##########
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java:
##########
@@ -230,6 +234,15 @@ public void create(final AnyObject anyObject, final 
AnyObjectCR anyObjectCR) {
                 AnyObject otherEnd = 
anyObjectDAO.find(relationshipTO.getOtherEndKey());
                 if (otherEnd == null) {
                     LOG.debug("Ignoring invalid anyObject " + 
relationshipTO.getOtherEndKey());
+                } else if (relationshipTO.getEnd().equals(End.RIGHT)) {
+                    LOG.error("Invalid relationship end: {} is not allowed for 
this operation.",

Review Comment:
   Avoid `.` at the end of the log message, follow other messages style



##########
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java:
##########
@@ -230,6 +234,15 @@ public void create(final AnyObject anyObject, final 
AnyObjectCR anyObjectCR) {
                 AnyObject otherEnd = 
anyObjectDAO.find(relationshipTO.getOtherEndKey());
                 if (otherEnd == null) {
                     LOG.debug("Ignoring invalid anyObject " + 
relationshipTO.getOtherEndKey());
+                } else if (relationshipTO.getEnd().equals(End.RIGHT)) {
+                    LOG.error("Invalid relationship end: {} is not allowed for 
this operation.",
+                            relationshipTO.getEnd());
+                    SyncopeClientException assigned =
+                            
SyncopeClientException.build(ClientExceptionType.InvalidRelationship);
+                    assigned.getElements().add("Invalid relationship end: "

Review Comment:
   same as above



##########
client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/RelationshipViewPanel.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.client.console.panels;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
+import 
org.apache.syncope.client.console.wicket.markup.html.form.ActionLinksTogglePanel;
+import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
+import org.apache.syncope.client.console.wizards.WizardMgtPanel;
+import org.apache.syncope.client.ui.commons.Constants;
+import org.apache.syncope.common.lib.to.AnyObjectTO;
+import org.apache.syncope.common.lib.to.AnyTO;
+import org.apache.syncope.common.lib.to.End;
+import org.apache.syncope.common.lib.to.RelationshipTO;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.AnyEntitlement;
+import org.apache.wicket.AttributeModifier;
+import org.apache.wicket.PageReference;
+import org.apache.wicket.ajax.AjaxEventBehavior;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.model.ResourceModel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class RelationshipViewPanel extends 
WizardMgtPanel<RelationshipTO> {
+
+    private static final long serialVersionUID = -7510529471158257903L;
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(RelationshipViewPanel.class);

Review Comment:
   `LOG` is unused, remove



##########
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java:
##########
@@ -355,6 +356,15 @@ public void create(final User user, final UserCR userCR) {
             AnyObject otherEnd = 
anyObjectDAO.find(relationshipTO.getOtherEndKey());
             if (otherEnd == null) {
                 LOG.debug("Ignoring invalid anyObject " + 
relationshipTO.getOtherEndKey());
+            } else if (relationshipTO.getEnd().equals(End.RIGHT)) {
+                LOG.error("Invalid relationship end: {} is not allowed for 
this operation.",

Review Comment:
   same as above



##########
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java:
##########
@@ -355,6 +356,15 @@ public void create(final User user, final UserCR userCR) {
             AnyObject otherEnd = 
anyObjectDAO.find(relationshipTO.getOtherEndKey());
             if (otherEnd == null) {
                 LOG.debug("Ignoring invalid anyObject " + 
relationshipTO.getOtherEndKey());
+            } else if (relationshipTO.getEnd().equals(End.RIGHT)) {

Review Comment:
   same as above



##########
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java:
##########
@@ -230,6 +234,15 @@ public void create(final AnyObject anyObject, final 
AnyObjectCR anyObjectCR) {
                 AnyObject otherEnd = 
anyObjectDAO.find(relationshipTO.getOtherEndKey());
                 if (otherEnd == null) {
                     LOG.debug("Ignoring invalid anyObject " + 
relationshipTO.getOtherEndKey());
+                } else if (relationshipTO.getEnd().equals(End.RIGHT)) {

Review Comment:
   Use `==` with enum values



##########
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java:
##########
@@ -355,6 +356,15 @@ public void create(final User user, final UserCR userCR) {
             AnyObject otherEnd = 
anyObjectDAO.find(relationshipTO.getOtherEndKey());
             if (otherEnd == null) {
                 LOG.debug("Ignoring invalid anyObject " + 
relationshipTO.getOtherEndKey());
+            } else if (relationshipTO.getEnd().equals(End.RIGHT)) {
+                LOG.error("Invalid relationship end: {} is not allowed for 
this operation.",
+                        relationshipTO.getEnd());
+                SyncopeClientException assigned =
+                        
SyncopeClientException.build(ClientExceptionType.InvalidRelationship);
+                assigned.getElements().add("Invalid relationship end: "
+                                           + relationshipTO.getEnd()
+                                           + " is not allowed for this 
operation.");

Review Comment:
   same as above



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@syncope.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to