Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
54   310   52   1.54
10   185   0.96   11.67
35     1.49  
3    
 
 
  User       Line # 40 52 50 15.8% 0.15789473
  User.NameComparator       Line # 294 1 1 0% 0.0
  User.LoginComparator       Line # 303 1 1 0% 0.0
 
No Tests
 
1    /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10    * the Free Software Foundation; either version 2 of the License, or
11    * (at your option) any later version.
12    *
13    * This program is distributed in the hope that it will be useful,
14    * but WITHOUT ANY WARRANTY; without even the implied warranty of
15    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16    * GNU General Public License for more details.
17    */
18   
19    package org.itracker.model;
20   
21    import java.util.ArrayList;
22    import java.util.Comparator;
23    import java.util.List;
24    import java.util.Set;
25    import java.util.TreeSet;
26   
27    import javax.mail.internet.AddressException;
28    import javax.mail.internet.InternetAddress;
29   
30    import org.apache.commons.lang.builder.CompareToBuilder;
31    import org.apache.commons.lang.builder.ToStringBuilder;
32    import org.apache.log4j.Logger;
33    import org.itracker.services.util.UserUtilities;
34   
35    /**
36    * A user.
37    *
38    * @author ready
39    */
 
40    public class User extends AbstractEntity implements Comparable<Entity> {
41   
42    /**
43    *
44    */
45    private static final long serialVersionUID = 1L;
46    private static final Logger log = Logger.getLogger(User.class);
47    public static final Comparator<User> NAME_COMPARATOR = new NameComparator();
48    public static final Comparator<User> LOGIN_COMPARATOR = new LoginComparator();
49   
50    private String login;
51   
52    private String password;
53   
54    private String firstName;
55   
56    private String lastName;
57   
58    private String email;
59   
60    private int status;
61   
62    private boolean superUser;
63   
64    private int registrationType;
65   
66    /** The system configuration for this User. */
67    private UserPreferences userPreferences;
68   
69    /** The Permissions of this User on all Projects. */
70    // TODO: it would be a Set, not list
71    private Set<Permission> permissions = new TreeSet<Permission>(Permission.PERMISSION_PROPERTIES_COMPARATOR);
72   
73    /** The Projects owned by this User. */
74    private List<Project> projects = new ArrayList<Project>();
75    private UserPreferences preferences;
76   
 
77  0 toggle public UserPreferences getPreferences() {
78  0 return preferences;
79    }
80   
 
81  0 toggle public void setPreferences(UserPreferences preferences) {
82  0 this.preferences = preferences;
83    }
84   
85    /*
86    * This class used to have an <code>activities</code> attribute, which was
87    * a Collection<IssueActivity>. This has been removed because the
88    * association User - IssueActivity doesn't need to be navigatable in this
89    * direction.
90    */
91   
92    /*
93    * This class used to have a <code>notifications</code> attribute, which
94    * was a Collection<Notification>. This has been removed because the
95    * association User - Notification doesn't need to be navigatable in this
96    * direction.
97    */
98   
99    /*
100    * This class used to have an <code>attachments</code> attribute, which
101    * was a Collection<IssueAttachment>. This has been removed because the
102    * association User - IssueAttachment doesn't need to be navigatable in this
103    * direction.
104    */
105   
106    /*
107    * This class used to have a <code>history</code> attribute, which was a
108    * Collection<IssueHistory>. This has been removed because the association
109    * User - IssueHistory doesn't need to be navigatable in this direction.
110    */
111   
112    /**
113    * Default constructor (required by Hibernate).
114    *
115    * <p>
116    * PENDING: should be <code>private</code> so that it can only be used by
117    * Hibernate, to ensure that the fields which form an instance's identity
118    * are always initialized/never <tt>null</tt>.
119    * </p>
120    */
 
121  3 toggle public User() {
122    }
123   
 
124  0 toggle public User(String login) {
125  0 setLogin(login);
126    }
127   
 
128  0 toggle public User(String login, String password, String firstName,
129    String lastName, String email, boolean superUser) {
130  0 this(login, password, firstName, lastName, email,
131    UserUtilities.REGISTRATION_TYPE_ADMIN, superUser);
132    }
133   
 
134  0 toggle public User(String login, String password, String firstName,
135    String lastName, String email, int registrationType,
136    boolean superUser) {
137  0 this(login);
138  0 this.password = password;
139  0 this.firstName = firstName;
140  0 this.lastName = lastName;
141  0 this.email = email;
142  0 this.registrationType = registrationType;
143  0 setSuperUser(superUser);
144    }
145   
 
146  0 toggle public String getLogin() {
147  0 return login;
148    }
149   
 
150  1 toggle public void setLogin(String login) {
151  1 if (login == null) {
152  0 throw new IllegalArgumentException("null login");
153    }
154  1 this.login = login;
155    }
156   
 
157  0 toggle public String getPassword() {
158  0 return password;
159    }
160   
 
161  0 toggle public void setPassword(String value) {
162  0 this.password = value;
163    }
164   
 
165  0 toggle public String getFirstName() {
166  0 return firstName;
167    }
168   
 
169  1 toggle public void setFirstName(String value) {
170  1 firstName = value;
171    }
172   
 
173  0 toggle public String getLastName() {
174  0 return lastName;
175    }
176   
 
177  1 toggle public void setLastName(String value) {
178  1 this.lastName = value;
179    }
180   
 
181  0 toggle public String getEmail() {
182  0 return email;
183    }
184   
 
185  0 toggle public InternetAddress getEmailAddress() {
186   
187  0 if (null == getEmail() || getEmail().trim().length() == 0) {
188  0 log.warn("getEmailAddress: failed to get eMail for user "
189    + getLogin() + " (" + getId() + ")");
190  0 return null;
191    }
192  0 try {
193  0 return new InternetAddress(getEmail(), getFirstName() + " "
194    + getLastName());
195    } catch (Exception e) {
196  0 try {
197  0 return new InternetAddress(getEmail());
198    } catch (AddressException e1) {
199  0 log.error("getEmailAddress: failed to parse email '"
200    + getEmail() + "' for user " + getLogin() + " ("
201    + getId() + "), returning null", e1);
202  0 return null;
203    }
204    }
205   
206    }
207   
 
208  1 toggle public void setEmail(String email) {
209  1 this.email = email;
210    }
211   
 
212  0 toggle public Set<Permission> getPermissions() {
213  0 return permissions;
214    }
215   
 
216  0 toggle public void setPermissions(Set<Permission> getPermissions) {
217  0 this.permissions = getPermissions;
218    }
219   
 
220  0 toggle public UserPreferences getUserPreferences() {
221  0 return userPreferences;
222    }
223   
 
224  0 toggle public void setUserPreferences(UserPreferences getPreferences) {
225  0 this.userPreferences = getPreferences;
226    }
227   
 
228  0 toggle public int getRegistrationType() {
229  0 return registrationType;
230    }
231   
 
232  0 toggle public void setRegistrationType(int registrationType) {
233  0 this.registrationType = registrationType;
234    }
235   
 
236  0 toggle public int getStatus() {
237  0 return status;
238    }
239   
 
240  1 toggle public void setStatus(int status) {
241  1 this.status = status;
242    }
243   
 
244  0 toggle public boolean isSuperUser() {
245  0 return superUser;
246    }
247   
 
248  1 toggle public void setSuperUser(boolean superUser) {
249  1 this.superUser = superUser;
250    }
251   
 
252  0 toggle public String getFirstInitial() {
253  0 return (null != getFirstName() && getFirstName().length() > 0 ? getFirstName().substring(0, 1)
254    .toUpperCase()
255    + "." : "");
256    }
257   
 
258  0 toggle public boolean hasRequiredData() {
259  0 return hasRequiredData(true);
260    }
261   
 
262  0 toggle public boolean hasRequiredData(boolean passwordRequired) {
263  0 if (this.getLogin() == null || this.getLogin().equals("")
264    || this.getFirstName() == null
265    || this.getFirstName().equals("") || this.getLastName() == null
266    || this.getLastName().equals("") || this.getEmail() == null
267    || this.getEmail().equals("")) {
268  0 return false;
269    }
270  0 if (passwordRequired
271    && (this.getPassword() == null || this.getPassword().equals(""))) {
272  0 return false;
273    }
274  0 return true;
275    }
276   
 
277  0 toggle public List<Project> getProjects() {
278  0 return projects;
279    }
280   
 
281  0 toggle public void setProjects(List<Project> projects) {
282  0 this.projects = projects;
283    }
284   
 
285  0 toggle @Override
286    public String toString() {
287  0 return new ToStringBuilder(this).append("id", getId())
288    .append("login", getLogin()).toString();
289    }
290   
291    /**
292    * Compares 2 users by last and first name.
293    */
 
294    private static class NameComparator implements Comparator<User> {
295   
 
296  0 toggle public int compare(User a, User b) {
297  0 return new CompareToBuilder().append(a.getLastName(), b.getLastName())
298    .append(a.getFirstName(), b.getFirstName()).append(a, b, LOGIN_COMPARATOR).toComparison();
299    }
300   
301    }
302   
 
303    public static final class LoginComparator implements Comparator<User> {
 
304  0 toggle public int compare(User o1, User o2) {
305  0 return new CompareToBuilder().append(o1.getLogin(), o2.getLogin())
306    .toComparison();
307    }
308    }
309   
310    }