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.ArrayList;
27  import java.util.Collection;
28  import java.util.Iterator;
29  
30  public class ProjectGroupUserBean
31  {
32      public static final String ROLE_ADMINISTRATOR = "Project Administrator";
33  
34      public static final String ROLE_DEVELOPER = "Project Developer";
35  
36      public static final String ROLE_USER = "Project User";
37  
38      private User user;
39  
40      private ProjectGroup projectGroup;
41  
42      private Collection roles;
43  
44      /*
45       * these booleans should be set on the addition of roles to this bean, see setRoles and addRole 
46       */ boolean isAdministrator = false;
47  
48      boolean isDeveloper = false;
49  
50      boolean isUser = false;
51  
52      public boolean isAdministrator()
53      {
54          return isAdministrator;
55      }
56  
57      public boolean isDeveloper()
58      {
59          return isDeveloper;
60      }
61  
62      public boolean isUser()
63      {
64          return isUser;
65      }
66  
67      public ProjectGroup getProjectGroup()
68      {
69          return projectGroup;
70      }
71  
72      public void setProjectGroup( ProjectGroup projectGroup )
73      {
74          this.projectGroup = projectGroup;
75      }
76  
77      public void addRole( Role role )
78      {
79          if ( roles == null )
80          {
81              roles = new ArrayList();
82          }
83  
84          roles.add( role );
85  
86          if ( role.getName().indexOf( ROLE_ADMINISTRATOR ) != -1 )
87          {
88              isAdministrator = true;
89          }
90  
91          if ( role.getName().indexOf( ROLE_DEVELOPER ) != -1 )
92          {
93              isDeveloper = true;
94          }
95  
96          if ( role.getName().indexOf( ROLE_USER ) != -1 )
97          {
98              isUser = true;
99          }
100     }
101 
102     public Collection getRoles()
103     {
104         return roles;
105     }
106 
107     public void setRoles( Collection roles )
108     {
109         this.roles = roles;
110 
111         for ( Iterator i = roles.iterator(); i.hasNext(); )
112         {
113             Role role = (Role) i.next();
114 
115             if ( role.getName().indexOf( ROLE_ADMINISTRATOR ) != -1 )
116             {
117                 isAdministrator = true;
118             }
119 
120             if ( role.getName().indexOf( ROLE_DEVELOPER ) != -1 )
121             {
122                 isDeveloper = true;
123             }
124 
125             if ( role.getName().indexOf( ROLE_USER ) != -1 )
126             {
127                 isUser = true;
128             }
129         }
130     }
131 
132     public User getUser()
133     {
134         return user;
135     }
136 
137     public void setUser( User user )
138     {
139         this.user = user;
140     }
141 
142     public String getUsername()
143     {
144         return user.getUsername();
145     }
146 
147     public String getUserFullName()
148     {
149         return user.getFullName();
150     }
151 
152     public String getUserEmail()
153     {
154         return user.getEmail();
155     }
156 
157     public String toString()
158     {
159         return user.getUsername() + ": " + roles + ": " + ( isAdministrator() ? "A" : "-" ) +
160             ( isDeveloper() ? "D" : "-" ) + ( isUser() ? "U" : "-" );
161     }
162 
163 }