1
2
3
4
5 package com.hack23.cia.model.application.impl.common;
6
7 import java.util.ArrayList;
8 import java.util.Date;
9 import java.util.List;
10
11 import javax.persistence.CascadeType;
12 import javax.persistence.Entity;
13 import javax.persistence.FetchType;
14 import javax.persistence.GeneratedValue;
15 import javax.persistence.GenerationType;
16 import javax.persistence.Id;
17 import javax.persistence.ManyToOne;
18 import javax.persistence.OneToMany;
19 import javax.persistence.Temporal;
20 import javax.persistence.TemporalType;
21 import javax.persistence.Version;
22
23 import org.hibernate.annotations.Cache;
24 import org.hibernate.annotations.CacheConcurrencyStrategy;
25
26 import com.hack23.cia.model.core.impl.BaseEntity;
27
28 /***
29 * The Class UserSession.
30 */
31 @Entity
32 @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
33 public class UserSession extends BaseEntity {
34
35 /*** The Constant serialVersionUID. */
36 private static final long serialVersionUID = -2831588433419103923L;
37
38 /*** The active. */
39 private boolean active;
40
41 /*** The client host. */
42 private String clientHost;
43
44 /*** The created at. */
45 private Date createdAt;
46
47 /*** The ended at. */
48 private Date endedAt;
49
50 /*** The events. */
51 private List<AbstractActionEvent> events = new ArrayList<AbstractActionEvent>();
52
53 /*** The id. */
54 private Long id;
55
56 /*** The language. */
57 private Language language;
58
59 /*** The portal. */
60 private Portal portal;
61
62 /*** The server host. */
63 private String serverHost;
64
65 /*** The session id. */
66 private String sessionId;
67
68 /*** The user. */
69 private User user;
70
71 /*** The user agent. */
72 private String userAgent;
73
74 /*** The version. */
75 private Long version=1L;
76
77 /***
78 * Instantiates a new user session.
79 */
80 public UserSession() {
81 }
82
83 /***
84 * Instantiates a new user session.
85 *
86 * @param user the user
87 * @param language the language
88 * @param portal the portal
89 * @param sessionId the session id
90 * @param clientHost the client host
91 * @param serverHost the server host
92 * @param createdAt the created at
93 * @param userAgent the user agent
94 */
95 public UserSession(final User user, final Language language, final Portal portal, final String sessionId, final String clientHost,final String serverHost, final Date createdAt, final String userAgent) {
96 this.user = user;
97 this.language = language;
98 this.portal = portal;
99 this.sessionId = sessionId;
100 this.clientHost = clientHost;
101 this.serverHost = serverHost;
102 this.createdAt = createdAt;
103 this.userAgent = userAgent;
104 this.active = true;
105 this.endedAt = null;
106 }
107
108 /***
109 * Gets the active.
110 *
111 * @return the active
112 */
113 public boolean getActive() {
114 return active;
115 }
116
117 /***
118 * Gets the client host.
119 *
120 * @return the client host
121 */
122 public String getClientHost() {
123 return clientHost;
124 }
125
126 /***
127 * Gets the created at.
128 *
129 * @return the created at
130 */
131 @Temporal(TemporalType.DATE)
132 public Date getCreatedAt() {
133 return createdAt;
134 }
135
136 /***
137 * Gets the ended at.
138 *
139 * @return the ended at
140 */
141 @Temporal(TemporalType.DATE)
142 public Date getEndedAt() {
143 return endedAt;
144 }
145
146 /***
147 * Gets the events.
148 *
149 * @return the events
150 */
151 @OneToMany(mappedBy = "userSession", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
152 @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
153 public List<AbstractActionEvent> getEvents() {
154 return events;
155 }
156
157 /***
158
159 /*
160 * (non-Javadoc)
161 *
162 * @see org.directdemocracyportal.democracy.model.core.BaseEntity#getId()
163 */
164 @Override
165 @Id
166 @GeneratedValue(strategy = GenerationType.AUTO)
167 public Long getId() {
168 return this.id;
169 }
170
171 /***
172 * Gets the language.
173 *
174 * @return the language
175 */
176 @ManyToOne
177 public Language getLanguage() {
178 return language;
179 }
180
181 /***
182 * Gets the portal.
183 *
184 * @return the portal
185 */
186 @ManyToOne
187 public Portal getPortal() {
188 return portal;
189 }
190
191 /***
192 * Gets the server host.
193 *
194 * @return the server host
195 */
196 public String getServerHost() {
197 return serverHost;
198 }
199
200 /***
201 * Gets the session id.
202 *
203 * @return the session id
204 */
205 public String getSessionId() {
206 return sessionId;
207 }
208
209 /***
210 * Gets the user.
211 *
212 * @return the user
213 */
214 @ManyToOne(cascade = CascadeType.ALL)
215 public User getUser() {
216 return user;
217 }
218
219 /***
220 * Gets the user agent.
221 *
222 * @return the user agent
223 */
224 public String getUserAgent() {
225 return userAgent;
226 }
227
228
229
230
231 @Override
232 @Version
233 public Long getVersion() {
234 return version;
235 }
236
237 /***
238 * Sets the active.
239 *
240 * @param active the new active
241 */
242 public void setActive(final boolean active) {
243 this.active = active;
244 }
245
246
247 /***
248 * Sets the client host.
249 *
250 * @param clientHost the new client host
251 */
252 public void setClientHost(final String clientHost) {
253 this.clientHost = clientHost;
254 }
255
256 /***
257 * Sets the created at.
258 *
259 * @param createdAt the new created at
260 */
261 public void setCreatedAt(final Date createdAt) {
262 this.createdAt = createdAt;
263 }
264
265 /***
266 * Sets the ended at.
267 *
268 * @param endedAt the new ended at
269 */
270 public void setEndedAt(final Date endedAt) {
271 this.endedAt = endedAt;
272 }
273
274 /***
275 * Sets the events.
276 *
277 * @param events the new events
278 */
279 public void setEvents(final List<AbstractActionEvent> events) {
280 this.events = events;
281 }
282
283 /***
284 * Sets the id.
285 *
286 * @param id the new id
287 */
288 public void setId(final Long id) {
289 this.id = id;
290 }
291
292 /***
293 * Sets the language.
294 *
295 * @param language the new language
296 */
297 public void setLanguage(final Language language) {
298 this.language = language;
299 }
300
301 /***
302 * Sets the portal.
303 *
304 * @param portal the new portal
305 */
306 public void setPortal(final Portal portal) {
307 this.portal = portal;
308 }
309
310 /***
311 * Sets the server host.
312 *
313 * @param serverHost the new server host
314 */
315 public void setServerHost(final String serverHost) {
316 this.serverHost = serverHost;
317 }
318
319 /***
320 * Sets the session id.
321 *
322 * @param sessionId the new session id
323 */
324 public void setSessionId(final String sessionId) {
325 this.sessionId = sessionId;
326 }
327
328 /***
329 * Sets the user.
330 *
331 * @param user the new user
332 */
333 public void setUser(final User user) {
334 this.user = user;
335 }
336
337 /***
338 * Sets the user agent.
339 *
340 * @param userAgent the new user agent
341 */
342 public void setUserAgent(final String userAgent) {
343 this.userAgent = userAgent;
344 }
345
346 /***
347 * Sets the version.
348 *
349 * @param version the new version
350 */
351 public void setVersion(final Long version) {
352 this.version = version;
353 }
354 }