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.ui.commons.status;
20  
21  import java.io.Serializable;
22  import org.apache.commons.lang3.builder.EqualsBuilder;
23  import org.apache.commons.lang3.builder.HashCodeBuilder;
24  import org.apache.commons.lang3.builder.ToStringBuilder;
25  import org.apache.syncope.common.lib.to.AnyObjectTO;
26  import org.apache.syncope.common.lib.to.AnyTO;
27  import org.apache.syncope.common.lib.to.GroupTO;
28  import org.apache.syncope.common.lib.to.RealmTO;
29  import org.apache.syncope.common.lib.to.UserTO;
30  
31  public class StatusBean implements Serializable {
32  
33      private static final long serialVersionUID = -5207260204921071129L;
34  
35      private final String key;
36  
37      private final String name;
38  
39      private final String resource;
40  
41      private String connObjectLink;
42  
43      private Status status = Status.OBJECT_NOT_FOUND;
44  
45      private boolean linked = true;
46  
47      public StatusBean(final AnyTO any, final String resource) {
48          this.key = any.getKey();
49          this.name = any instanceof UserTO
50                  ? ((UserTO) any).getUsername()
51                  : any instanceof GroupTO
52                          ? ((GroupTO) any).getName()
53                          : ((AnyObjectTO) any).getName();
54          this.resource = resource;
55      }
56  
57      public StatusBean(final RealmTO realm, final String resource) {
58          this.key = realm.getKey();
59          this.name = realm.getFullPath();
60          this.resource = resource;
61      }
62  
63      public String getConnObjectLink() {
64          return connObjectLink;
65      }
66  
67      public void setConnObjectLink(final String connObjectLink) {
68          this.connObjectLink = connObjectLink;
69      }
70  
71      public String getResource() {
72          return resource;
73      }
74  
75      public Status getStatus() {
76          return status;
77      }
78  
79      public void setStatus(final Status status) {
80          this.status = status;
81      }
82  
83      public String getKey() {
84          return key;
85      }
86  
87      public String getName() {
88          return name;
89      }
90  
91      public boolean isLinked() {
92          return linked;
93      }
94  
95      public void setLinked(final boolean linked) {
96          this.linked = linked;
97      }
98  
99      @Override
100     public int hashCode() {
101         return new HashCodeBuilder().
102                 append(key).
103                 append(name).
104                 append(resource).
105                 append(connObjectLink).
106                 append(status).
107                 append(linked).
108                 build();
109     }
110 
111     @Override
112     public boolean equals(final Object obj) {
113         if (this == obj) {
114             return true;
115         }
116         if (obj == null) {
117             return false;
118         }
119         if (getClass() != obj.getClass()) {
120             return false;
121         }
122         final StatusBean other = (StatusBean) obj;
123         return new EqualsBuilder().
124                 append(key, other.key).
125                 append(name, other.name).
126                 append(resource, other.resource).
127                 append(connObjectLink, other.connObjectLink).
128                 append(status, other.status).
129                 append(linked, other.linked).
130                 build();
131     }
132 
133     @Override
134     public String toString() {
135         return new ToStringBuilder(this).
136                 append(key).
137                 append(name).
138                 append(resource).
139                 append(connObjectLink).
140                 append(status).
141                 append(linked).
142                 build();
143     }
144 }