View Javadoc

1   package com.panogenesis.model;
2   
3   import java.io.Serializable;
4   
5   import java.util.ArrayList;
6   import java.util.HashSet;
7   import java.util.Iterator;
8   import java.util.List;
9   import java.util.Set;
10  
11  import org.apache.commons.lang.builder.EqualsBuilder;
12  import org.apache.commons.lang.builder.HashCodeBuilder;
13  import org.apache.commons.lang.builder.ToStringBuilder;
14  import org.apache.commons.lang.builder.ToStringStyle;
15  
16  /***
17   * User class
18   *
19   * This class is used to generate Spring Validation rules
20   * as well as the Hibernate mapping file.
21   *
22   * <p><a href="User.java.html"><i>View Source</i></a></p>
23   *
24   * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
25   *         Updated by Dan Kibler (dan@getrolling.com)
26   *
27   * @hibernate.class table="app_user"
28   */
29  public class User extends BaseObject implements Serializable {
30      protected String username;
31      protected String password;
32      protected String confirmPassword;
33      protected String firstName;
34      protected String lastName;
35      protected Address address = new Address();
36      protected String phoneNumber;
37      protected String email;
38      protected String website;
39      protected String passwordHint;
40      protected Integer version;
41      protected Set roles = new HashSet();
42  
43      /***
44       * Returns the username.
45       *
46       * @return String
47       *
48       * @hibernate.id column="username" length="20" generator-class="assigned"
49       *               unsaved-value="version"
50       */
51      public String getUsername() {
52          return username;
53      }
54  
55      /***
56       * Returns the password.
57       * @return String
58       *
59       * @hibernate.property column="password" not-null="true"
60       */
61      public String getPassword() {
62          return password;
63      }
64  
65      /***
66       * Returns the confirmedPassword.
67       * @return String
68       */
69      public String getConfirmPassword() {
70          return confirmPassword;
71      }
72  
73      /***
74       * Returns the firstName.
75       * @return String
76       *
77       * @hibernate.property column="first_name" not-null="true" length="50"
78       */
79      public String getFirstName() {
80          return firstName;
81      }
82  
83      /***
84       * Returns the lastName.
85       * @return String
86       *
87       * @hibernate.property column="last_name" not-null="true" length="50"
88       */
89      public String getLastName() {
90          return lastName;
91      }
92  
93      public String getFullName() {
94          return firstName + ' ' + lastName;
95      }
96  
97      /***
98       * Returns the address.
99       *
100      * @return Address
101      *
102      * @hibernate.component
103      */
104     public Address getAddress() {
105         return address;
106     }
107 
108     /***
109      * Returns the email.  This is an optional field for specifying a
110      * different e-mail than the username.
111      * 
112      * @return String
113      *
114      * @hibernate.property name="email" not-null="true" unique="true"
115      */
116     public String getEmail() {
117         return email;
118     }
119 
120     /***
121      * Returns the phoneNumber.
122      * @return String
123      *
124      * @hibernate.property column="phone_number" not-null="false"
125      */
126     public String getPhoneNumber() {
127         return phoneNumber;
128     }
129 
130     /***
131      * Returns the website.
132      * @return String
133      *
134      * @hibernate.property column="website" not-null="false"
135      */
136     public String getWebsite() {
137         return website;
138     }
139 
140     /***
141      * Returns the passwordHint.
142      * @return String
143      *
144      * @hibernate.property column="password_hint" not-null="false"
145      */
146     public String getPasswordHint() {
147         return passwordHint;
148     }
149 
150     /***
151      * Returns the user's roles.
152      * @return Set
153      *
154      * @hibernate.set table="user_role" cascade="save-update" lazy="false"
155      * @hibernate.collection-key column="username"
156      * @hibernate.collection-many-to-many class="com.panogenesis.model.Role"
157      *                                    column="role_name"
158      */
159     public Set getRoles() {
160         return roles;
161     }
162 
163     /***
164      * Adds a role for the user
165      *
166      * @param rolename
167      */
168     public void addRole(Role role) {
169         getRoles().add(role);
170     }
171 
172     /***
173      * Sets the username.
174      * @param username The username to set
175      * @spring.validator type="required"
176      */
177     public void setUsername(String username) {
178         this.username = username;
179     }
180 
181     /***
182      * Sets the password.
183      * @param password The password to set
184      *
185      * @spring.validator type="required"
186      * @spring.validator type="twofields" msgkey="errors.twofields"
187      * @spring.validator-args arg1resource="user.password"
188      * @spring.validator-args arg1resource="user.confirmPassword"
189      * @spring.validator-var name="secondProperty" value="confirmPassword"
190      */
191     public void setPassword(String password) {
192         this.password = password;
193     }
194 
195     /***
196      * Sets the confirmedPassword.
197      * @param confirmPassword The confirmed password to set
198      * @spring.validator type="required"
199      */
200     public void setConfirmPassword(String confirmPassword) {
201         this.confirmPassword = confirmPassword;
202     }
203 
204     /***
205      * Sets the firstName.
206      * @spring.validator type="required"
207      * @param firstName The firstName to set
208      */
209     public void setFirstName(String firstName) {
210         this.firstName = firstName;
211     }
212 
213     /***
214      * Sets the lastName.
215      * @param lastName The lastName to set
216      *
217      * @spring.validator type="required"
218      */
219     public void setLastName(String lastName) {
220         this.lastName = lastName;
221     }
222 
223     /***
224      * Sets the address.
225      * @param address The address to set
226      *
227      * @spring.validator
228      */
229     public void setAddress(Address address) {
230         this.address = address;
231     }
232 
233     /***
234      * Sets the email.
235      * @param email The email to set
236      *
237      * @spring.validator type="required"
238      * @spring.validator type="email"
239      */
240     public void setEmail(String email) {
241         this.email = email;
242     }
243 
244     /***
245      * Sets the phoneNumber.
246      * @param phoneNumber The phoneNumber to set
247      *
248      * @spring.validator type="mask" msgkey="errors.phone"
249      * @spring.validator-var name="mask" value="${phone}"
250      */
251     public void setPhoneNumber(String phoneNumber) {
252         this.phoneNumber = phoneNumber;
253     }
254 
255     /***
256      * Sets the website.
257      * @param website The website to set
258      */
259     public void setWebsite(String website) {
260         this.website = website;
261     }
262 
263     /***
264      * @param passwordHint The password hint to set
265      *
266      * @spring.validator type="required"
267      */
268     public void setPasswordHint(String passwordHint) {
269         this.passwordHint = passwordHint;
270     }
271 
272     /***
273      * Sets the roles.
274      * @param roles The roles to set
275      */
276     public void setRoles(Set roles) {
277         this.roles = roles;
278     }
279 
280     /***
281      * @return Returns the updated timestamp.
282      * @hibernate.version
283      */
284     public Integer getVersion() {
285         return version;
286     }
287 
288     /***
289      * @param updated The updated version to set.
290      */
291     public void setVersion(Integer version) {
292         this.version = version;
293     }
294 
295     /***
296      * Convert user roles to LabelValue objects for convenience.  
297      */
298     public List getRoleList() {
299         List userRoles = new ArrayList();
300 
301         if (this.roles != null) {
302             for (Iterator it = roles.iterator(); it.hasNext();) {
303                 Role role = (Role) it.next();
304 
305                 // convert the user's roles to LabelValue Objects
306                 userRoles.add(new LabelValue(role.getName(),
307                                              role.getName()));
308             }
309         }
310 
311         return userRoles;
312     }
313 
314     /***
315      * Generated using Commonclipse (http://commonclipse.sf.net)
316      */
317     public boolean equals(Object object) {
318         if (!(object instanceof User)) {
319             return false;
320         }
321 
322         User rhs = (User) object;
323 
324         return new EqualsBuilder().append(this.password, rhs.password).append(
325                 this.passwordHint, rhs.passwordHint).append(this.address,
326                 rhs.address).append(this.confirmPassword, rhs.confirmPassword)
327                 .append(this.username, rhs.username).append(this.email,
328                         rhs.email).append(this.phoneNumber, rhs.phoneNumber)
329                 .append(this.roles, rhs.roles)
330                 .append(this.website, rhs.website).append(this.firstName,
331                         rhs.firstName).append(this.lastName, rhs.lastName)
332                 .isEquals();
333     }
334 
335     /***
336      * Generated using Commonclipse (http://commonclipse.sf.net)
337      */
338     public int hashCode() {
339         return new HashCodeBuilder(-2022315247, 1437659757).append(
340                 this.password).append(this.passwordHint).append(this.address)
341                 .append(this.confirmPassword).append(this.username).append(
342                         this.email).append(this.phoneNumber).append(this.roles)
343                 .append(this.website).append(this.firstName).append(
344                         this.lastName).toHashCode();
345     }
346 
347     /***
348      * Generated using Commonclipse (http://commonclipse.sf.net)
349      */
350     public String toString() {
351         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
352                 .append("roles", this.roles)
353                 .append("firstName", this.firstName).append("lastName",
354                         this.lastName)
355                 .append("passwordHint", this.passwordHint).append("username",
356                         this.username).append("fullName", this.getFullName())
357                 .append("email", this.email).append("phoneNumber",
358                         this.phoneNumber).append("password", this.password)
359                 .append("address", this.address).append("confirmPassword",
360                         this.confirmPassword).append("website", this.website)
361                 .append("version", this.getVersion()).toString();
362     }
363 }