1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.mobility.user.entity; |
17 | |
|
18 | |
import java.io.Serializable; |
19 | |
import java.sql.Timestamp; |
20 | |
import java.util.ArrayList; |
21 | |
import java.util.Collections; |
22 | |
import java.util.HashMap; |
23 | |
import java.util.List; |
24 | |
import java.util.Map; |
25 | |
|
26 | |
import javax.persistence.Column; |
27 | |
import javax.persistence.Entity; |
28 | |
import javax.persistence.GeneratedValue; |
29 | |
import javax.persistence.GenerationType; |
30 | |
import javax.persistence.Id; |
31 | |
import javax.persistence.Table; |
32 | |
import javax.persistence.Transient; |
33 | |
import javax.persistence.Version; |
34 | |
|
35 | |
@Entity(name = "User") |
36 | |
@Table(name = "KME_USR_T") |
37 | |
public class UserImpl implements User, Serializable { |
38 | |
|
39 | |
private static final long serialVersionUID = -2720266083487368287L; |
40 | |
|
41 | |
@Id |
42 | |
@GeneratedValue(strategy = GenerationType.TABLE) |
43 | |
@Column(name = "ID") |
44 | |
private Long principalId; |
45 | |
|
46 | |
@Column(name = "PRNCPL_NM") |
47 | |
private String principalName; |
48 | |
|
49 | |
@Column(name = "FRST_LGN_DT") |
50 | |
private Timestamp firstLogin; |
51 | |
|
52 | |
@Column(name = "LST_LGN_DT") |
53 | |
private Timestamp lastLogin; |
54 | |
|
55 | |
@Column(name = "DEV_ID") |
56 | |
private String deviceId; |
57 | |
|
58 | |
@Version |
59 | |
@Column(name = "VER_NBR") |
60 | |
protected Long versionNumber; |
61 | |
|
62 | |
@Transient |
63 | |
private Map<String, String> userAttributes; |
64 | |
|
65 | |
@Transient |
66 | |
private String primaryCampus; |
67 | |
|
68 | |
@Transient |
69 | |
private String email; |
70 | |
|
71 | |
@Transient |
72 | |
private List<String> groups; |
73 | |
|
74 | |
@Transient |
75 | |
private List<String> affiliations; |
76 | |
|
77 | |
@Transient |
78 | |
private String viewCampus; |
79 | |
|
80 | |
@Transient |
81 | |
private boolean publicUser; |
82 | |
|
83 | 0 | @Transient |
84 | |
private final UserCache cache = new UserCache(); |
85 | |
|
86 | |
@Transient |
87 | |
private String ipAddress; |
88 | |
|
89 | 0 | public UserImpl() { |
90 | 0 | publicUser = false; |
91 | 0 | userAttributes = new HashMap<String, String>(); |
92 | 0 | groups = new ArrayList<String>(); |
93 | 0 | affiliations = new ArrayList<String>(); |
94 | 0 | } |
95 | |
|
96 | 0 | public UserImpl(boolean publicUser) { |
97 | 0 | if (publicUser) { |
98 | 0 | principalId = -1L; |
99 | |
} |
100 | 0 | userAttributes = new HashMap<String, String>(); |
101 | 0 | groups = new ArrayList<String>(); |
102 | 0 | affiliations = new ArrayList<String>(); |
103 | 0 | this.publicUser = publicUser; |
104 | 0 | } |
105 | |
|
106 | |
public boolean isPublicUser() { |
107 | 0 | return publicUser; |
108 | |
} |
109 | |
|
110 | |
public void setPublicUser(boolean publicUser) { |
111 | 0 | this.publicUser = publicUser; |
112 | 0 | } |
113 | |
|
114 | |
public String getViewCampus() { |
115 | 0 | return viewCampus; |
116 | |
} |
117 | |
|
118 | |
public void setViewCampus(String viewCampus) { |
119 | 0 | this.viewCampus = viewCampus; |
120 | 0 | } |
121 | |
|
122 | |
public Long getPrincipalId() { |
123 | 0 | return principalId; |
124 | |
} |
125 | |
|
126 | |
public void setPrincipalId(Long principalId) { |
127 | 0 | this.principalId = principalId; |
128 | 0 | } |
129 | |
|
130 | |
public String getPrincipalName() { |
131 | 0 | return principalName; |
132 | |
} |
133 | |
|
134 | |
public void setPrincipalName(String principalName) { |
135 | 0 | this.principalName = principalName; |
136 | 0 | } |
137 | |
|
138 | |
public Timestamp getFirstLogin() { |
139 | 0 | return firstLogin; |
140 | |
} |
141 | |
|
142 | |
public void setFirstLogin(Timestamp firstLogin) { |
143 | 0 | this.firstLogin = firstLogin; |
144 | 0 | } |
145 | |
|
146 | |
public Timestamp getLastLogin() { |
147 | 0 | return lastLogin; |
148 | |
} |
149 | |
|
150 | |
public void setLastLogin(Timestamp lastLogin) { |
151 | 0 | this.lastLogin = lastLogin; |
152 | 0 | } |
153 | |
|
154 | |
public Long getVersionNumber() { |
155 | 0 | return versionNumber; |
156 | |
} |
157 | |
|
158 | |
public void setVersionNumber(Long versionNumber) { |
159 | 0 | this.versionNumber = versionNumber; |
160 | 0 | } |
161 | |
|
162 | |
public String getDeviceId() { |
163 | 0 | return deviceId; |
164 | |
} |
165 | |
|
166 | |
public void setDeviceId(String deviceId) { |
167 | 0 | this.deviceId = deviceId; |
168 | 0 | } |
169 | |
|
170 | |
@Override |
171 | |
public Map<String, String> getUserAttributes() { |
172 | 0 | return userAttributes; |
173 | |
} |
174 | |
|
175 | |
@Override |
176 | |
public void setUserAttributes(Map<String, String> userAttributes) { |
177 | 0 | this.userAttributes = userAttributes; |
178 | 0 | } |
179 | |
|
180 | |
@Override |
181 | |
public String getUserAttribute(String key) { |
182 | 0 | return userAttributes.get(key); |
183 | |
} |
184 | |
|
185 | |
@Override |
186 | |
public void setUserAttribute(String key, String value) { |
187 | 0 | userAttributes.put(key, value); |
188 | 0 | } |
189 | |
|
190 | |
@Override |
191 | |
public void removeUserAttribute(String key) { |
192 | 0 | userAttributes.remove(key); |
193 | 0 | } |
194 | |
|
195 | |
@Override |
196 | |
public String getPrimaryCampus() { |
197 | 0 | return primaryCampus; |
198 | |
} |
199 | |
|
200 | |
@Override |
201 | |
public void setPrimaryCampus(String primaryCampus) { |
202 | 0 | this.primaryCampus = primaryCampus; |
203 | 0 | } |
204 | |
|
205 | |
@Override |
206 | |
public List<String> getGroups() { |
207 | 0 | return Collections.unmodifiableList(groups); |
208 | |
} |
209 | |
|
210 | |
@Override |
211 | |
public List<String> getAffiliations() { |
212 | 0 | return Collections.unmodifiableList(affiliations); |
213 | |
} |
214 | |
|
215 | |
@Override |
216 | |
public boolean isMember(String groupName) { |
217 | 0 | return groups.contains(groupName); |
218 | |
} |
219 | |
|
220 | |
@Override |
221 | |
public boolean isStudent() { |
222 | 0 | return affiliations.contains("Enrolled"); |
223 | |
} |
224 | |
|
225 | |
@Override |
226 | |
public boolean isFaculty() { |
227 | 0 | return affiliations.contains("Faculty"); |
228 | |
} |
229 | |
|
230 | |
@Override |
231 | |
public boolean isStaff() { |
232 | 0 | return affiliations.contains("Staff"); |
233 | |
} |
234 | |
|
235 | |
@Override |
236 | |
public boolean isAlumnus() { |
237 | 0 | return affiliations.contains("Alumni"); |
238 | |
} |
239 | |
|
240 | |
@Override |
241 | |
public void setGroups(List<String> groups) { |
242 | 0 | this.groups = groups; |
243 | 0 | } |
244 | |
|
245 | |
@Override |
246 | |
public void setAffiliations(List<String> affiliations) { |
247 | 0 | this.affiliations = affiliations; |
248 | 0 | } |
249 | |
|
250 | |
@Override |
251 | |
public String getEmail() { |
252 | 0 | return email; |
253 | |
} |
254 | |
|
255 | |
@Override |
256 | |
public void setEmail(String email) { |
257 | 0 | this.email = email; |
258 | 0 | } |
259 | |
|
260 | |
@Override |
261 | |
public String getIpAddress() { |
262 | 0 | return ipAddress; |
263 | |
} |
264 | |
|
265 | |
@Override |
266 | |
public void setIpAddress(String ipAddress) { |
267 | 0 | this.ipAddress = ipAddress; |
268 | 0 | } |
269 | |
|
270 | |
@Override |
271 | |
public UserCacheObject getFromCache(String key) { |
272 | 0 | return cache.get(key); |
273 | |
} |
274 | |
|
275 | |
@Override |
276 | |
public void putInCache(String key, Object item) { |
277 | 0 | cache.put(key, item); |
278 | 0 | } |
279 | |
|
280 | |
@Override |
281 | |
public void removeFromCache(String key) { |
282 | 0 | cache.remove(key); |
283 | 0 | } |
284 | |
|
285 | |
} |