UserDTO.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. package rocks.zipcode.io.service.dto;
  2. import rocks.zipcode.io.config.Constants;
  3. import rocks.zipcode.io.domain.Authority;
  4. import rocks.zipcode.io.domain.User;
  5. import javax.validation.constraints.Email;
  6. import javax.validation.constraints.NotBlank;
  7. import javax.validation.constraints.*;
  8. import java.time.Instant;
  9. import java.util.Set;
  10. import java.util.stream.Collectors;
  11. /**
  12. * A DTO representing a user, with his authorities.
  13. */
  14. public class UserDTO {
  15. private Long id;
  16. @NotBlank
  17. @Pattern(regexp = Constants.LOGIN_REGEX)
  18. @Size(min = 1, max = 50)
  19. private String login;
  20. @Size(max = 50)
  21. private String firstName;
  22. @Size(max = 50)
  23. private String lastName;
  24. @Email
  25. @Size(min = 5, max = 254)
  26. private String email;
  27. @Size(max = 256)
  28. private String imageUrl;
  29. private boolean activated = false;
  30. @Size(min = 2, max = 6)
  31. private String langKey;
  32. private String createdBy;
  33. private Instant createdDate;
  34. private String lastModifiedBy;
  35. private Instant lastModifiedDate;
  36. private Set<String> authorities;
  37. public UserDTO() {
  38. // Empty constructor needed for Jackson.
  39. }
  40. public UserDTO(User user) {
  41. this.id = user.getId();
  42. this.login = user.getLogin();
  43. this.firstName = user.getFirstName();
  44. this.lastName = user.getLastName();
  45. this.email = user.getEmail();
  46. this.activated = user.getActivated();
  47. this.imageUrl = user.getImageUrl();
  48. this.langKey = user.getLangKey();
  49. this.createdBy = user.getCreatedBy();
  50. this.createdDate = user.getCreatedDate();
  51. this.lastModifiedBy = user.getLastModifiedBy();
  52. this.lastModifiedDate = user.getLastModifiedDate();
  53. this.authorities = user.getAuthorities().stream()
  54. .map(Authority::getName)
  55. .collect(Collectors.toSet());
  56. }
  57. public Long getId() {
  58. return id;
  59. }
  60. public void setId(Long id) {
  61. this.id = id;
  62. }
  63. public String getLogin() {
  64. return login;
  65. }
  66. public void setLogin(String login) {
  67. this.login = login;
  68. }
  69. public String getFirstName() {
  70. return firstName;
  71. }
  72. public void setFirstName(String firstName) {
  73. this.firstName = firstName;
  74. }
  75. public String getLastName() {
  76. return lastName;
  77. }
  78. public void setLastName(String lastName) {
  79. this.lastName = lastName;
  80. }
  81. public String getEmail() {
  82. return email;
  83. }
  84. public void setEmail(String email) {
  85. this.email = email;
  86. }
  87. public String getImageUrl() {
  88. return imageUrl;
  89. }
  90. public void setImageUrl(String imageUrl) {
  91. this.imageUrl = imageUrl;
  92. }
  93. public boolean isActivated() {
  94. return activated;
  95. }
  96. public void setActivated(boolean activated) {
  97. this.activated = activated;
  98. }
  99. public String getLangKey() {
  100. return langKey;
  101. }
  102. public void setLangKey(String langKey) {
  103. this.langKey = langKey;
  104. }
  105. public String getCreatedBy() {
  106. return createdBy;
  107. }
  108. public void setCreatedBy(String createdBy) {
  109. this.createdBy = createdBy;
  110. }
  111. public Instant getCreatedDate() {
  112. return createdDate;
  113. }
  114. public void setCreatedDate(Instant createdDate) {
  115. this.createdDate = createdDate;
  116. }
  117. public String getLastModifiedBy() {
  118. return lastModifiedBy;
  119. }
  120. public void setLastModifiedBy(String lastModifiedBy) {
  121. this.lastModifiedBy = lastModifiedBy;
  122. }
  123. public Instant getLastModifiedDate() {
  124. return lastModifiedDate;
  125. }
  126. public void setLastModifiedDate(Instant lastModifiedDate) {
  127. this.lastModifiedDate = lastModifiedDate;
  128. }
  129. public Set<String> getAuthorities() {
  130. return authorities;
  131. }
  132. public void setAuthorities(Set<String> authorities) {
  133. this.authorities = authorities;
  134. }
  135. @Override
  136. public String toString() {
  137. return "UserDTO{" +
  138. "login='" + login + '\'' +
  139. ", firstName='" + firstName + '\'' +
  140. ", lastName='" + lastName + '\'' +
  141. ", email='" + email + '\'' +
  142. ", imageUrl='" + imageUrl + '\'' +
  143. ", activated=" + activated +
  144. ", langKey='" + langKey + '\'' +
  145. ", createdBy=" + createdBy +
  146. ", createdDate=" + createdDate +
  147. ", lastModifiedBy='" + lastModifiedBy + '\'' +
  148. ", lastModifiedDate=" + lastModifiedDate +
  149. ", authorities=" + authorities +
  150. "}";
  151. }
  152. }