/spindles-api/src/spindles/api/domain/User.java

http://spindles.googlecode.com/ · Java · 115 lines · 77 code · 35 blank · 3 comment · 0 complexity · fad8b0e0b8ec3a1898c7c2ff6a8e7c7d MD5 · raw file

  1. package spindles.api.domain;
  2. import static com.sleepycat.persist.model.Relationship.ONE_TO_ONE;
  3. import org.apache.commons.lang.Validate;
  4. import spindles.api.util.Util;
  5. import com.sleepycat.persist.model.Entity;
  6. import com.sleepycat.persist.model.SecondaryKey;
  7. @Entity
  8. public class User extends DomainObject {
  9. /**
  10. *
  11. */
  12. private static transient final long serialVersionUID = -906027125431996690L;
  13. private static final User DEFAULT =
  14. new User("admin", "admin", Role.ADMIN, "Default user.");
  15. public static final String DEFAULT_USERNAME = "admin";
  16. private String firstName;
  17. private String lastName;
  18. @SecondaryKey(relate=ONE_TO_ONE)
  19. private String userName;
  20. private String password;
  21. private String email;
  22. private String comments;
  23. private Role role;
  24. public User(String username, String password, Role role, String comments){
  25. setUserName(username);
  26. setPassword(password);
  27. setRole(role);
  28. setComments(comments);
  29. }
  30. private User(){};
  31. public static User getDefaultUser(){
  32. return DEFAULT;
  33. }
  34. public User(String username, String password, Role role){
  35. this(username, password, role, "");
  36. }
  37. public String getComments() {
  38. return comments;
  39. }
  40. public void setComments(String comments) {
  41. this.comments = comments;
  42. }
  43. public String getEmail() {
  44. return email;
  45. }
  46. public void setEmail(String email) {
  47. this.email = email;
  48. }
  49. public String getFirstName() {
  50. return firstName;
  51. }
  52. public void setFirstName(String firstName) {
  53. this.firstName = firstName;
  54. }
  55. public String getLastName() {
  56. return lastName;
  57. }
  58. public void setLastName(String lastName) {
  59. this.lastName = lastName;
  60. }
  61. public String getPassword() {
  62. return password;
  63. }
  64. public void setPassword(String password) {
  65. this.password = password;
  66. }
  67. public String getUserName() {
  68. return userName;
  69. }
  70. public void setUserName(String userName) {
  71. Validate.isTrue(!Util.isEmpty(userName), "Username cannot by empty");
  72. this.userName = userName;
  73. }
  74. public Role getRole() {
  75. return role;
  76. }
  77. public void setRole(Role role) {
  78. this.role = role;
  79. }
  80. }