Subversion Repositories general

Rev

Rev 31 | Rev 972 | 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();
32 dev 277
				if(a.getAct() != null)
278
					actsMap.put(a.getAct().getId(), a);
9 dev 279
			}
3 dev 280
		}
281
	}
282
 
283
	public EventAct getAct(Long actId)
284
	{
285
		return (EventAct)actsMap.get(actId);
286
	}
9 dev 287
 
288
	public void addAct(EventAct act)
289
	{
290
		acts.add(act);
291
		actsMap.put(act.getAct().getId(), act);
292
	}
293
 
294
	public void removeAct(EventAct act)
295
	{
296
		acts.remove(act);
297
		actsMap.remove(act.getAct().getId());
298
	}
299
 
300
 	/**
301
 	 * @return Collection(EventApartment)
302
 	 *
303
 	 * @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true"
304
	 * @hibernate.collection-key column="event"
11 dev 305
     * @hibernate.collection-one-to-many class="ak.kickup.core.model.EventApartment"
9 dev 306
     */
307
	protected Collection getApartments()
308
	{
309
		return apartments;
310
	}
311
 
312
	public Collection getApartmentCollection()
313
	{
314
		return Collections.unmodifiableCollection(apartments);
315
	}
316
 
317
	/**
318
	 * @param destinations Collection(EventApartment)
319
	 */
320
	protected void setApartments(Collection apartments)
321
	{
322
		this.apartments = apartments;
323
 
324
		apartmentsMap.clear();
325
		if(apartments != null) {
326
			for(Iterator i = apartments.iterator(); i.hasNext(); ) {
327
				EventApartment a = (EventApartment)i.next();
32 dev 328
				if(a.getApartment() != null)
329
					apartmentsMap.put(a.getApartment().getId(), a);
9 dev 330
			}
331
		}
332
	}
333
 
334
	public EventApartment getApartment(Long apartmentId)
335
	{
336
		return (EventApartment)apartmentsMap.get(apartmentId);
337
	}
338
 
339
	public void addApartment(EventApartment apartment)
340
	{
341
		apartments.add(apartment);
342
		apartmentsMap.put(apartment.getApartment().getId(), apartment);
343
	}
344
 
345
	public void removeApartment(EventApartment apartment)
346
	{
347
		apartments.remove(apartment);
348
		apartmentsMap.remove(apartment.getApartment().getId());
16 dev 349
	}
350
 
351
	public boolean isRegistrationAvailable()
352
	{
353
		if(enabled == null || !enabled.booleanValue()) return false;
354
 
355
		Calendar cal = Calendar.getInstance();
356
		cal.set(Calendar.HOUR_OF_DAY, 0);
357
		cal.set(Calendar.MINUTE,      0);
358
		cal.set(Calendar.SECOND,      0);
359
		cal.set(Calendar.MILLISECOND, 0);
360
 
361
		Date now = cal.getTime();
362
 
363
		if(lastRegister == null) {
364
			return (start == null || !start.before(now));
365
		}
366
		else {
367
 			return !lastRegister.before(now);
368
 		}
9 dev 369
	}
16 dev 370
 
371
	public boolean isUnregistrationAvailable()
372
	{
373
		if(enabled == null || !enabled.booleanValue()) return false;
374
 
375
		Calendar cal = Calendar.getInstance();
376
		cal.set(Calendar.HOUR_OF_DAY, 0);
377
		cal.set(Calendar.MINUTE,      0);
378
		cal.set(Calendar.SECOND,      0);
379
		cal.set(Calendar.MILLISECOND, 0);
380
 
381
		Date now = cal.getTime();
382
 
383
		if(lastUnregister == null) {
384
			return (start == null || !start.before(now));
385
		}
386
		else {
387
 			return !lastUnregister.before(now);
388
 		}
389
	}
390
 
391
	public int getParticipantCount()
392
	{
393
		return participants.size();
394
	}
395
 
396
	public int getPersonCount()
397
	{
398
		int count = 0;
399
 
400
		for(Iterator i = participants.iterator(); i.hasNext(); ) {
401
			Participant p = (Participant)i.next();
402
			if(p.getPersons() != null)
403
				count += p.getPersons().intValue();
404
		}
405
 
406
		return count;
407
	}
408
 
409
 	/**
410
 	 * @return Collection(Participant)
411
 	 *
412
 	 * @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true"
413
	 * @hibernate.collection-key column="event"
414
     * @hibernate.collection-one-to-many class="ak.kickup.core.model.Participant"
415
     */
416
	protected Collection getParticipants()
417
	{
418
		return participants;
419
	}
420
 
421
	public Collection getParticipantCollection()
422
	{
423
		return Collections.unmodifiableCollection(participants);
424
	}
425
 
426
	/**
427
	 * @param destinations Collection(Participant)
428
	 */
429
	protected void setParticipants(Collection participants)
430
	{
431
		this.participants = participants;
432
	}
3 dev 433
}