View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.client.console.topology;
20  
21  import org.apache.commons.lang3.StringUtils;
22  import org.apache.syncope.client.console.rest.ConnectorRestClient;
23  import org.apache.syncope.client.console.topology.TopologyNode.Kind;
24  import org.apache.syncope.client.console.topology.TopologyTogglePanel.UpdateEvent;
25  import org.apache.syncope.client.ui.commons.Constants;
26  import org.apache.syncope.common.lib.to.ConnInstanceTO;
27  import org.apache.wicket.AttributeModifier;
28  import org.apache.wicket.ajax.IAjaxIndicatorAware;
29  import org.apache.wicket.behavior.AttributeAppender;
30  import org.apache.wicket.event.IEvent;
31  import org.apache.wicket.markup.html.basic.Label;
32  import org.apache.wicket.markup.html.panel.Panel;
33  import org.apache.wicket.spring.injection.annot.SpringBean;
34  
35  public class TopologyNodePanel extends Panel implements IAjaxIndicatorAware {
36  
37      private static final long serialVersionUID = -8775095410207013913L;
38  
39      @SpringBean
40      protected ConnectorRestClient connectorRestClient;
41  
42      protected final Label label;
43  
44      protected final TopologyNode node;
45  
46      protected enum Status {
47          ACTIVE,
48          INACTIVE
49  
50      }
51  
52      public TopologyNodePanel(final String id, final TopologyNode node, final boolean errored) {
53          super(id);
54          this.node = node;
55  
56          label = new Label("label", StringUtils.abbreviate(node.getDisplayName(), 10));
57          label.setOutputMarkupId(true);
58          add(label);
59  
60          String title;
61          switch (node.getKind()) {
62              case SYNCOPE:
63                  title = "";
64                  add(new AttributeAppender("class", "topology_root", " "));
65                  break;
66  
67              case CONNECTOR_SERVER:
68                  title = node.getDisplayName();
69                  add(new AttributeAppender("class", "topology_cs", " "));
70                  break;
71  
72              case FS_PATH:
73                  title = node.getDisplayName();
74                  add(new AttributeAppender("class", "topology_cs", " "));
75                  break;
76  
77              case CONNECTOR:
78                  title = (StringUtils.isBlank(node.getConnectionDisplayName())
79                          ? "" : node.getConnectionDisplayName() + ':') + node.getDisplayName();
80                  if (errored) {
81                      add(new AttributeAppender("class", "topology_conn_errored", " "));
82                  } else {
83                      add(new AttributeAppender("class", "topology_conn", " "));
84                  }
85                  break;
86  
87              case RESOURCE:
88              default:
89                  title = node.getDisplayName().length() > 14 ? node.getDisplayName() : "";
90                  add(new AttributeAppender("class", "topology_res", " "));
91          }
92  
93          if (StringUtils.isNotEmpty(title)) {
94              add(AttributeModifier.append("data-original-title", title));
95          }
96  
97          this.setMarkupId(node.getDisplayName());
98      }
99  
100     @Override
101     public String getAjaxIndicatorMarkupId() {
102         return Constants.VEIL_INDICATOR_MARKUP_ID;
103     }
104 
105     @Override
106     public void onEvent(final IEvent<?> event) {
107         if (event.getPayload() instanceof UpdateEvent) {
108             UpdateEvent updateEvent = UpdateEvent.class.cast(event.getPayload());
109             String key = updateEvent.getKey();
110 
111             if (node.getKind() == Kind.CONNECTOR && key.equalsIgnoreCase(node.getKey())) {
112                 ConnInstanceTO conn = connectorRestClient.read(key);
113 
114                 // [SYNCOPE-1233]
115                 String displayName = StringUtils.isBlank(conn.getDisplayName())
116                         ? conn.getBundleName() : conn.getDisplayName();
117 
118                 label.setDefaultModelObject(StringUtils.abbreviate(displayName, 10));
119                 updateEvent.getTarget().add(label);
120                 node.setDisplayName(displayName);
121             }
122         }
123     }
124 }