Rev 31 | Rev 972 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package ak.kickup.core.model;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Collections;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.Calendar;
import ak.kickup.util.ModelException;
import ak.kickup.util.ModelSecurityException;
/**
*
* @hibernate.class table="events"
*/
public class Event
extends GeneralModelObject
{
private String name;
private String email;
private String admins;
private String place;
private String address;
private String transportDesc;
private Date start;
private Date stop;
private Date lastRegister;
private Date lastUnregister;
private BigDecimal price;
private String moneyAccount;
private Boolean enabled;
private String comment;
private Collection acts; // Collection(EventAct)
private Map actsMap = new HashMap(); // Map(Long id -> EventAct)
private Collection apartments; // Collection(EventApartment)
private Map apartmentsMap = new HashMap(); // Map(Long id -> EventApartment)
private Collection participants; // Collection(EventAct)
protected Event()
{
}
protected void init()
{
acts = new ArrayList();
apartments = new ArrayList();
participants = new ArrayList();
}
/**
*
* @hibernate.property
*/
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
/**
*
* @hibernate.property
*/
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
/**
*
* @hibernate.property
*/
public String getAdmins()
{
return admins;
}
public void setAdmins(String admins)
{
this.admins = admins;
}
/**
*
* @hibernate.property
*/
public String getPlace()
{
return place;
}
public void setPlace(String place)
{
this.place = place;
}
/**
*
* @hibernate.property
*/
public String getAddress()
{
return address;
}
public void setAddress(String address)
{
this.address = address;
}
/**
*
* @hibernate.property column="transport_desc"
*/
public String getTransportDesc()
{
return transportDesc;
}
public void setTransportDesc(String transportDesc)
{
this.transportDesc = transportDesc;
}
/**
*
* @hibernate.property
*/
public Date getStart()
{
return start;
}
public void setStart(Date start)
{
this.start = start;
}
/**
*
* @hibernate.property
*/
public Date getStop()
{
return stop;
}
public void setStop(Date stop)
{
this.stop = stop;
}
/**
*
* @hibernate.property column="last_register"
*/
public Date getLastRegister()
{
return lastRegister;
}
public void setLastRegister(Date lastRegister)
{
this.lastRegister = lastRegister;
}
/**
*
* @hibernate.property column="last_unregister"
*/
public Date getLastUnregister()
{
return lastUnregister;
}
public void setLastUnregister(Date lastUnregister)
{
this.lastUnregister = lastUnregister;
}
/**
*
* @hibernate.property
*/
public BigDecimal getPrice()
{
return price;
}
public void setPrice(BigDecimal price)
{
this.price = price;
}
/**
*
* @hibernate.property column="money_account"
*/
public String getMoneyAccount()
{
return moneyAccount;
}
public void setMoneyAccount(String moneyAccount)
{
this.moneyAccount = moneyAccount;
}
/**
*
* @hibernate.property
*/
public Boolean getEnabled()
{
return enabled;
}
public void setEnabled(Boolean enabled)
{
this.enabled = enabled;
}
/**
*
* @hibernate.property
*/
public String getComment()
{
return comment;
}
public void setComment(String comment)
{
this.comment = comment;
}
/**
* @return Collection(EventAct)
*
* @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true"
* @hibernate.collection-key column="event"
* @hibernate.collection-one-to-many class="ak.kickup.core.model.EventAct"
*/
protected Collection getActs()
{
return acts;
}
public Collection getActCollection()
{
return Collections.unmodifiableCollection(acts);
}
/**
* @param destinations Collection(EventAct)
*/
protected void setActs(Collection acts)
{
this.acts = acts;
actsMap.clear();
if(acts != null) {
for(Iterator i = acts.iterator(); i.hasNext(); ) {
EventAct a = (EventAct)i.next();
if(a.getAct() != null)
actsMap.put(a.getAct().getId(), a);
}
}
}
public EventAct getAct(Long actId)
{
return (EventAct)actsMap.get(actId);
}
public void addAct(EventAct act)
{
acts.add(act);
actsMap.put(act.getAct().getId(), act);
}
public void removeAct(EventAct act)
{
acts.remove(act);
actsMap.remove(act.getAct().getId());
}
/**
* @return Collection(EventApartment)
*
* @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true"
* @hibernate.collection-key column="event"
* @hibernate.collection-one-to-many class="ak.kickup.core.model.EventApartment"
*/
protected Collection getApartments()
{
return apartments;
}
public Collection getApartmentCollection()
{
return Collections.unmodifiableCollection(apartments);
}
/**
* @param destinations Collection(EventApartment)
*/
protected void setApartments(Collection apartments)
{
this.apartments = apartments;
apartmentsMap.clear();
if(apartments != null) {
for(Iterator i = apartments.iterator(); i.hasNext(); ) {
EventApartment a = (EventApartment)i.next();
if(a.getApartment() != null)
apartmentsMap.put(a.getApartment().getId(), a);
}
}
}
public EventApartment getApartment(Long apartmentId)
{
return (EventApartment)apartmentsMap.get(apartmentId);
}
public void addApartment(EventApartment apartment)
{
apartments.add(apartment);
apartmentsMap.put(apartment.getApartment().getId(), apartment);
}
public void removeApartment(EventApartment apartment)
{
apartments.remove(apartment);
apartmentsMap.remove(apartment.getApartment().getId());
}
public boolean isRegistrationAvailable()
{
if(enabled == null || !enabled.booleanValue()) return false;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date now = cal.getTime();
if(lastRegister == null) {
return (start == null || !start.before(now));
}
else {
return !lastRegister.before(now);
}
}
public boolean isUnregistrationAvailable()
{
if(enabled == null || !enabled.booleanValue()) return false;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date now = cal.getTime();
if(lastUnregister == null) {
return (start == null || !start.before(now));
}
else {
return !lastUnregister.before(now);
}
}
public int getParticipantCount()
{
return participants.size();
}
public int getPersonCount()
{
int count = 0;
for(Iterator i = participants.iterator(); i.hasNext(); ) {
Participant p = (Participant)i.next();
if(p.getPersons() != null)
count += p.getPersons().intValue();
}
return count;
}
/**
* @return Collection(Participant)
*
* @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true"
* @hibernate.collection-key column="event"
* @hibernate.collection-one-to-many class="ak.kickup.core.model.Participant"
*/
protected Collection getParticipants()
{
return participants;
}
public Collection getParticipantCollection()
{
return Collections.unmodifiableCollection(participants);
}
/**
* @param destinations Collection(Participant)
*/
protected void setParticipants(Collection participants)
{
this.participants = participants;
}
}