Subversion Repositories general

Rev

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