View Javadoc

1   // Created on 31.10.2003
2   package com.pnpconsult.zeiterfassung.model;
3   
4   import java.util.HashMap;
5   import java.util.Iterator;
6   import java.util.Map;
7   import java.util.Set;
8   import java.util.SortedSet;
9   import java.util.TreeSet;
10  
11  import org.apache.commons.lang.StringUtils;
12  import org.apache.commons.lang.builder.EqualsBuilder;
13  import org.apache.commons.lang.builder.HashCodeBuilder;
14  
15  import com.pnpconsult.zeiterfassung.util.Description;
16  
17  /***
18   * @author <a href="mailto:powerpete@users.sf.net">M. Petersen</a>
19   * @version $Id: User.java,v 1.19 2004/06/24 20:54:19 powerpete Exp $
20   * 
21   * @hibernate.class table="user"
22   */
23  public class User extends ArchivableObject
24  {
25      private String firstName;
26      private boolean isMale;
27      private String lastName;
28      private String login;
29      private String password;
30      private float rate;
31      private Set roles;
32      private Map userProjects = new HashMap();
33      private SortedSet userEntries = new TreeSet();
34  
35      /***
36       * @return Returns the entries.
37       * 
38       * @hibernate.set cascade="none" sort="natural"
39       * @hibernate.collection-key column="userLogin"
40       * @hibernate.collection-one-to-many class="com.pnpconsult.zeiterfassung.model.UserEntry"
41       */
42      public SortedSet getUserEntries()
43      {
44          return userEntries;
45      }
46  
47      /***
48       * @param entries
49       *            The entries to set.
50       */
51      public void setUserEntries(SortedSet entries)
52      {
53          this.userEntries = entries;
54      }
55  
56      /***
57       * @return Returns the firstName.
58       * 
59       * @hibernate.property
60       */
61      public String getFirstName()
62      {
63          return firstName;
64      }
65  
66      /***
67       * @return Returns the lastName.
68       * 
69       * @hibernate.property
70       */
71      public String getLastName()
72      {
73          return lastName;
74      }
75  
76      /***
77       * @return Returns the login.
78       * 
79       * @hibernate.id generator-class="assigned"
80       */
81      public String getLogin()
82      {
83          return login;
84      }
85  
86      /***
87       * @return Returns the password.
88       * 
89       * @hibernate.property
90       */
91      public String getPassword()
92      {
93          return password;
94      }
95  
96      /***
97       * @return Returns the rate.
98       * 
99       * @hibernate.property
100      */
101     public float getRate()
102     {
103         return rate;
104     }
105 
106     /***
107      * @return Returns the isMale.
108      * 
109      * @hibernate.property
110      */
111     public boolean isMale()
112     {
113         return isMale;
114     }
115 
116     /***
117      * @param firstName
118      *            The firstName to set.
119      */
120     public void setFirstName(String firstName)
121     {
122         this.firstName = firstName;
123     }
124 
125     /***
126      * @param lastName
127      *            The lastName to set.
128      */
129     public void setLastName(String lastName)
130     {
131         this.lastName = lastName;
132     }
133 
134     /***
135      * @param login
136      *            The login to set.
137      */
138     public void setLogin(String login)
139     {
140         this.login = login;
141     }
142 
143     /***
144      * @param isMale
145      *            The isMale to set.
146      */
147     public void setMale(boolean isMale)
148     {
149         this.isMale = isMale;
150     }
151 
152     /***
153      * @param password
154      *            The password to set.
155      */
156     public void setPassword(String password)
157     {
158         this.password = password;
159     }
160 
161     /***
162      * @param rate
163      *            The rate to set.
164      */
165     public void setRate(float rate)
166     {
167         this.rate = rate;
168     }
169 
170     /***
171      * @return Returns the roles.
172      * 
173      * @hibernate.set table="userrole" lazy="true"
174      * @hibernate.collection-key column="login"
175      * @hibernate.collection-many-to-many class="com.pnpconsult.zeiterfassung.model.Role" column="roleName"
176      */
177     public Set getRoles()
178     {
179         return roles;
180     }
181 
182     /***
183      * @param roles
184      *            The roles to set.
185      */
186     public void setRoles(Set roles)
187     {
188         this.roles = roles;
189     }
190 
191     /***
192      * @return Returns the userProjects.
193      * 
194      * @hibernate.set cascade="none" sort="natural" lazy="true"
195      * @hibernate.collection-key column="userLogin"
196      * @hibernate.collection-one-to-many class="com.pnpconsult.zeiterfassung.model.UserProject"
197      */
198     public SortedSet getUserProjects()
199     {
200         return new TreeSet(userProjects.values());
201     }
202 
203     public void setUserProjects(SortedSet userProjects)
204     {
205         this.userProjects.clear();
206         if (userProjects != null)
207         {
208             for (Iterator it = userProjects.iterator(); it.hasNext();)
209             {
210                 UserProject userProject = (UserProject) it.next();
211                 addUserProject(userProject);
212             }
213         }
214     }
215 
216     public UserProject getUserProject(Project project)
217     {
218         return (UserProject) userProjects.get(project);
219     }
220 
221     public boolean equals(Object obj)
222     {
223         return EqualsBuilder.reflectionEquals(this, obj);
224     }
225 
226     public int hashCode()
227     {
228         return HashCodeBuilder.reflectionHashCode(this);
229     }
230 
231     protected Description buildDescription()
232     {
233         return new Description().append(lastName).append(
234             ", ",
235             null,
236             firstName,
237             null).append(" ", "(", login, ")");
238     }
239 
240     public void addUserProject(UserProject userProject)
241     {
242         userProjects.put(userProject.getProject(), userProject);
243     }
244 
245     public String getDisplayName()
246     {
247         return (StringUtils.stripToEmpty(firstName) + " " + StringUtils
248             .stripToEmpty(lastName)).trim();
249     }
250 }