Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 15 → Rev 16

/kickup/trunk/src/ak/kickup/core/model/EventManager.java
56,16 → 56,23
return e;
}
 
public Event get(Long id)
public Event get(Long id, boolean enabledOnly)
throws ModelException
{
Event event;
 
try {
return (Event)HibernateUtil.currentSession().load(Event.class, id);
event = (Event)HibernateUtil.currentSession().load(Event.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(enabledOnly && (event.getEnabled() == null || !event.getEnabled().booleanValue()))
throw new ModelSecurityException();
 
return event;
}
 
public boolean nameExists(Event event, String name)
201,4 → 208,62
return (obj instanceof StartComparator);
}
}
 
public static final Comparator ACT_NAME_COMPARATOR = new ActNameComparator();
 
private static class ActNameComparator
implements Comparator
{
public int compare(Object o1, Object o2)
{
if(!(o1 instanceof EventAct) || !(o2 instanceof EventAct))
throw new ClassCastException("not a EventAct");
 
EventAct a1 = (EventAct)o1;
EventAct a2 = (EventAct)o2;
 
if(a1 == null && a2 == null)
return 0;
else if(a1 == null && a2 != null)
return -1;
else if(a1 != null && a2 == null)
return 1;
else
return a1.getAct().getName().compareToIgnoreCase(a2.getAct().getName());
}
 
public boolean equals(Object obj)
{
return (obj instanceof ActNameComparator);
}
}
 
public static final Comparator APARTMENT_NAME_COMPARATOR = new ApartmentNameComparator();
 
private static class ApartmentNameComparator
implements Comparator
{
public int compare(Object o1, Object o2)
{
if(!(o1 instanceof EventApartment) || !(o2 instanceof EventApartment))
throw new ClassCastException("not a EventApartment");
 
EventApartment a1 = (EventApartment)o1;
EventApartment a2 = (EventApartment)o2;
 
if(a1 == null && a2 == null)
return 0;
else if(a1 == null && a2 != null)
return -1;
else if(a1 != null && a2 == null)
return 1;
else
return a1.getApartment().getName().compareToIgnoreCase(a2.getApartment().getName());
}
 
public boolean equals(Object obj)
{
return (obj instanceof ApartmentNameComparator);
}
}
}
/kickup/trunk/src/ak/kickup/core/model/Event.java
8,6 → 8,7
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;
 
34,6 → 35,7
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()
{
310,5 → 312,88
{
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;
}
}
/kickup/trunk/src/ak/kickup/core/model/ParticipantManager.java
125,12 → 125,12
}
}
 
public Collection listParticipants(Event event)
public Collection listFreeTransport(Event event)
throws ModelException
{
try {
return HibernateUtil.currentSession().find(
"from Participant where event = ?",
"from Participant where event = ? and free_transport > 0",
event, Hibernate.entity(Event.class));
}
catch(HibernateException ex)
139,6 → 139,20
}
}
 
public Collection listFreeSleep(Event event)
throws ModelException
{
try {
return HibernateUtil.currentSession().find(
"from Participant where event = ? and free_sleep > 0",
event, Hibernate.entity(Event.class));
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
}
 
public static final Comparator NICK_COMPARATOR = new NickComparator();
 
private static class NickComparator