Rev 16 | Rev 31 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
11 | dev | 1 | package ak.kickup.core.model; |
3 | dev | 2 | |
3 | import java.math.BigDecimal; |
||
4 | import java.util.Collection; |
||
9 | dev | 5 | import java.util.Collections; |
3 | dev | 6 | import java.util.ArrayList; |
7 | import java.util.Iterator; |
||
8 | import java.util.Date; |
||
9 | import java.util.Map; |
||
10 | import java.util.HashMap; |
||
16 | dev | 11 | import java.util.Calendar; |
11 | dev | 12 | import ak.kickup.util.ModelException; |
13 | import ak.kickup.util.ModelSecurityException; |
||
3 | dev | 14 | |
15 | /** |
||
16 | * |
||
17 | * @hibernate.class table="events" |
||
18 | */ |
||
19 | public class Event |
||
20 | extends GeneralModelObject |
||
21 | { |
||
22 | private String name; |
||
19 | dev | 23 | private String email; |
24 | private String admins; |
||
3 | dev | 25 | private String place; |
26 | private String address; |
||
27 | private String transportDesc; |
||
28 | private Date start; |
||
29 | private Date stop; |
||
30 | private Date lastRegister; |
||
31 | private Date lastUnregister; |
||
32 | private BigDecimal price; |
||
33 | private String moneyAccount; |
||
34 | private Boolean enabled; |
||
35 | private String comment; |
||
9 | dev | 36 | private Collection acts; // Collection(EventAct) |
37 | private Map actsMap = new HashMap(); // Map(Long id -> EventAct) |
||
38 | private Collection apartments; // Collection(EventApartment) |
||
39 | private Map apartmentsMap = new HashMap(); // Map(Long id -> EventApartment) |
||
16 | dev | 40 | private Collection participants; // Collection(EventAct) |
3 | dev | 41 | |
42 | protected Event() |
||
43 | { |
||
44 | } |
||
45 | |||
46 | protected void init() |
||
47 | { |
||
48 | acts = new ArrayList(); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * |
||
53 | * @hibernate.property |
||
54 | */ |
||
55 | public String getName() |
||
56 | { |
||
57 | return name; |
||
58 | } |
||
59 | |||
60 | public void setName(String name) |
||
61 | { |
||
62 | this.name = name; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * |
||
67 | * @hibernate.property |
||
68 | */ |
||
19 | dev | 69 | public String getEmail() |
70 | { |
||
71 | return email; |
||
72 | } |
||
73 | |||
74 | public void setEmail(String email) |
||
75 | { |
||
76 | this.email = email; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * |
||
81 | * @hibernate.property |
||
82 | */ |
||
83 | public String getAdmins() |
||
84 | { |
||
85 | return admins; |
||
86 | } |
||
87 | |||
88 | public void setAdmins(String admins) |
||
89 | { |
||
90 | this.admins = admins; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * |
||
95 | * @hibernate.property |
||
96 | */ |
||
3 | dev | 97 | public String getPlace() |
98 | { |
||
99 | return place; |
||
100 | } |
||
101 | |||
102 | public void setPlace(String place) |
||
103 | { |
||
104 | this.place = place; |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * |
||
109 | * @hibernate.property |
||
110 | */ |
||
111 | public String getAddress() |
||
112 | { |
||
113 | return address; |
||
114 | } |
||
115 | |||
116 | public void setAddress(String address) |
||
117 | { |
||
118 | this.address = address; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * |
||
123 | * @hibernate.property column="transport_desc" |
||
124 | */ |
||
125 | public String getTransportDesc() |
||
126 | { |
||
127 | return transportDesc; |
||
128 | } |
||
129 | |||
130 | public void setTransportDesc(String transportDesc) |
||
131 | { |
||
132 | this.transportDesc = transportDesc; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * |
||
137 | * @hibernate.property |
||
138 | */ |
||
139 | public Date getStart() |
||
140 | { |
||
141 | return start; |
||
142 | } |
||
143 | |||
144 | public void setStart(Date start) |
||
145 | { |
||
146 | this.start = start; |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * |
||
151 | * @hibernate.property |
||
152 | */ |
||
153 | public Date getStop() |
||
154 | { |
||
155 | return stop; |
||
156 | } |
||
157 | |||
158 | public void setStop(Date stop) |
||
159 | { |
||
160 | this.stop = stop; |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * |
||
165 | * @hibernate.property column="last_register" |
||
166 | */ |
||
167 | public Date getLastRegister() |
||
168 | { |
||
169 | return lastRegister; |
||
170 | } |
||
171 | |||
172 | public void setLastRegister(Date lastRegister) |
||
173 | { |
||
174 | this.lastRegister = lastRegister; |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * |
||
179 | * @hibernate.property column="last_unregister" |
||
180 | */ |
||
181 | public Date getLastUnregister() |
||
182 | { |
||
183 | return lastUnregister; |
||
184 | } |
||
185 | |||
186 | public void setLastUnregister(Date lastUnregister) |
||
187 | { |
||
188 | this.lastUnregister = lastUnregister; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * |
||
193 | * @hibernate.property |
||
194 | */ |
||
195 | public BigDecimal getPrice() |
||
196 | { |
||
197 | return price; |
||
198 | } |
||
199 | |||
200 | public void setPrice(BigDecimal price) |
||
201 | { |
||
202 | this.price = price; |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * |
||
207 | * @hibernate.property column="money_account" |
||
208 | */ |
||
209 | public String getMoneyAccount() |
||
210 | { |
||
211 | return moneyAccount; |
||
212 | } |
||
213 | |||
214 | public void setMoneyAccount(String moneyAccount) |
||
215 | { |
||
216 | this.moneyAccount = moneyAccount; |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * |
||
221 | * @hibernate.property |
||
222 | */ |
||
223 | public Boolean getEnabled() |
||
224 | { |
||
225 | return enabled; |
||
226 | } |
||
227 | |||
228 | public void setEnabled(Boolean enabled) |
||
229 | { |
||
230 | this.enabled = enabled; |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * |
||
235 | * @hibernate.property |
||
236 | */ |
||
237 | public String getComment() |
||
238 | { |
||
239 | return comment; |
||
240 | } |
||
241 | |||
242 | public void setComment(String comment) |
||
243 | { |
||
244 | this.comment = comment; |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * @return Collection(EventAct) |
||
249 | * |
||
250 | * @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true" |
||
9 | dev | 251 | * @hibernate.collection-key column="event" |
11 | dev | 252 | * @hibernate.collection-one-to-many class="ak.kickup.core.model.EventAct" |
3 | dev | 253 | */ |
9 | dev | 254 | protected Collection getActs() |
3 | dev | 255 | { |
256 | return acts; |
||
257 | } |
||
258 | |||
9 | dev | 259 | public Collection getActCollection() |
260 | { |
||
261 | return Collections.unmodifiableCollection(acts); |
||
262 | } |
||
263 | |||
3 | dev | 264 | /** |
265 | * @param destinations Collection(EventAct) |
||
266 | */ |
||
9 | dev | 267 | protected void setActs(Collection acts) |
3 | dev | 268 | { |
269 | this.acts = acts; |
||
270 | |||
271 | actsMap.clear(); |
||
9 | dev | 272 | if(acts != null) { |
273 | for(Iterator i = acts.iterator(); i.hasNext(); ) { |
||
274 | EventAct a = (EventAct)i.next(); |
||
275 | actsMap.put(a.getAct().getId(), a); |
||
276 | } |
||
3 | dev | 277 | } |
278 | } |
||
279 | |||
280 | public EventAct getAct(Long actId) |
||
281 | { |
||
282 | return (EventAct)actsMap.get(actId); |
||
283 | } |
||
9 | dev | 284 | |
285 | public void addAct(EventAct act) |
||
286 | { |
||
287 | acts.add(act); |
||
288 | actsMap.put(act.getAct().getId(), act); |
||
289 | } |
||
290 | |||
291 | public void removeAct(EventAct act) |
||
292 | { |
||
293 | acts.remove(act); |
||
294 | actsMap.remove(act.getAct().getId()); |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * @return Collection(EventApartment) |
||
299 | * |
||
300 | * @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true" |
||
301 | * @hibernate.collection-key column="event" |
||
11 | dev | 302 | * @hibernate.collection-one-to-many class="ak.kickup.core.model.EventApartment" |
9 | dev | 303 | */ |
304 | protected Collection getApartments() |
||
305 | { |
||
306 | return apartments; |
||
307 | } |
||
308 | |||
309 | public Collection getApartmentCollection() |
||
310 | { |
||
311 | return Collections.unmodifiableCollection(apartments); |
||
312 | } |
||
313 | |||
314 | /** |
||
315 | * @param destinations Collection(EventApartment) |
||
316 | */ |
||
317 | protected void setApartments(Collection apartments) |
||
318 | { |
||
319 | this.apartments = apartments; |
||
320 | |||
321 | apartmentsMap.clear(); |
||
322 | if(apartments != null) { |
||
323 | for(Iterator i = apartments.iterator(); i.hasNext(); ) { |
||
324 | EventApartment a = (EventApartment)i.next(); |
||
325 | apartmentsMap.put(a.getApartment().getId(), a); |
||
326 | } |
||
327 | } |
||
328 | } |
||
329 | |||
330 | public EventApartment getApartment(Long apartmentId) |
||
331 | { |
||
332 | return (EventApartment)apartmentsMap.get(apartmentId); |
||
333 | } |
||
334 | |||
335 | public void addApartment(EventApartment apartment) |
||
336 | { |
||
337 | apartments.add(apartment); |
||
338 | apartmentsMap.put(apartment.getApartment().getId(), apartment); |
||
339 | } |
||
340 | |||
341 | public void removeApartment(EventApartment apartment) |
||
342 | { |
||
343 | apartments.remove(apartment); |
||
344 | apartmentsMap.remove(apartment.getApartment().getId()); |
||
16 | dev | 345 | } |
346 | |||
347 | public boolean isRegistrationAvailable() |
||
348 | { |
||
349 | if(enabled == null || !enabled.booleanValue()) return false; |
||
350 | |||
351 | Calendar cal = Calendar.getInstance(); |
||
352 | cal.set(Calendar.HOUR_OF_DAY, 0); |
||
353 | cal.set(Calendar.MINUTE, 0); |
||
354 | cal.set(Calendar.SECOND, 0); |
||
355 | cal.set(Calendar.MILLISECOND, 0); |
||
356 | |||
357 | Date now = cal.getTime(); |
||
358 | |||
359 | if(lastRegister == null) { |
||
360 | return (start == null || !start.before(now)); |
||
361 | } |
||
362 | else { |
||
363 | return !lastRegister.before(now); |
||
364 | } |
||
9 | dev | 365 | } |
16 | dev | 366 | |
367 | public boolean isUnregistrationAvailable() |
||
368 | { |
||
369 | if(enabled == null || !enabled.booleanValue()) return false; |
||
370 | |||
371 | Calendar cal = Calendar.getInstance(); |
||
372 | cal.set(Calendar.HOUR_OF_DAY, 0); |
||
373 | cal.set(Calendar.MINUTE, 0); |
||
374 | cal.set(Calendar.SECOND, 0); |
||
375 | cal.set(Calendar.MILLISECOND, 0); |
||
376 | |||
377 | Date now = cal.getTime(); |
||
378 | |||
379 | if(lastUnregister == null) { |
||
380 | return (start == null || !start.before(now)); |
||
381 | } |
||
382 | else { |
||
383 | return !lastUnregister.before(now); |
||
384 | } |
||
385 | } |
||
386 | |||
387 | public int getParticipantCount() |
||
388 | { |
||
389 | return participants.size(); |
||
390 | } |
||
391 | |||
392 | public int getPersonCount() |
||
393 | { |
||
394 | int count = 0; |
||
395 | |||
396 | for(Iterator i = participants.iterator(); i.hasNext(); ) { |
||
397 | Participant p = (Participant)i.next(); |
||
398 | if(p.getPersons() != null) |
||
399 | count += p.getPersons().intValue(); |
||
400 | } |
||
401 | |||
402 | return count; |
||
403 | } |
||
404 | |||
405 | /** |
||
406 | * @return Collection(Participant) |
||
407 | * |
||
408 | * @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true" |
||
409 | * @hibernate.collection-key column="event" |
||
410 | * @hibernate.collection-one-to-many class="ak.kickup.core.model.Participant" |
||
411 | */ |
||
412 | protected Collection getParticipants() |
||
413 | { |
||
414 | return participants; |
||
415 | } |
||
416 | |||
417 | public Collection getParticipantCollection() |
||
418 | { |
||
419 | return Collections.unmodifiableCollection(participants); |
||
420 | } |
||
421 | |||
422 | /** |
||
423 | * @param destinations Collection(Participant) |
||
424 | */ |
||
425 | protected void setParticipants(Collection participants) |
||
426 | { |
||
427 | this.participants = participants; |
||
428 | } |
||
3 | dev | 429 | } |