Salome HOME
Update copyrights 2014.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / dto / UserDTO.java
1 package org.splat.service.dto;
2
3 import java.security.Principal;
4
5 import org.splat.kernel.Name;
6
7 /**
8  * User DTO.
9  * 
10  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
11  */
12 public class UserDTO implements Principal, Name {
13
14         /**
15          * User password.
16          */
17         private String _password;
18         /**
19          * User login name. Unique in the user directory.
20          */
21         private String _username;
22         /**
23          * User first name.
24          */
25         private String _firstName;
26         /**
27          * User family.
28          */
29         private String _name;
30         /**
31          * User name to be displayed. Optional.
32          */
33         private String _displayName;
34         /**
35          * Roles as list (as stored in the database).
36          */
37         private RoleDTO _role = new RoleDTO();
38         /**
39          * Email address.
40          */
41         private String _mailAddress;
42         /**
43          * Organization name.
44          */
45         private String _organizationName;
46
47         /**
48          * Persistent id of the type.
49          */
50         private long _index;
51
52         // ==============================================================================================================================
53         // Public member functions
54         // ==============================================================================================================================
55
56         /**
57          * {@inheritDoc}
58          * 
59          * @see java.lang.Object#equals(java.lang.Object)
60          */
61         @Override
62         public boolean equals(final Object item) {
63                 boolean res = (item != null);
64                 if (res) {
65                         if (item instanceof String) {
66                                 res = this._username.equals(item); // Usernames are unique
67                         } else if (item instanceof UserDTO) {
68                                 UserDTO given = (UserDTO) item;
69                                 res = given._username.equals(this._username); // Usernames are unique
70                         }
71                 }
72                 return res;
73         }
74
75         /**
76          * Get user display name.
77          * 
78          * @return the user display name
79          */
80         public String getDisplayName() {
81                 String res = _displayName;
82                 if (res == null) {
83                         res = _name + " " + _firstName;
84                 }
85                 return res;
86         }
87
88         /**
89          * Get user first name.
90          * 
91          * @return the user first name
92          */
93         public String getFirstName() {
94                 return _firstName;
95         }
96
97         /**
98          * Set user first name.
99          * 
100          * @param name
101          *            the first name to set
102          */
103         public void setFirstName(final String name) {
104                 _firstName = name;
105         }
106
107         /**
108          * Get user email address.
109          * 
110          * @return the email address
111          */
112         public String getMailAddress() {
113                 return _mailAddress;
114         }
115
116         /**
117          * Set user email address.
118          * 
119          * @param addr
120          *            the email address to set
121          */
122         public void setMailAddress(final String addr) {
123                 _mailAddress = addr;
124         }
125
126         /**
127          * {@inheritDoc}
128          * 
129          * @see java.security.Principal#getName()
130          */
131         public String getName() {
132                 return _name;
133         }
134
135         /**
136          * Set user family.
137          * 
138          * @param name
139          *            the user family to set
140          */
141         public void setName(final String name) {
142                 _name = name;
143         }
144
145         /**
146          * Get user's organization name.
147          * 
148          * @return the user's organization name
149          */
150         public String getOrganizationName() {
151                 return _organizationName;
152         }
153
154         /**
155          * Set user's organization name.
156          * 
157          * @param name
158          *            the user's organization name
159          */
160         public void setOrganizationName(final String name) {
161                 _organizationName = name;
162         }
163
164         /**
165          * Get user roles names separated by commas.
166          * 
167          * @return the string containing roles names
168          */
169         public String getRoleNames() {
170                 return _role.getName();
171         }
172
173         /**
174          * Get users roles as an array of DTO.
175          * 
176          * @return the array of roles DTO
177          */
178         public RoleDTO[] getRoles() {
179                 return _role.toArray();
180         }
181
182         /**
183          * Get user login name.
184          * @return the user login name
185          */
186         public String getUsername() {
187                 return _username;
188         }
189
190         /** 
191          * {@inheritDoc}
192          * @see java.lang.Object#toString()
193          */
194         @Override
195         public String toString() {
196                 return _name + " " + _firstName;
197         }
198
199         /**
200          * Get the rid.
201          * 
202          * @return the rid
203          */
204         public long getIndex() {
205                 return _index;
206         }
207
208         /**
209          * Set the rid.
210          * 
211          * @param rid
212          *            the rid to set
213          */
214         public void setIndex(final long rid) {
215                 this._index = rid;
216         }
217
218         /**
219          * Get the password.
220          * 
221          * @return the password
222          */
223         public String getPassword() {
224                 return _password;
225         }
226
227         /**
228          * Set the password.
229          * 
230          * @param password
231          *            the password to set
232          */
233         public void setPassword(final String password) {
234                 this._password = password;
235         }
236
237         /**
238          * Set the username.
239          * 
240          * @param username
241          *            the username to set
242          */
243         public void setUsername(final String username) {
244                 this._username = username;
245         }
246
247         /**
248          * Get the role.
249          * 
250          * @return the role
251          */
252         public RoleDTO getRole() {
253                 return _role;
254         }
255
256         /**
257          * Set the role.
258          * 
259          * @param role
260          *            the role to set
261          */
262         public void setRole(final RoleDTO role) {
263                 this._role = role;
264         }
265
266         /**
267          * Set the displayName.
268          * 
269          * @param displayName
270          *            the displayName to set
271          */
272         public void setDisplayName(final String displayName) {
273                 _displayName = displayName;
274         }
275 }