1 /*
2 * Copyright (c) 2002-2014, Mairie de Paris
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice
10 * and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice
13 * and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 * License 1.0
33 */
34 package fr.paris.lutece.plugins.crm.business.user;
35
36 import org.apache.commons.lang3.StringUtils;
37
38 import java.sql.Timestamp;
39
40 import java.util.Map;
41
42 /**
43 *
44 * CRMUser
45 *
46 */
47 public class CRMUser
48 {
49 public static final Timestamp DEFAULT_DATE_LAST_LOGIN = Timestamp.valueOf( "1980-01-01 00:00:00" );
50
51 /**
52 * Status of not activated users.
53 */
54 public static final int STATUS_NOT_ACTIVATED = 0;
55
56 /**
57 * Status of activated users.
58 */
59 public static final int STATUS_ACTIVATED = 1;
60
61 /**
62 * Status of expired users. Expired users will be anonymized.
63 */
64 public static final int STATUS_EXPIRED = 5;
65
66 /**
67 * Status of anonymized users.
68 */
69 public static final int STATUS_ANONYMIZED = 10;
70 private int _nIdCRMUser;
71 private String _strUserGuid;
72 private Map<String, String> _userInfos;
73 private int _nStatus;
74 private Timestamp _dateLastLogin;
75 private boolean _bMustBeUpdated;
76
77 /**
78 * Set the id crm user
79 *
80 * @param nIdCRMUser
81 * the id crm user
82 */
83 public void setIdCRMUser( int nIdCRMUser )
84 {
85 _nIdCRMUser = nIdCRMUser;
86 }
87
88 /**
89 * Get the id crm user
90 *
91 * @return the id crm user
92 */
93 public int getIdCRMUser( )
94 {
95 return _nIdCRMUser;
96 }
97
98 /**
99 * Set the user guid
100 *
101 * @param strUserGuid
102 * the user guid
103 */
104 public void setUserGuid( String strUserGuid )
105 {
106 _strUserGuid = strUserGuid;
107 }
108
109 /**
110 * Get the user guid
111 *
112 * @return the user guid
113 */
114 public String getUserGuid( )
115 {
116 return _strUserGuid;
117 }
118
119 /**
120 * Set the user attributes
121 *
122 * @param userInfos
123 * the user attributes
124 */
125 public void setUserAttributes( Map<String, String> userInfos )
126 {
127 _userInfos = userInfos;
128 }
129
130 /**
131 * Get the user attributes
132 *
133 * @return the user attributes
134 */
135 public Map<String, String> getUserAttributes( )
136 {
137 return _userInfos;
138 }
139
140 /**
141 * Get the user attribute value
142 *
143 * @param strUserAttributeKey
144 * the key
145 * @return the user attribute value
146 */
147 public String getUserAttributeValue( String strUserAttributeKey )
148 {
149 String strUserInfoValue = StringUtils.EMPTY;
150
151 if ( _userInfos != null )
152 {
153 strUserInfoValue = _userInfos.get( strUserAttributeKey );
154 }
155
156 return StringUtils.isNotBlank( strUserInfoValue ) ? strUserInfoValue : StringUtils.EMPTY;
157 }
158
159 /**
160 * Get the status of the user
161 *
162 * @return The status of the user
163 */
164 public int getStatus( )
165 {
166 return _nStatus;
167 }
168
169 /**
170 * Set the status of the user
171 *
172 * @param nStatus
173 * The status of the user
174 */
175 public void setStatus( int nStatus )
176 {
177 _nStatus = nStatus;
178 }
179
180 /**
181 * Check if the user is active
182 *
183 * @return true if it is active, false otherwise
184 */
185 public boolean isActive( )
186 {
187 return ( ( _nStatus >= STATUS_ACTIVATED ) && ( _nStatus < STATUS_EXPIRED ) );
188 }
189
190 /**
191 * Checks if is anonymized.
192 *
193 * @return true, if is anonymized
194 */
195 public boolean isAnonymized( )
196 {
197 return _nStatus == STATUS_ANONYMIZED;
198 }
199
200 /**
201 * Get the last login date of the user
202 *
203 * @return The last login date of the user. The last login date is null if the user never logged in before.
204 */
205 public Timestamp getDateLastLogin( )
206 {
207 return _dateLastLogin;
208 }
209
210 /**
211 * Set the last login date of the user
212 *
213 * @param dateLastLogin
214 * The last login date of the user, or null if the user never logged in.
215 */
216 public void setDateLastLogin( Timestamp dateLastLogin )
217 {
218 this._dateLastLogin = dateLastLogin;
219 }
220
221 /**
222 *
223 * @return true if the user information must be updated
224 */
225 public boolean isMustBeUpdated( )
226 {
227 return _bMustBeUpdated;
228 }
229
230 /**
231 *
232 * @param _bMustBeUpdated
233 * true if the user information must be updated
234 */
235 public void setMustBeUpdated( boolean _bMustBeUpdated )
236 {
237 this._bMustBeUpdated = _bMustBeUpdated;
238 }
239 }