Subversion Repositories general

Rev

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