View Javadoc

1   package org.apache.maven.continuum.web.bean;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.continuum.model.project.ProjectGroup;
23  import org.codehaus.plexus.redback.rbac.Role;
24  import org.codehaus.plexus.redback.users.User;
25  
26  import java.util.Collection;
27  import java.util.Iterator;
28  
29  public class ProjectGroupUserBean
30  {
31      public static final String ROLE_ADMINISTRATOR = "Project Administrator";
32  
33      public static final String ROLE_DEVELOPER = "Project Developer";
34  
35      public static final String ROLE_USER = "Project User";
36  
37      private User user;
38  
39      private ProjectGroup projectGroup;
40  
41      private Collection roles;
42  
43      /*
44       * these booleans should be set on the addition of roles to this bean, see setRoles and addRole 
45       */ boolean isAdministrator = false;
46  
47      boolean isDeveloper = false;
48  
49      boolean isUser = false;
50  
51      public boolean isAdministrator()
52      {
53          return isAdministrator;
54      }
55  
56      public boolean isDeveloper()
57      {
58          return isDeveloper;
59      }
60  
61      public boolean isUser()
62      {
63          return isUser;
64      }
65  
66      public ProjectGroup getProjectGroup()
67      {
68          return projectGroup;
69      }
70  
71      public void setProjectGroup( ProjectGroup projectGroup )
72      {
73          this.projectGroup = projectGroup;
74      }
75  
76      public void addRole( String role )
77      {
78          roles.add( role );
79  
80          if ( role.indexOf( ROLE_ADMINISTRATOR ) != -1 )
81          {
82              isAdministrator = true;
83          }
84  
85          if ( role.indexOf( ROLE_DEVELOPER ) != -1 )
86          {
87              isDeveloper = true;
88          }
89  
90          if ( role.indexOf( ROLE_USER ) != -1 )
91          {
92              isUser = true;
93          }
94      }
95  
96      public Collection getRoles()
97      {
98          return roles;
99      }
100 
101     public void setRoles( Collection roles )
102     {
103         this.roles = roles;
104 
105         for ( Iterator i = roles.iterator(); i.hasNext(); )
106         {
107             Role role = (Role) i.next();
108 
109             if ( role.getName().indexOf( ROLE_ADMINISTRATOR ) != -1 )
110             {
111                 isAdministrator = true;
112             }
113 
114             if ( role.getName().indexOf( ROLE_DEVELOPER ) != -1 )
115             {
116                 isDeveloper = true;
117             }
118 
119             if ( role.getName().indexOf( ROLE_USER ) != -1 )
120             {
121                 isUser = true;
122             }
123         }
124     }
125 
126     public User getUser()
127     {
128         return user;
129     }
130 
131     public void setUser( User user )
132     {
133         this.user = user;
134     }
135 
136     public String getUsername()
137     {
138         return user.getUsername();
139     }
140 
141     public String getUserFullName()
142     {
143         return user.getFullName();
144     }
145 
146     public String getUserEmail()
147     {
148         return user.getEmail();
149     }
150 
151     public String toString()
152     {
153         return user.getUsername() + ": " + roles + ": " + ( isAdministrator() ? "A" : "-" ) +
154             ( isDeveloper() ? "D" : "-" ) + ( isUser() ? "U" : "-" );
155     }
156 
157 }