| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 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 |
|
|
| 37 |
|
|
| 38 |
|
@author |
| 39 |
|
|
|
|
|
| 15.8% |
Uncovered Elements: 80 (95) |
Complexity: 50 |
Complexity Density: 0.96 |
|
| 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 |
|
|
| 67 |
|
private UserPreferences userPreferences; |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
private Set<Permission> permissions = new TreeSet<Permission>(Permission.PERMISSION_PROPERTIES_COMPARATOR); |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
private List<Project> projects = new ArrayList<Project>(); |
| 75 |
|
private UserPreferences preferences; |
| 76 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 77 |
0
|
public UserPreferences getPreferences() {... |
| 78 |
0
|
return preferences; |
| 79 |
|
} |
| 80 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 81 |
0
|
public void setPreferences(UserPreferences preferences) {... |
| 82 |
0
|
this.preferences = preferences; |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 121 |
3
|
public User() {... |
| 122 |
|
} |
| 123 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 124 |
0
|
public User(String login) {... |
| 125 |
0
|
setLogin(login); |
| 126 |
|
} |
| 127 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 128 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
| 134 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 146 |
0
|
public String getLogin() {... |
| 147 |
0
|
return login; |
| 148 |
|
} |
| 149 |
|
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 150 |
1
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 157 |
0
|
public String getPassword() {... |
| 158 |
0
|
return password; |
| 159 |
|
} |
| 160 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 161 |
0
|
public void setPassword(String value) {... |
| 162 |
0
|
this.password = value; |
| 163 |
|
} |
| 164 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 165 |
0
|
public String getFirstName() {... |
| 166 |
0
|
return firstName; |
| 167 |
|
} |
| 168 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 169 |
1
|
public void setFirstName(String value) {... |
| 170 |
1
|
firstName = value; |
| 171 |
|
} |
| 172 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 173 |
0
|
public String getLastName() {... |
| 174 |
0
|
return lastName; |
| 175 |
|
} |
| 176 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 177 |
1
|
public void setLastName(String value) {... |
| 178 |
1
|
this.lastName = value; |
| 179 |
|
} |
| 180 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 181 |
0
|
public String getEmail() {... |
| 182 |
0
|
return email; |
| 183 |
|
} |
| 184 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 185 |
0
|
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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 208 |
1
|
public void setEmail(String email) {... |
| 209 |
1
|
this.email = email; |
| 210 |
|
} |
| 211 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 212 |
0
|
public Set<Permission> getPermissions() {... |
| 213 |
0
|
return permissions; |
| 214 |
|
} |
| 215 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 216 |
0
|
public void setPermissions(Set<Permission> getPermissions) {... |
| 217 |
0
|
this.permissions = getPermissions; |
| 218 |
|
} |
| 219 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 220 |
0
|
public UserPreferences getUserPreferences() {... |
| 221 |
0
|
return userPreferences; |
| 222 |
|
} |
| 223 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 224 |
0
|
public void setUserPreferences(UserPreferences getPreferences) {... |
| 225 |
0
|
this.userPreferences = getPreferences; |
| 226 |
|
} |
| 227 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 228 |
0
|
public int getRegistrationType() {... |
| 229 |
0
|
return registrationType; |
| 230 |
|
} |
| 231 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 232 |
0
|
public void setRegistrationType(int registrationType) {... |
| 233 |
0
|
this.registrationType = registrationType; |
| 234 |
|
} |
| 235 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 236 |
0
|
public int getStatus() {... |
| 237 |
0
|
return status; |
| 238 |
|
} |
| 239 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 240 |
1
|
public void setStatus(int status) {... |
| 241 |
1
|
this.status = status; |
| 242 |
|
} |
| 243 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 244 |
0
|
public boolean isSuperUser() {... |
| 245 |
0
|
return superUser; |
| 246 |
|
} |
| 247 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 248 |
1
|
public void setSuperUser(boolean superUser) {... |
| 249 |
1
|
this.superUser = superUser; |
| 250 |
|
} |
| 251 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 252 |
0
|
public String getFirstInitial() {... |
| 253 |
0
|
return (null != getFirstName() && getFirstName().length() > 0 ? getFirstName().substring(0, 1) |
| 254 |
|
.toUpperCase() |
| 255 |
|
+ "." : ""); |
| 256 |
|
} |
| 257 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 258 |
0
|
public boolean hasRequiredData() {... |
| 259 |
0
|
return hasRequiredData(true); |
| 260 |
|
} |
| 261 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 12 |
Complexity Density: 2.4 |
|
| 262 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 277 |
0
|
public List<Project> getProjects() {... |
| 278 |
0
|
return projects; |
| 279 |
|
} |
| 280 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 281 |
0
|
public void setProjects(List<Project> projects) {... |
| 282 |
0
|
this.projects = projects; |
| 283 |
|
} |
| 284 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 285 |
0
|
@Override... |
| 286 |
|
public String toString() { |
| 287 |
0
|
return new ToStringBuilder(this).append("id", getId()) |
| 288 |
|
.append("login", getLogin()).toString(); |
| 289 |
|
} |
| 290 |
|
|
| 291 |
|
|
| 292 |
|
|
| 293 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
| 294 |
|
private static class NameComparator implements Comparator<User> { |
| 295 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 296 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
| 303 |
|
public static final class LoginComparator implements Comparator<User> { |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 304 |
0
|
public int compare(User o1, User o2) {... |
| 305 |
0
|
return new CompareToBuilder().append(o1.getLogin(), o2.getLogin()) |
| 306 |
|
.toComparison(); |
| 307 |
|
} |
| 308 |
|
} |
| 309 |
|
|
| 310 |
|
} |