0,0 → 1,387 |
package ak.kickup.core.model; |
|
import java.math.BigDecimal; |
import java.util.Date; |
import java.util.Map; |
import java.util.HashMap; |
import java.util.Collections; |
import java.util.Collection; |
import java.util.Iterator; |
import java.util.ArrayList; |
import ak.kickup.util.ModelException; |
import ak.kickup.util.ModelSecurityException; |
|
/** |
* |
* @hibernate.class table="participants" |
*/ |
public class Participant |
extends GeneralModelObject |
{ |
public static final int PAYED_NULL = 0; // event price is nto defined |
public static final int PAYED_NONE = 1; // noit yet payed |
public static final int PAYED_LESS = 2; // payed but less then needed |
public static final int PAYED_EXACTLY = 3; // payed exactly as needed |
public static final int PAYED_MORE = 4; // payed more then needed |
|
private String ident; |
private String nick; |
private String email; |
private Boolean emailPublic; |
private String name; |
private String phone; |
private Event event; |
private Integer persons; |
private String fromZip; |
private String fromCity; |
private Date departure; |
private Integer freeTransport; |
private String transportComment; |
private Integer freeSleep; |
private String sleepComment; |
private BigDecimal payed; |
private String comment; |
private String privateComment; |
private Collection acts; // Collection(ParticipantAct) |
private Map actsMap = new HashMap(); // Map(Long id -> ParticipantAct) |
|
protected Participant() |
{ |
} |
|
protected void init() |
{ |
acts = new ArrayList(); |
} |
|
/** |
* |
* @hibernate.property |
*/ |
public String getIdent() |
{ |
return ident; |
} |
|
public void setIdent(String ident) |
{ |
this.ident = ident; |
} |
|
/** |
* |
* @hibernate.property |
*/ |
public String getNick() |
{ |
return nick; |
} |
|
public void setNick(String nick) |
{ |
this.nick = nick; |
} |
|
/** |
* |
* @hibernate.property |
*/ |
public String getEmail() |
{ |
return email; |
} |
|
public void setEmail(String email) |
{ |
this.email = email; |
} |
|
/** |
* |
* @hibernate.property column="email_public" |
*/ |
public Boolean getEmailPublic() |
{ |
return emailPublic; |
} |
|
public void setEmailPublic(Boolean emailPublic) |
{ |
this.emailPublic = emailPublic; |
} |
|
/** |
* |
* @hibernate.property |
*/ |
public String getName() |
{ |
return name; |
} |
|
public void setName(String name) |
{ |
this.name = name; |
} |
|
/** |
* |
* @hibernate.property |
*/ |
public String getPhone() |
{ |
return phone; |
} |
|
public void setPhone(String phone) |
{ |
this.phone = phone; |
} |
|
/** |
* |
* @hibernate.many-to-one |
*/ |
public Event getEvent() |
{ |
return event; |
} |
|
public void setEvent(Event event) |
{ |
this.event = event; |
} |
|
/** |
* |
* @hibernate.property |
*/ |
public Integer getPersons() |
{ |
return persons; |
} |
|
public void setPersons(Integer persons) |
{ |
this.persons = persons; |
} |
|
/** |
* |
* @hibernate.property column="from_zip" |
*/ |
public String getFromZip() |
{ |
return fromZip; |
} |
|
public void setFromZip(String fromZip) |
{ |
this.fromZip = fromZip; |
} |
|
/** |
* |
* @hibernate.property column="from_city" |
*/ |
public String getFromCity() |
{ |
return fromCity; |
} |
|
public void setFromCity(String fromCity) |
{ |
this.fromCity = fromCity; |
} |
|
/** |
* |
* @hibernate.property |
*/ |
public Date getDeparture() |
{ |
return departure; |
} |
|
public void setDeparture(Date departure) |
{ |
this.departure = departure; |
} |
|
/** |
* |
* @hibernate.property column="free_transport" |
*/ |
public Integer getFreeTransport() |
{ |
return freeTransport; |
} |
|
public void setFreeTransport(Integer freeTransport) |
{ |
this.freeTransport = freeTransport; |
} |
|
/** |
* |
* @hibernate.property column="transport_comment" |
*/ |
public String getTransportComment() |
{ |
return transportComment; |
} |
|
public void setTransportComment(String transportComment) |
{ |
this.transportComment = transportComment; |
} |
|
/** |
* |
* @hibernate.property column="free_sleep" |
*/ |
public Integer getFreeSleep() |
{ |
return freeSleep; |
} |
|
public void setFreeSleep(Integer freeSleep) |
{ |
this.freeSleep = freeSleep; |
} |
|
/** |
* |
* @hibernate.property column="sleep_comment" |
*/ |
public String getSleepComment() |
{ |
return sleepComment; |
} |
|
public void setSleepComment(String sleepComment) |
{ |
this.sleepComment = sleepComment; |
} |
|
/** |
* |
* @hibernate.property |
*/ |
public BigDecimal getPayed() |
{ |
return payed; |
} |
|
public void setPayed(BigDecimal payed) |
{ |
this.payed = payed; |
} |
|
public BigDecimal getMustPay() |
{ |
if(event == null || event.getPrice() == null || persons == null) return null; |
|
return new BigDecimal(event.getPrice().doubleValue() * persons.intValue()); |
} |
|
public int getPayedStatus() |
{ |
if(event == null || event.getPrice() == null || persons == null) return PAYED_NULL; |
if(payed == null) return PAYED_NONE; |
|
double needed = event.getPrice().doubleValue() * persons.intValue(); |
double p = payed.doubleValue(); |
|
if(Math.abs(needed - p) < 0.001) return PAYED_EXACTLY; |
else if(needed < p) return PAYED_MORE; |
else return PAYED_LESS; |
} |
|
/** |
* |
* @hibernate.property |
*/ |
public String getComment() |
{ |
return comment; |
} |
|
public void setComment(String comment) |
{ |
this.comment = comment; |
} |
|
/** |
* |
* @hibernate.property column="private_comment" |
*/ |
public String getPrivateComment() |
{ |
return privateComment; |
} |
|
public void setPrivateComment(String privateComment) |
{ |
this.privateComment = privateComment; |
} |
|
/** |
* @return Collection(ParticipantAct) |
* |
* @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true" |
* @hibernate.collection-key column="participant" |
* @hibernate.collection-one-to-many class="ak.kickup.core.model.ParticipantAct" |
*/ |
protected Collection getActs() |
{ |
return acts; |
} |
|
public Collection getActCollection() |
{ |
return Collections.unmodifiableCollection(acts); |
} |
|
/** |
* @param destinations Collection(ParticipantAct) |
*/ |
protected void setActs(Collection acts) |
{ |
this.acts = acts; |
|
actsMap.clear(); |
if(acts != null) { |
for(Iterator i = acts.iterator(); i.hasNext(); ) { |
ParticipantAct a = (ParticipantAct)i.next(); |
if(a.getAct() != null) |
actsMap.put(a.getAct().getId(), a); |
} |
} |
} |
|
public ParticipantAct getAct(Long actId) |
{ |
return (ParticipantAct)actsMap.get(actId); |
} |
|
public void addAct(ParticipantAct act) |
{ |
acts.add(act); |
actsMap.put(act.getAct().getId(), act); |
} |
|
public void removeAct(ParticipantAct act) |
{ |
acts.remove(act); |
actsMap.remove(act.getAct().getId()); |
} |
|
public boolean equals(Object o) |
{ |
if(o == null || !(o instanceof Participant)) return false; |
|
Participant p = (Participant)o; |
return (getId() != null) && (p.getId() != null) && (getId().equals(p.getId())); |
} |
} |