2 * In Samsung Ukraine R&D Center (SRK under a contract between)
3 * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
6 package com.samsung.samserver.service.dto;
10 import com.samsung.samserver.config.Constants;
11 import com.samsung.samserver.domain.Authority;
12 import com.samsung.samserver.domain.User;
13 import org.hibernate.validator.constraints.Email;
14 import org.hibernate.validator.constraints.NotBlank;
16 import javax.validation.constraints.*;
17 import java.time.Instant;
19 import java.util.stream.Collectors;
22 * A DTO representing a user, with his authorities.
24 public class UserDTO {
29 @Pattern(regexp = Constants.LOGIN_REGEX)
30 @Size(min = 1, max = 50)
34 private String firstName;
37 private String lastName;
40 @Size(min = 5, max = 100)
44 private String imageUrl;
46 private boolean activated = false;
48 @Size(min = 2, max = 6)
49 private String langKey;
51 private String createdBy;
53 private Instant createdDate;
55 private String lastModifiedBy;
57 private Instant lastModifiedDate;
59 private Set<String> authorities;
62 // Empty constructor needed for Jackson.
65 public UserDTO(User user) {
66 this.id = user.getId();
67 this.login = user.getLogin();
68 this.firstName = user.getFirstName();
69 this.lastName = user.getLastName();
70 this.email = user.getEmail();
71 this.activated = user.getActivated();
72 this.imageUrl = user.getImageUrl();
73 this.langKey = user.getLangKey();
74 this.authorities = user.getAuthorities().stream()
75 .map(Authority::getName)
76 .collect(Collectors.toSet());
83 public void setId(Long id) {
87 public String getLogin() {
91 public void setLogin(String login) {
95 public String getFirstName() {
99 public void setFirstName(String firstName) {
100 this.firstName = firstName;
103 public String getLastName() {
107 public void setLastName(String lastName) {
108 this.lastName = lastName;
111 public String getEmail() {
115 public void setEmail(String email) {
119 public String getImageUrl() {
123 public void setImageUrl(String imageUrl) {
124 this.imageUrl = imageUrl;
127 public boolean isActivated() {
131 public void setActivated(boolean activated) {
132 this.activated = activated;
135 public String getLangKey() {
139 public void setLangKey(String langKey) {
140 this.langKey = langKey;
143 public String getCreatedBy() {
147 public void setCreatedBy(String createdBy) {
148 this.createdBy = createdBy;
151 public Instant getCreatedDate() {
155 public void setCreatedDate(Instant createdDate) {
156 this.createdDate = createdDate;
159 public String getLastModifiedBy() {
160 return lastModifiedBy;
163 public void setLastModifiedBy(String lastModifiedBy) {
164 this.lastModifiedBy = lastModifiedBy;
167 public Instant getLastModifiedDate() {
168 return lastModifiedDate;
171 public void setLastModifiedDate(Instant lastModifiedDate) {
172 this.lastModifiedDate = lastModifiedDate;
175 public Set<String> getAuthorities() {
179 public void setAuthorities(Set<String> authorities) {
180 this.authorities = authorities;
184 public String toString() {
186 "login='" + login + '\'' +
187 ", firstName='" + firstName + '\'' +
188 ", lastName='" + lastName + '\'' +
189 ", email='" + email + '\'' +
190 ", imageUrl='" + imageUrl + '\'' +
191 ", activated=" + activated +
192 ", langKey='" + langKey + '\'' +
193 ", createdBy=" + createdBy +
194 ", createdDate=" + createdDate +
195 ", lastModifiedBy='" + lastModifiedBy + '\'' +
196 ", lastModifiedDate=" + lastModifiedDate +
197 ", authorities=" + authorities +