1 16 package com.blandware.atleap.model.core; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 42 public class User extends BaseObject { 43 46 protected String name; 47 protected String password; 48 protected String updatePassword; 49 protected String confirmPassword; 50 protected String updateConfirmPassword; 51 protected String firstName; 52 protected String lastName; 53 protected String address; 54 protected String city; 55 protected String province; 56 protected String country; 57 protected String postalCode; 58 protected String phoneNumber; 59 protected String email; 60 protected String website; 61 62 65 protected List roles = new ArrayList (); 66 72 protected List rolesAssociations = new ArrayList (); 73 76 protected List freeRoles = new ArrayList (); 77 80 protected List groups = new ArrayList (); 81 84 protected Long version; 85 88 protected Boolean enabled; 89 90 103 public String getName() { 104 return name; 105 } 106 107 123 public String getPassword() { 124 return password; 125 } 126 127 149 public String getUpdatePassword() { 150 return updatePassword; 151 } 152 153 161 public String getConfirmPassword() { 162 return confirmPassword; 163 } 164 165 179 public String getUpdateConfirmPassword() { 180 return confirmPassword; 181 } 182 183 192 public String getFirstName() { 193 return firstName; 194 } 195 196 203 public String getLastName() { 204 return lastName; 205 } 206 207 212 public String getFullName() { 213 if ( lastName == null || lastName.length() == 0 ) { 214 return firstName; 215 } 216 return firstName + ' ' + lastName; 217 } 218 219 226 public String getAddress() { 227 return address; 228 } 229 230 237 public String getCity() { 238 return city; 239 } 240 241 248 public String getProvince() { 249 return province; 250 } 251 252 259 public String getCountry() { 260 return country; 261 } 262 263 273 public String getPostalCode() { 274 return postalCode; 275 } 276 277 289 public String getEmail() { 290 return email; 291 } 292 293 303 public String getPhoneNumber() { 304 return phoneNumber; 305 } 306 307 314 public String getWebsite() { 315 return website; 316 } 317 318 329 public List getRolesAssociations() { 330 return rolesAssociations; 331 } 332 333 338 public List getRoles() { 339 return roles; 340 } 341 342 348 public List getFreeRoles() { 349 return freeRoles; 350 } 351 352 362 public List getGroups() { 363 return groups; 364 } 365 366 371 public void setGroups(List groups) { 372 this.groups = groups; 373 } 374 375 382 public Boolean getEnabled() { 383 return enabled; 384 } 385 386 391 public String getRolesAsString() { 392 StringBuffer roles = new StringBuffer (); 393 if ( this.roles != null && this.roles.size() > 0 ) { 394 for ( Iterator i = this.roles.iterator(); i.hasNext(); ) { 395 Role role = (Role) i.next(); 396 roles.append(role.getTitle()); 397 if ( i.hasNext() ) { 398 roles.append(", "); 399 } 400 } 401 } 402 return roles.toString(); 403 } 404 405 410 public String getFreeRolesAsString() { 411 StringBuffer roles = new StringBuffer (); 412 if ( this.freeRoles != null && this.freeRoles.size() > 0 ) { 413 for ( Iterator i = this.freeRoles.iterator(); i.hasNext(); ) { 414 Role role = (Role) i.next(); 415 roles.append(role.getTitle()); 416 if ( i.hasNext() ) { 417 roles.append(", "); 418 } 419 } 420 } 421 return roles.toString(); 422 } 423 424 429 public String getGroupsAsString() { 430 StringBuffer groups = new StringBuffer (); 431 if ( this.groups != null && this.groups.size() > 0 ) { 432 for ( Iterator i = this.groups.iterator(); i.hasNext(); ) { 433 Group group = (Group) i.next(); 434 groups.append(group.getTitle()); 435 if ( i.hasNext() ) { 436 groups.append(", "); 437 } 438 } 439 } 440 return groups.toString(); 441 } 442 443 450 public Long getVersion() { 451 return version; 452 } 453 454 459 public void setName(String name) { 460 this.name = name; 461 } 462 463 468 public void setPassword(String password) { 469 this.password = password; 470 } 471 472 478 public void setUpdatePassword(String updatePassword) { 479 this.updatePassword = updatePassword; 480 } 481 482 487 public void setConfirmPassword(String confirmPassword) { 488 this.confirmPassword = confirmPassword; 489 } 490 491 497 public void setUpdateConfirmPassword(String updateConfirmPassword) { 498 this.updateConfirmPassword = updateConfirmPassword; 499 } 500 501 506 public void setFirstName(String firstName) { 507 this.firstName = firstName; 508 } 509 510 515 public void setLastName(String lastName) { 516 this.lastName = lastName; 517 } 518 519 524 public void setAddress(String address) { 525 this.address = address; 526 } 527 528 533 public void setCity(String city) { 534 this.city = city; 535 } 536 537 542 public void setCountry(String country) { 543 this.country = country; 544 } 545 546 551 public void setPostalCode(String postalCode) { 552 this.postalCode = postalCode; 553 } 554 555 560 public void setProvince(String province) { 561 this.province = province; 562 } 563 564 569 public void setEmail(String email) { 570 this.email = email; 571 } 572 573 578 public void setPhoneNumber(String phoneNumber) { 579 this.phoneNumber = phoneNumber; 580 } 581 582 587 public void setWebsite(String website) { 588 this.website = website; 589 } 590 591 597 public void setRolesAssociations(List rolesAssociations) { 598 this.rolesAssociations = rolesAssociations; 599 600 roles = new ArrayList (); 601 freeRoles = new ArrayList (); 602 for (Iterator i = rolesAssociations.iterator(); i.hasNext();) { 603 UserRoleAssociation association = (UserRoleAssociation) i.next(); 604 Role role = association.getRole(); 605 607 if (!roles.contains(role)) { 608 roles.add(role); 609 } 610 if (association.getGroup() == null) { 611 if (!freeRoles.contains(role)) { 612 freeRoles.add(role); 613 } 614 } 615 } 616 } 617 618 621 622 624 629 public void addFreeRole(Role role) { 630 addRole(role, null); 631 } 632 633 642 public void addRole(Role role, Group group) { 643 UserRoleAssociation association = new UserRoleAssociation(this, role, group); 644 if ( !getRolesAssociations().contains(association) ) { 645 getRolesAssociations().add(association); 646 } 647 setRolesAssociations(getRolesAssociations()); 649 } 650 651 656 public void removeFreeRole(Role role) { 657 removeRole(role, null); 658 } 659 660 669 public void removeRole(Role role, Group group) { 670 UserRoleAssociation association = new UserRoleAssociation(this, role, group); 671 getRolesAssociations().remove(association); 672 setRolesAssociations(getRolesAssociations()); 674 } 675 676 682 public void removeRole(Role role) { 683 List newAssociations = new ArrayList (); 684 List oldAssociations = getRolesAssociations(); 685 for (int i = 0; i < oldAssociations.size(); i++) { 686 UserRoleAssociation association = (UserRoleAssociation) oldAssociations.get(i); 687 if (!association.getRole().equals(role)) { 688 newAssociations.add(association); 689 } 690 } 691 setRolesAssociations(newAssociations); 692 } 693 694 699 public void setVersion(Long version) { 700 this.version = version; 701 } 702 703 708 public void setEnabled(Boolean enabled) { 709 this.enabled = enabled; 710 } 711 712 public boolean equals(Object o) { 713 if ( this == o ) { 714 return true; 715 } 716 if ( !(o instanceof User) ) { 717 return false; 718 } 719 720 final User user = (User) o; 721 722 if ( address != null ? !address.equals(user.address) : user.address != null ) { 723 return false; 724 } 725 if ( city != null ? !city.equals(user.city) : user.city != null ) { 726 return false; 727 } 728 if ( country != null ? !country.equals(user.country) : user.country != null ) { 729 return false; 730 } 731 if ( email != null ? !email.equals(user.email) : user.email != null ) { 732 return false; 733 } 734 if ( firstName != null ? !firstName.equals(user.firstName) : user.firstName != null ) { 735 return false; 736 } 737 if ( lastName != null ? !lastName.equals(user.lastName) : user.lastName != null ) { 738 return false; 739 } 740 if ( password != null ? !password.equals(user.password) : user.password != null ) { 741 return false; 742 } 743 if ( phoneNumber != null ? !phoneNumber.equals(user.phoneNumber) : user.phoneNumber != null ) { 744 return false; 745 } 746 if ( postalCode != null ? !postalCode.equals(user.postalCode) : user.postalCode != null ) { 747 return false; 748 } 749 if ( province != null ? !province.equals(user.province) : user.province != null ) { 750 return false; 751 } 752 if ( website != null ? !website.equals(user.website) : user.website != null ) { 753 return false; 754 } 755 756 return true; 757 } 758 759 public int hashCode() { 760 int result; 761 result = (password != null ? password.hashCode() : 0); 762 result = 29 * result + (firstName != null ? firstName.hashCode() : 0); 763 result = 29 * result + (lastName != null ? lastName.hashCode() : 0); 764 result = 29 * result + (address != null ? address.hashCode() : 0); 765 result = 29 * result + (city != null ? city.hashCode() : 0); 766 result = 29 * result + (province != null ? province.hashCode() : 0); 767 result = 29 * result + (country != null ? country.hashCode() : 0); 768 result = 29 * result + (postalCode != null ? postalCode.hashCode() : 0); 769 result = 29 * result + (phoneNumber != null ? phoneNumber.hashCode() : 0); 770 result = 29 * result + (email != null ? email.hashCode() : 0); 771 result = 29 * result + (website != null ? website.hashCode() : 0); 772 return result; 773 } 774 775 } | Popular Tags |