This project has retired. For details please refer to its Attic page.
Role xref
View Javadoc

1   package org.apache.archiva.redback.rest.api.model;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import javax.xml.bind.annotation.XmlRootElement;
22  import java.io.Serializable;
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  /**
27   * @author Olivier Lamy
28   * @since 1.4
29   */
30  @XmlRootElement( name = "role" )
31  public class Role
32      implements Serializable
33  {
34      /**
35       * Field name
36       */
37      private String name;
38  
39      /**
40       * Field description
41       */
42      private String description;
43  
44      /**
45       * Field assignable
46       */
47      private boolean assignable = false;
48  
49      /**
50       * Field childRoleNames
51       */
52      private List<String> childRoleNames = new ArrayList<String>(0);
53  
54      /**
55       * Field permissions
56       */
57      private List<Permission> permissions = new ArrayList<Permission>(0);
58  
59      /**
60       * some services doesn't populate this field getAllRoles in RoleManagementService
61       */
62      private List<String> parentRoleNames = new ArrayList<String>(0);
63  
64      /**
65       * user with a parent role
66       * some services doesn't populate this field getAllRoles in RoleManagementService
67       */
68      private List<User> parentsRolesUsers = new ArrayList<User>(0);
69  
70      /**
71       * user with this role
72       * some services doesn't populate this field getAllRoles in RoleManagementService
73       */
74      private List<User> users = new ArrayList<User>(0);
75  
76      /**
77       * users without this role or parent role
78       * some services doesn't populate this field getAllRoles in RoleManagementService
79       */
80      private List<User> otherUsers = new ArrayList<User>(0);
81  
82      /**
83       * users to remove assignement to this role
84       */
85      private List<User> removedUsers = new ArrayList<User>(0);
86  
87      /**
88       * Field permanent
89       */
90      private boolean permanent = false;
91  
92      public Role()
93      {
94          // no op
95      }
96  
97      public Role( String name )
98      {
99          this.name = name;
100     }
101 
102     public Role( org.apache.archiva.redback.rbac.Role role )
103     {
104         this.name = role.getName();
105         this.description = role.getDescription();
106         this.assignable = role.isAssignable();
107         this.childRoleNames = role.getChildRoleNames() == null
108             ? new ArrayList<String>( 0 )
109             : new ArrayList<String>( role.getChildRoleNames() );
110 
111         if ( role.getPermissions() == null )
112         {
113             this.permissions = new ArrayList<Permission>( 0 );
114         }
115         else
116         {
117             for ( org.apache.archiva.redback.rbac.Permission p : role.getPermissions() )
118             {
119                 this.permissions.add( new Permission( p ) );
120             }
121         }
122     }
123 
124     public String getName()
125     {
126         return name;
127     }
128 
129     public void setName( String name )
130     {
131         this.name = name;
132     }
133 
134     public String getDescription()
135     {
136         return description;
137     }
138 
139     public void setDescription( String description )
140     {
141         this.description = description;
142     }
143 
144     public boolean isAssignable()
145     {
146         return assignable;
147     }
148 
149     public void setAssignable( boolean assignable )
150     {
151         this.assignable = assignable;
152     }
153 
154     public List<String> getChildRoleNames()
155     {
156         return childRoleNames;
157     }
158 
159     public void setChildRoleNames( List<String> childRoleNames )
160     {
161         this.childRoleNames = childRoleNames;
162     }
163 
164     public List<Permission> getPermissions()
165     {
166         return permissions;
167     }
168 
169     public void setPermissions( List<Permission> permissions )
170     {
171         this.permissions = permissions;
172     }
173 
174     public boolean isPermanent()
175     {
176         return permanent;
177     }
178 
179     public void setPermanent( boolean permanent )
180     {
181         this.permanent = permanent;
182     }
183 
184     public List<String> getParentRoleNames()
185     {
186         return parentRoleNames;
187     }
188 
189     public void setParentRoleNames( List<String> parentRoleNames )
190     {
191         this.parentRoleNames = parentRoleNames;
192     }
193 
194     public List<User> getParentsRolesUsers()
195     {
196         return parentsRolesUsers;
197     }
198 
199     public void setParentsRolesUsers( List<User> parentsRolesUsers )
200     {
201         this.parentsRolesUsers = parentsRolesUsers;
202     }
203 
204     public List<User> getUsers()
205     {
206         return users;
207     }
208 
209     public void setUsers( List<User> users )
210     {
211         this.users = users;
212     }
213 
214     public List<User> getOtherUsers()
215     {
216         return otherUsers;
217     }
218 
219     public void setOtherUsers( List<User> otherUsers )
220     {
221         this.otherUsers = otherUsers;
222     }
223 
224     public List<User> getRemovedUsers()
225     {
226         return removedUsers;
227     }
228 
229     public void setRemovedUsers( List<User> removedUsers )
230     {
231         this.removedUsers = removedUsers;
232     }
233 
234     @Override
235     public String toString()
236     {
237         final StringBuilder sb = new StringBuilder();
238         sb.append( "Role" );
239         sb.append( "{name='" ).append( name ).append( '\'' );
240         sb.append( ", description='" ).append( description ).append( '\'' );
241         sb.append( ", assignable=" ).append( assignable );
242         sb.append( ", childRoleNames=" ).append( childRoleNames );
243         sb.append( ", permissions=" ).append( permissions );
244         sb.append( ", parentRoleNames=" ).append( parentRoleNames );
245         sb.append( ", parentsRolesUsers=" ).append( parentsRolesUsers );
246         sb.append( ", users=" ).append( users );
247         sb.append( ", otherUsers=" ).append( otherUsers );
248         sb.append( ", removedUsers=" ).append( removedUsers );
249         sb.append( ", permanent=" ).append( permanent );
250         sb.append( '}' );
251         return sb.toString();
252     }
253 
254 
255     @Override
256     public boolean equals( Object o )
257     {
258         if ( this == o )
259         {
260             return true;
261         }
262         if ( o == null || getClass() != o.getClass() )
263         {
264             return false;
265         }
266 
267         Role role = (Role) o;
268 
269         if ( name != null ? !name.equals( role.name ) : role.name != null )
270         {
271             return false;
272         }
273 
274         return true;
275     }
276 
277     @Override
278     public int hashCode()
279     {
280         return name != null ? name.hashCode() : 0;
281     }
282 }