Subversion Repositories general

Rev

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