KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > api > metadata > user > domain > client > UserImpl


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21
22 package com.jaspersoft.jasperserver.api.metadata.user.domain.client;
23
24 import java.io.Serializable JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Set JavaDoc;
28
29 import org.apache.commons.collections.CollectionUtils;
30 import org.apache.commons.collections.Predicate;
31 import org.apache.commons.lang.builder.EqualsBuilder;
32 import org.apache.commons.lang.builder.HashCodeBuilder;
33 import org.apache.commons.lang.builder.ToStringBuilder;
34
35 import com.jaspersoft.jasperserver.api.metadata.user.domain.Role;
36 import com.jaspersoft.jasperserver.api.metadata.user.domain.User;
37
38 /**
39  * @author swood
40  *
41  */

42 public class UserImpl implements User, Serializable JavaDoc {
43     
44     private Set JavaDoc roleSet = new HashSet JavaDoc();
45     private String JavaDoc username = null;
46     private String JavaDoc fullName = null;
47     private String JavaDoc password = null;
48     private String JavaDoc emailAddress = null;
49     private boolean externallyDefined = false;
50     private boolean enabled = false;
51
52     /**
53      * @return Returns the username.
54      *
55      * (non-Javadoc)
56      * @see com.jaspersoft.jasperserver.api.metadata.user.domain.User#getUsername()
57      */

58     public String JavaDoc getUsername() {
59         return username;
60     }
61     
62     public void setUsername(String JavaDoc newUsername) {
63         if (newUsername == null || newUsername.trim().length() == 0) {
64             throw new RuntimeException JavaDoc("No user name");
65         }
66         username = newUsername;
67     }
68
69     /**
70      * @return Returns the fullName.
71      *
72      * (non-Javadoc)
73      * @see com.jaspersoft.jasperserver.api.metadata.user.domain.User#getFullName()
74      */

75     public String JavaDoc getFullName() {
76         return fullName;
77     }
78
79     /**
80      * @param fullName The fullName to set.
81      */

82     public void setFullName(String JavaDoc fullName) {
83         this.fullName = fullName;
84     }
85
86     /**
87      * (non-Javadoc)
88      * @see org.acegisecurity.userdetails.UserDetails#getPassword()
89      */

90     public String JavaDoc getPassword() {
91         return password;
92     }
93
94     /**
95      * @param password The password to set.
96      */

97     public void setPassword(String JavaDoc password) {
98         this.password = password;
99     }
100
101     /**
102      * @return Returns the emailAddress.
103      */

104     public String JavaDoc getEmailAddress() {
105         return emailAddress;
106     }
107
108     /**
109      * @param emailAddress The emailAddress to set.
110      */

111     public void setEmailAddress(String JavaDoc emailAddress) {
112         this.emailAddress = emailAddress;
113     }
114
115     /**
116      *
117      * @return Set
118      */

119     public Set JavaDoc getRoles() {
120         return roleSet;
121     }
122     
123     public void setRoles(Set JavaDoc newRoleSet) {
124         roleSet = newRoleSet;
125     }
126
127     public void addRole(final Role newRole) {
128         /*
129         Predicate findRolePredicate = new Predicate() {
130             public boolean evaluate(Object o) {
131                 Role r = (Role) o;
132                 if (r == null || newRole == null || r.getRoleName() == null || newRole.getRoleName() == null) {
133                     return false;
134                 }
135                 return r.getRoleName().equalsIgnoreCase(newRole.getRoleName());
136             }
137         };
138         Object found = CollectionUtils.find(getRoles(), findRolePredicate);
139         */

140         if (newRole != null && !getRoles().contains(newRole)) {
141             getRoles().add(newRole);
142             // Not for DTO? newRole.getUsers().add(this);
143
}
144     }
145
146     public void removeRole(final Role removedRole) {
147         getRoles().remove(removedRole);
148 // Not for DTO? removedRole.getUsers().remove(this);
149
}
150     
151     /* (non-Javadoc)
152      * @see com.jaspersoft.jasperserver.api.common.domain.AttributedObject#getAttributes()
153      */

154     public List JavaDoc getAttributes() {
155         // TODO Auto-generated method stub
156
return null;
157     }
158
159     /* (non-Javadoc)
160      * @see com.jaspersoft.jasperserver.api.metadata.user.domain.User#isExternallyDefined()
161      */

162     public boolean isExternallyDefined() {
163         return externallyDefined;
164     }
165
166     /* (non-Javadoc)
167      * @see com.jaspersoft.jasperserver.api.metadata.user.domain.User#setExternallyDefined(boolean)
168      */

169     public void setExternallyDefined(boolean externallyDefined) {
170         this.externallyDefined = externallyDefined;
171     }
172
173     /**
174      * (non-Javadoc)
175      * @see org.acegisecurity.userdetails.UserDetails#isEnabled()
176      */

177     public boolean isEnabled() {
178         return enabled;
179     }
180
181     /* (non-Javadoc)
182      * @see com.jaspersoft.jasperserver.api.metadata.user.domain.User#setEnabled(boolean)
183      */

184     public void setEnabled(boolean enabled) {
185         this.enabled = enabled;
186     }
187     
188     public String JavaDoc toString() {
189         return new ToStringBuilder(this)
190             .append("username", getUsername())
191             .toString();
192     }
193
194     public boolean equals(Object JavaDoc other) {
195         if ( !(other instanceof UserImpl) ) return false;
196         UserImpl castOther = (UserImpl) other;
197         return new EqualsBuilder()
198             .append(this.getUsername(), castOther.getUsername())
199             .isEquals();
200     }
201
202     public int hashCode() {
203         return new HashCodeBuilder()
204             .append(getUsername())
205             .toHashCode();
206     }
207
208 }
209
Popular Tags