[SECARSP-111] +Auth API [SECARSP-115 +Get Devices]
[platform/core/security/suspicious-activity-monitor.git] / server / src / main / java / com / samsung / samserver / service / dto / UserDTO.java
1 /*
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.
5  */
6 package com.samsung.samserver.service.dto;
7
8
9
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;
15
16 import javax.validation.constraints.*;
17 import java.time.Instant;
18 import java.util.Set;
19 import java.util.stream.Collectors;
20
21 /**
22  * A DTO representing a user, with his authorities.
23  */
24 public class UserDTO {
25
26     private Long id;
27
28     @NotBlank
29     @Pattern(regexp = Constants.LOGIN_REGEX)
30     @Size(min = 1, max = 50)
31     private String login;
32
33     @Size(max = 50)
34     private String firstName;
35
36     @Size(max = 50)
37     private String lastName;
38
39     @Email
40     @Size(min = 5, max = 100)
41     private String email;
42
43     @Size(max = 256)
44     private String imageUrl;
45
46     private boolean activated = false;
47
48     @Size(min = 2, max = 6)
49     private String langKey;
50
51     private String createdBy;
52
53     private Instant createdDate;
54
55     private String lastModifiedBy;
56
57     private Instant lastModifiedDate;
58
59     private Set<String> authorities;
60
61     public UserDTO() {
62         // Empty constructor needed for Jackson.
63     }
64
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());
77     }
78
79     public Long getId() {
80         return id;
81     }
82
83     public void setId(Long id) {
84         this.id = id;
85     }
86
87     public String getLogin() {
88         return login;
89     }
90
91     public void setLogin(String login) {
92         this.login = login;
93     }
94
95     public String getFirstName() {
96         return firstName;
97     }
98
99     public void setFirstName(String firstName) {
100         this.firstName = firstName;
101     }
102
103     public String getLastName() {
104         return lastName;
105     }
106
107     public void setLastName(String lastName) {
108         this.lastName = lastName;
109     }
110
111     public String getEmail() {
112         return email;
113     }
114
115     public void setEmail(String email) {
116         this.email = email;
117     }
118
119     public String getImageUrl() {
120         return imageUrl;
121     }
122
123     public void setImageUrl(String imageUrl) {
124         this.imageUrl = imageUrl;
125     }
126
127     public boolean isActivated() {
128         return activated;
129     }
130
131     public void setActivated(boolean activated) {
132         this.activated = activated;
133     }
134
135     public String getLangKey() {
136         return langKey;
137     }
138
139     public void setLangKey(String langKey) {
140         this.langKey = langKey;
141     }
142
143     public String getCreatedBy() {
144         return createdBy;
145     }
146
147     public void setCreatedBy(String createdBy) {
148         this.createdBy = createdBy;
149     }
150
151     public Instant getCreatedDate() {
152         return createdDate;
153     }
154
155     public void setCreatedDate(Instant createdDate) {
156         this.createdDate = createdDate;
157     }
158
159     public String getLastModifiedBy() {
160         return lastModifiedBy;
161     }
162
163     public void setLastModifiedBy(String lastModifiedBy) {
164         this.lastModifiedBy = lastModifiedBy;
165     }
166
167     public Instant getLastModifiedDate() {
168         return lastModifiedDate;
169     }
170
171     public void setLastModifiedDate(Instant lastModifiedDate) {
172         this.lastModifiedDate = lastModifiedDate;
173     }
174
175     public Set<String> getAuthorities() {
176         return authorities;
177     }
178
179     public void setAuthorities(Set<String> authorities) {
180         this.authorities = authorities;
181     }
182
183     @Override
184     public String toString() {
185         return "UserDTO{" +
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 +
198             "}";
199     }
200 }