/it-ru/trunk/src/ak/itru/core/action/AdminParticipantAction.java |
---|
0,0 → 1,156 |
package ak.itru.core.action; |
import java.util.List; |
import java.util.Collections; |
import java.util.ArrayList; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.action.Action; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.DynaActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionError; |
import ak.strutsx.RequestUtilsX; |
import ak.strutsx.ErrorHandlerX; |
import ak.backpath.BackPath; |
import ak.itru.util.StringConverter; |
import ak.itru.util.UserException; |
import ak.itru.core.model.Participant; |
import ak.itru.core.model.ParticipantManager; |
import ak.itru.core.model.Event; |
import ak.itru.core.model.EventManager; |
public final class AdminParticipantAction |
extends Action |
implements ErrorHandlerX |
{ |
public void handleErrors(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long eventId = StringConverter.parseLong(theForm.get("event")); |
Event event = EventManager.getInstance().get(eventId); |
Long participantId = StringConverter.parseLong(theForm.get("id")); |
Participant participant; |
if(participantId == null) { |
participant = ParticipantManager.getInstance().create(); |
} |
else { |
participant = ParticipantManager.getInstance().get(participantId); |
} |
request.setAttribute("event", event); |
request.setAttribute("participant", participant); |
} |
} |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
if("list".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long eventId = StringConverter.parseLong(theForm.get("event")); |
Event event = EventManager.getInstance().get(eventId); |
List list = new ArrayList(ParticipantManager.getInstance().listParticipants(event)); |
Collections.sort(list, ParticipantManager.NICK_COMPARATOR); |
request.setAttribute("participants", list); |
request.setAttribute("event", event); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long eventId = StringConverter.parseLong(theForm.get("event")); |
Event event = EventManager.getInstance().get(eventId); |
Long participantId = StringConverter.parseLong(theForm.get("id")); |
Participant participant; |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "ParticipantEditForm"); |
if(participantId == null) { |
participant = ParticipantManager.getInstance().create(); |
} |
else { |
participant = ParticipantManager.getInstance().get(participantId); |
showForm.set("nick", participant.getNick()); |
showForm.set("email", participant.getEmail()); |
showForm.set("emailPublic", participant.getEmailPublic()); |
showForm.set("name", participant.getName()); |
showForm.set("phone", participant.getPhone()); |
showForm.set("persons", StringConverter.toString(participant.getPersons())); |
showForm.set("fromZip", participant.getFromZip()); |
showForm.set("fromCity", participant.getFromCity()); |
showForm.set("departure", StringConverter.toDateTime(participant.getDeparture())); |
showForm.set("freeTransport", StringConverter.toString(participant.getFreeTransport())); |
showForm.set("transportComment", participant.getTransportComment()); |
showForm.set("freeSleep", StringConverter.toString(participant.getFreeSleep())); |
showForm.set("sleepComment", participant.getSleepComment()); |
showForm.set("payed", participant.getPayed()); |
showForm.set("comment", participant.getComment()); |
showForm.set("privateComment", participant.getPrivateComment()); |
} |
request.setAttribute("event", event); |
request.setAttribute("participant", participant); |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long participantId = StringConverter.parseLong(theForm.get("id")); |
Participant participant = ParticipantManager.getInstance().get(participantId); |
ParticipantManager.getInstance().delete(participant); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long participantId = StringConverter.parseLong(theForm.get("id")); |
Participant participant; |
if(participantId == null) { |
Long eventId = StringConverter.parseLong(theForm.get("event")); |
Event event = EventManager.getInstance().get(eventId); |
participant = ParticipantManager.getInstance().create(); |
participant.setIdent(ParticipantManager.getInstance().generateIdent()); |
participant.setEvent(event); |
} |
else { |
participant = ParticipantManager.getInstance().get(participantId); |
} |
participant.setNick((String)theForm.get("nick")); |
participant.setEmail((String)theForm.get("email")); |
participant.setEmailPublic((Boolean)theForm.get("emailPublic")); |
participant.setName((String)theForm.get("name")); |
participant.setPhone((String)theForm.get("phone")); |
participant.setPersons(StringConverter.parseInteger(theForm.get("persons"))); |
participant.setFromZip((String)theForm.get("fromZip")); |
participant.setFromCity((String)theForm.get("fromCity")); |
participant.setDeparture(StringConverter.parseDateTime(theForm.get("departure"))); |
participant.setFreeTransport(StringConverter.parseInteger(theForm.get("freeTransport"))); |
participant.setTransportComment((String)theForm.get("transportComment")); |
participant.setFreeSleep(StringConverter.parseInteger(theForm.get("freeSleep"))); |
participant.setSleepComment((String)theForm.get("sleepComment")); |
participant.setPayed((Boolean)theForm.get("payed")); |
participant.setComment((String)theForm.get("comment")); |
participant.setPrivateComment((String)theForm.get("privateComment")); |
ParticipantManager.getInstance().save(participant); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
} |
/it-ru/trunk/src/ak/itru/core/action/AdminEventAction.java |
---|
24,13 → 24,28 |
import ak.itru.util.UserException; |
import ak.itru.core.model.Event; |
import ak.itru.core.model.EventManager; |
import ak.itru.core.model.EventAct; |
import ak.itru.core.model.EventApartment; |
import ak.itru.core.model.Act; |
import ak.itru.core.model.ActManager; |
import ak.itru.core.model.Apartment; |
import ak.itru.core.model.ApartmentManager; |
import ak.itru.core.form.EventActBean; |
import ak.itru.core.form.EventApartmentBean; |
public final class AdminEventAction |
extends Action |
implements ErrorHandlerX |
{ |
public void handleErrors(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
if("submit".equals(mapping.getParameter())) { |
initLists(request); // FIXME: if a list is changed between "edit" and "submit" then indicies are wrong |
} |
} |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
42,11 → 57,12 |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long eventId = StringConverter.parseLong(theForm.get("id")); |
DynaActionForm theForm = (DynaActionForm)form; |
Long eventId = StringConverter.parseLong(theForm.get("id")); |
Event event; |
List acts = new ArrayList(ActManager.getInstance().listActs()); |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
List acts = new ArrayList(ActManager.getInstance().listActs()); |
List apartments = new ArrayList(ApartmentManager.getInstance().listApartments()); |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "EventEditForm"); |
if(eventId == null) { |
69,6 → 85,7 |
showForm.set("comment", event.getComment()); |
} |
// acts |
EventActBean[] a = new EventActBean[acts.size()]; |
Collections.sort(acts, ActManager.NAME_COMPARATOR); |
for(int i = 0; i < acts.size(); i++) { |
77,6 → 94,17 |
} |
showForm.set("acts", a); |
// apartments |
EventApartmentBean[] ap = new EventApartmentBean[apartments.size()]; |
Collections.sort(apartments, ApartmentManager.NAME_COMPARATOR); |
for(int i = 0; i < apartments.size(); i++) { |
Apartment apartment = (Apartment)apartments.get(i); |
ap[i] = new EventApartmentBean(apartment, (event == null) |
? null : event.getApartment(apartment.getId())); |
} |
showForm.set("apartments", ap); |
initLists(request); |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
89,9 → 117,9 |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long eventId = StringConverter.parseLong(theForm.get("id")); |
Event event; |
DynaActionForm theForm = (DynaActionForm)form; |
Long eventId = StringConverter.parseLong(theForm.get("id")); |
Event event; |
if(eventId == null) { |
event = EventManager.getInstance().create(); |
100,6 → 128,56 |
event = EventManager.getInstance().get(eventId); |
} |
// acts |
EventActBean[] acts = (EventActBean[])theForm.get("acts"); |
for(int i = 0; i < acts.length; i++) { |
// FIXME: validate act id |
// get bean |
Long actId = StringConverter.parseLong(acts[i].getActId()); |
Act act = ActManager.getInstance().get(actId); |
EventAct eventAct = event.getAct(actId); |
if(acts[i].getSelected() == null || !acts[i].getSelected().booleanValue()) { |
if(eventAct != null) event.removeAct(eventAct); |
} |
else { |
if(eventAct == null) { |
eventAct = EventManager.getInstance().createAct(); |
eventAct.setEvent(event); |
eventAct.setAct(act); |
event.addAct(eventAct); |
} |
eventAct.setComment(acts[i].getComment()); |
} |
} |
// apartments |
EventApartmentBean[] apartments = (EventApartmentBean[])theForm.get("apartments"); |
for(int i = 0; i < apartments.length; i++) { |
// FIXME: validate apartment id, distance |
// get bean |
Long apartmentId = StringConverter.parseLong(apartments[i].getApartmentId()); |
Apartment apartment = ApartmentManager.getInstance().get(apartmentId); |
EventApartment eventApartment = event.getApartment(apartmentId); |
if(apartments[i].getSelected() == null || !apartments[i].getSelected().booleanValue()) { |
if(eventApartment != null) event.removeApartment(eventApartment); |
} |
else { |
if(eventApartment == null) { |
eventApartment = EventManager.getInstance().createApartment(); |
eventApartment.setEvent(event); |
eventApartment.setApartment(apartment); |
event.addApartment(eventApartment); |
} |
eventApartment.setDistance(StringConverter.parseNumber(apartments[i].getDistance())); |
eventApartment.setComment(apartments[i].getComment()); |
} |
} |
// name |
String name = (String)theForm.get("name"); |
if(EventManager.getInstance().nameExists(event, name)) { |
throw new UserException("ak.itru.core.event.name.nonunique"); |
106,6 → 184,7 |
} |
event.setName(name); |
// others |
event.setPlace((String)theForm.get("place")); |
event.setAddress((String)theForm.get("address")); |
event.setTransportDesc((String)theForm.get("transport")); |
118,6 → 197,7 |
event.setEnabled((Boolean)theForm.get("enabled")); |
event.setComment((String)theForm.get("comment")); |
// save |
EventManager.getInstance().save(event); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
126,4 → 206,16 |
throw new Exception("unknown mapping parameter"); |
} |
} |
private void initLists(HttpServletRequest request) |
throws Exception |
{ |
List acts = new ArrayList(ActManager.getInstance().listActs()); |
List apartments = new ArrayList(ApartmentManager.getInstance().listApartments()); |
Collections.sort(acts, ActManager.NAME_COMPARATOR); |
request.setAttribute("actList", new ObjectList(acts)); |
Collections.sort(apartments, ApartmentManager.NAME_COMPARATOR); |
request.setAttribute("apartmentList", new ObjectList(apartments)); |
} |
} |
/it-ru/trunk/src/ak/itru/core/action/ObjectList.java |
---|
0,0 → 1,23 |
package ak.itru.core.action; |
import java.util.List; |
public class ObjectList |
{ |
private List objects; |
public ObjectList(List objects) |
{ |
this.objects = objects; |
} |
public List getObjects() |
{ |
return objects; |
} |
public void setObjects(List objects) |
{ |
this.objects = objects; |
} |
} |
/it-ru/trunk/src/ak/itru/core/model/EventAct.java |
---|
9,10 → 9,10 |
* @hibernate.class table="event_acts" |
*/ |
public class EventAct |
extends GeneralModelObject |
{ |
private Long id; |
private Long eventId; |
private Long actId; |
private Event event; |
private Act act; |
private String comment; |
private Date modStamp; |
22,30 → 22,30 |
/** |
* |
* @hibernate.id generator-class="native" |
* @hibernate.many-to-one |
*/ |
public Long getId() |
public Event getEvent() |
{ |
return id; |
return event; |
} |
protected void setId(Long id) |
public void setEvent(Event event) |
{ |
this.id = id; |
this.event = event; |
} |
/** |
* |
* @hibernate.property |
* @hibernate.many-to-one |
*/ |
public Long getEventId() |
public Act getAct() |
{ |
return eventId; |
return act; |
} |
public void setEventId(Long eventId) |
public void setAct(Act act) |
{ |
this.eventId = eventId; |
this.act = act; |
} |
/** |
52,20 → 52,6 |
* |
* @hibernate.property |
*/ |
public Long getActId() |
{ |
return actId; |
} |
public void setActId(Long actId) |
{ |
this.actId = actId; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getComment() |
{ |
return comment; |
75,18 → 61,4 |
{ |
this.comment = comment; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
} |
/it-ru/trunk/src/ak/itru/core/model/ParticipantManager.java |
---|
0,0 → 1,170 |
package ak.itru.core.model; |
import java.util.*; |
import java.io.UnsupportedEncodingException; |
import net.sf.hibernate.*; |
import net.sf.hibernate.type.Type; |
import ak.itru.util.HibernateUtil; |
import ak.itru.util.ModelException; |
import ak.itru.util.ModelSecurityException; |
public class ParticipantManager |
{ |
private static ParticipantManager participantManager = null; |
private static boolean registered = false; |
public static ParticipantManager getInstance() |
{ |
return participantManager; |
} |
protected static void register() |
{ |
synchronized(ParticipantManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"ak/itru/core/model/Participant.hbm.xml"); |
participantManager = new ParticipantManager(); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private ParticipantManager() |
{ |
} |
public Participant create() |
throws ModelException |
{ |
return new Participant(); |
} |
public Participant get(Long id) |
throws ModelException |
{ |
try { |
return (Participant)HibernateUtil.currentSession().load(Participant.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public String generateIdent() |
throws ModelException |
{ |
String ident; |
do { |
byte[] buf = new byte[6]; |
for(int i = 0; i < buf.length; i++) { |
buf[i] = (byte)(Math.random() * 10 + 48); |
} |
try { |
ident = new String(buf, "ascii"); |
} |
catch(UnsupportedEncodingException ex) { |
throw new ModelException(ex); |
} |
} while(identExists(ident)); |
return ident; |
} |
public boolean identExists(String ident) |
throws ModelException |
{ |
try { |
return ((Integer)HibernateUtil.currentSession().iterate( |
"select count(*) from Participant where ident = ?", |
ident, Hibernate.STRING) |
.next()).intValue() > 0; |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(Participant participant) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(participant); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(Participant participant) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(participant); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listParticipants(Event event) |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"from Participant where event = ?", |
event, Hibernate.entity(Event.class)); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public static final Comparator NICK_COMPARATOR = new NickComparator(); |
private static class NickComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof Participant) || !(o2 instanceof Participant)) |
throw new ClassCastException("not a Participant"); |
Participant a1 = (Participant)o1; |
Participant a2 = (Participant)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.getNick().compareToIgnoreCase(a2.getNick()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof NickComparator); |
} |
} |
} |
/it-ru/trunk/src/ak/itru/core/model/EventManager.java |
---|
28,6 → 28,8 |
"ak/itru/core/model/Event.hbm.xml"); |
HibernateUtil.getConfiguration().addResource( |
"ak/itru/core/model/EventAct.hbm.xml"); |
HibernateUtil.getConfiguration().addResource( |
"ak/itru/core/model/EventApartment.hbm.xml"); |
eventManager = new EventManager(); |
} |
131,6 → 133,18 |
} |
} |
public EventAct createAct() |
throws ModelException |
{ |
return new EventAct(); |
} |
public EventApartment createApartment() |
throws ModelException |
{ |
return new EventApartment(); |
} |
public static final Comparator NAME_COMPARATOR = new NameComparator(); |
public static final Comparator START_COMPARATOR = new StartComparator(); |
/it-ru/trunk/src/ak/itru/core/model/EventApartment.java |
---|
0,0 → 1,80 |
package ak.itru.core.model; |
import java.math.BigDecimal; |
import java.util.Date; |
import ak.itru.util.ModelException; |
import ak.itru.util.ModelSecurityException; |
/** |
* |
* @hibernate.class table="event_apartments" |
*/ |
public class EventApartment |
extends GeneralModelObject |
{ |
private Event event; |
private Apartment apartment; |
private BigDecimal distance; |
private String comment; |
private Date modStamp; |
protected EventApartment() |
{ |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public Event getEvent() |
{ |
return event; |
} |
public void setEvent(Event event) |
{ |
this.event = event; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public Apartment getApartment() |
{ |
return apartment; |
} |
public void setApartment(Apartment apartment) |
{ |
this.apartment = apartment; |
} |
/** |
* |
* @hibernate.property |
*/ |
public BigDecimal getDistance() |
{ |
return distance; |
} |
public void setDistance(BigDecimal distance) |
{ |
this.distance = distance; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getComment() |
{ |
return comment; |
} |
public void setComment(String comment) |
{ |
this.comment = comment; |
} |
} |
/it-ru/trunk/src/ak/itru/core/model/Participant.java |
---|
1,5 → 1,6 |
package ak.itru.core.model; |
import java.util.Date; |
import ak.itru.util.ModelException; |
import ak.itru.util.ModelSecurityException; |
10,11 → 11,24 |
public class Participant |
extends GeneralModelObject |
{ |
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 Boolean payed; |
private String comment; |
private String privateComment; |
protected Participant() |
{ |
24,6 → 38,20 |
* |
* @hibernate.property |
*/ |
public String getIdent() |
{ |
return ident; |
} |
public void setIdent(String ident) |
{ |
this.ident = ident; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getNick() |
{ |
return nick; |
48,6 → 76,20 |
this.email = email; |
} |
/** |
* |
* @hibernate.property column="email_public" |
*/ |
public Boolean getEmailPublic() |
{ |
return emailPublic; |
} |
public void setEmailPublic(Boolean emailPublic) |
{ |
this.emailPublic = emailPublic; |
} |
/** |
* |
* @hibernate.property |
76,10 → 118,150 |
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 Boolean getPayed() |
{ |
return payed; |
} |
public void setPayed(Boolean payed) |
{ |
this.payed = payed; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getComment() |
{ |
return comment; |
88,7 → 270,21 |
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; |
} |
public boolean equals(Object o) |
{ |
/it-ru/trunk/src/ak/itru/core/model/Event.java |
---|
2,6 → 2,7 |
import java.math.BigDecimal; |
import java.util.Collection; |
import java.util.Collections; |
import java.util.ArrayList; |
import java.util.Iterator; |
import java.util.Date; |
29,8 → 30,10 |
private String moneyAccount; |
private Boolean enabled; |
private String comment; |
private Collection acts; // Collection(EventAct) |
private Map actsMap = new HashMap(); |
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) |
protected Event() |
{ |
213,25 → 216,32 |
* @return Collection(EventAct) |
* |
* @hibernate.bag inverse="true" cascade="all-delete-orphan" lazy="true" |
* @hibernate.collection-key column="eventid" |
* @hibernate.collection-key column="event" |
* @hibernate.collection-one-to-many class="ak.itru.core.model.EventAct" |
*/ |
public Collection getActs() |
protected Collection getActs() |
{ |
return acts; |
} |
public Collection getActCollection() |
{ |
return Collections.unmodifiableCollection(acts); |
} |
/** |
* @param destinations Collection(EventAct) |
*/ |
public void setActs(Collection acts) |
protected void setActs(Collection acts) |
{ |
this.acts = acts; |
actsMap.clear(); |
for(Iterator i = acts.iterator(); i.hasNext(); ) { |
EventAct a = (EventAct)i.next(); |
actsMap.put(a.getActId(), a); |
if(acts != null) { |
for(Iterator i = acts.iterator(); i.hasNext(); ) { |
EventAct a = (EventAct)i.next(); |
actsMap.put(a.getAct().getId(), a); |
} |
} |
} |
239,4 → 249,66 |
{ |
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.itru.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(); |
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()); |
} |
} |
/it-ru/trunk/src/ak/itru/core/taglib/ExtendedLinkTag.java |
---|
0,0 → 1,230 |
// based on Jakarta Struts |
package ak.itru.core.taglib; |
import java.net.MalformedURLException; |
import java.util.Map; |
import java.util.HashMap; |
import javax.servlet.jsp.JspException; |
import org.apache.struts.util.RequestUtils; |
import org.apache.struts.taglib.logic.IterateTag; |
import ak.backpath.taglib.ForwardLinkTag; |
public class ExtendedLinkTag |
extends ForwardLinkTag |
{ |
protected String paramId2 = null; |
public String getParamId2() |
{ |
return this.paramId2; |
} |
public void setParamId2(String paramId2) |
{ |
this.paramId2 = paramId2; |
} |
protected String paramName2 = null; |
public String getParamName2() |
{ |
return this.paramName2; |
} |
public void setParamName2(String paramName2) |
{ |
this.paramName2 = paramName2; |
} |
protected String paramProperty2 = null; |
public String getParamProperty2() |
{ |
return this.paramProperty2; |
} |
public void setParamProperty2(String paramProperty2) |
{ |
this.paramProperty2 = paramProperty2; |
} |
protected String paramScope2 = null; |
public String getParamScope2() |
{ |
return this.paramScope2; |
} |
public void setParamScope2(String paramScope2) |
{ |
this.paramScope2 = paramScope2; |
} |
protected String paramId3 = null; |
public String getParamId3() |
{ |
return this.paramId3; |
} |
public void setParamId3(String paramId3) |
{ |
this.paramId3 = paramId3; |
} |
protected String paramName3 = null; |
public String getParamName3() |
{ |
return this.paramName3; |
} |
public void setParamName3(String paramName3) |
{ |
this.paramName3 = paramName3; |
} |
protected String paramProperty3 = null; |
public String getParamProperty3() |
{ |
return this.paramProperty3; |
} |
public void setParamProperty3(String paramProperty3) |
{ |
this.paramProperty3 = paramProperty3; |
} |
protected String paramScope3 = null; |
public String getParamScope3() |
{ |
return this.paramScope3; |
} |
public void setParamScope3(String paramScope3) |
{ |
this.paramScope3 = paramScope3; |
} |
protected String paramId4 = null; |
public String getParamId4() |
{ |
return this.paramId4; |
} |
public void setParamId4(String paramId4) |
{ |
this.paramId4 = paramId4; |
} |
protected String paramName4 = null; |
public String getParamName4() |
{ |
return this.paramName4; |
} |
public void setParamName4(String paramName4) |
{ |
this.paramName4 = paramName4; |
} |
protected String paramProperty4 = null; |
public String getParamProperty4() |
{ |
return this.paramProperty4; |
} |
public void setParamProperty4(String paramProperty4) |
{ |
this.paramProperty4 = paramProperty4; |
} |
protected String paramScope4 = null; |
public String getParamScope4() |
{ |
return this.paramScope4; |
} |
public void setParamScope4(String paramScope4) |
{ |
this.paramScope4 = paramScope4; |
} |
public void release() |
{ |
super.release(); |
paramId2 = null; |
paramName2 = null; |
paramProperty2 = null; |
paramScope2 = null; |
paramId3 = null; |
paramName3 = null; |
paramProperty3 = null; |
paramScope3 = null; |
paramId4 = null; |
paramName4 = null; |
paramProperty4 = null; |
paramScope4 = null; |
} |
protected String calculateURL() |
throws JspException |
{ |
Map params = RequestUtils.computeParameters(pageContext, paramId, paramName, paramProperty, paramScope, |
name, property, scope, transaction); |
Map params2 = RequestUtils.computeParameters(pageContext, paramId2, paramName2, paramProperty2, paramScope2, |
null, null, null, false); |
if(params2 != null) params.putAll(params2); |
Map params3 = RequestUtils.computeParameters(pageContext, paramId3, paramName3, paramProperty3, paramScope3, |
null, null, null, false); |
if(params3 != null) params.putAll(params3); |
Map params4 = RequestUtils.computeParameters(pageContext, paramId4, paramName4, paramProperty4, paramScope4, |
null, null, null, false); |
if(params4 != null) params.putAll(params4); |
if(indexed) { |
IterateTag iterateTag = (IterateTag) findAncestorWithClass(this, IterateTag.class); |
if(iterateTag == null) { |
JspException e = new JspException(messages.getMessage("indexed.noEnclosingIterate")); |
RequestUtils.saveException(pageContext, e); |
throw e; |
} |
if(params == null) params = new HashMap(); |
if(indexId != null) |
params.put(indexId, Integer.toString(iterateTag.getIndex())); |
else |
params.put("index", Integer.toString(iterateTag.getIndex())); |
} |
String url = null; |
try { |
url = RequestUtils.computeURL(pageContext, forward, href, page, action, params, anchor, false); |
} |
catch(MalformedURLException ex) { |
RequestUtils.saveException(pageContext, ex); |
throw new JspException(messages.getMessage("rewrite.url", ex.toString())); |
} |
if(url == null) return null; |
// add backpath |
String forwardParams = findBackPath().getForwardParams(); |
if(forwardParams == null) return url; |
if(url.indexOf("?") > 0) |
return url + "&" + backPathParam + "=" + forwardParams; |
else |
return url + "?" + backPathParam + "=" + forwardParams; |
} |
} |
/it-ru/trunk/src/ak/itru/core/form/EventApartmentBean.java |
---|
0,0 → 1,65 |
package ak.itru.core.form; |
import ak.itru.util.StringConverter; |
import ak.itru.core.model.EventApartment; |
import ak.itru.core.model.Apartment; |
public final class EventApartmentBean |
{ |
private String apartmentId; |
private String distance; |
private String comment; |
private Boolean selected; |
public EventApartmentBean() |
{ |
} |
public EventApartmentBean(Apartment apartment, EventApartment info) |
{ |
this.apartmentId = StringConverter.toString(apartment.getId()); |
this.distance = (info == null) ? null : StringConverter.toNumber(info.getDistance()); |
this.comment = (info == null) ? null : info.getComment(); |
this.selected = Boolean.valueOf(info != null); |
} |
public String getApartmentId() |
{ |
return apartmentId; |
} |
public void setApartmentId(String apartmentId) |
{ |
this.apartmentId = apartmentId; |
} |
public String getDistance() |
{ |
return distance; |
} |
public void setDistance(String distance) |
{ |
this.distance = distance; |
} |
public String getComment() |
{ |
return comment; |
} |
public void setComment(String comment) |
{ |
this.comment = comment; |
} |
public Boolean getSelected() |
{ |
return selected; |
} |
public void setSelected(Boolean selected) |
{ |
this.selected = selected; |
} |
} |
/it-ru/trunk/src/ak/itru/util/Validator.java |
---|
16,6 → 16,26 |
public class Validator |
{ |
public static BigDecimal validateNumber(Object bean, ValidatorAction va, Field field, |
ActionErrors errors, HttpServletRequest request) |
{ |
String value = null; |
if((bean == null) || (bean instanceof String)) |
value = (String)bean; |
else |
value = ValidatorUtil.getValueAsString(bean, field.getProperty()); |
if(value == null || "".equals(value)) return null; |
try { |
return new BigDecimal(NumberFormat.getInstance().parse(value).doubleValue()); |
} |
catch(ParseException ex) { |
errors.add(field.getKey(), Resources.getActionError(request, va, field)); |
return null; |
} |
} |
public static BigDecimal validateCurrency(Object bean, ValidatorAction va, Field field, |
ActionErrors errors, HttpServletRequest request) |
{ |
/it-ru/trunk/src/ak/itru/util/StringConverter.java |
---|
47,6 → 47,22 |
return (s == null) ? null : new Integer(s); |
} |
public static BigDecimal parseNumber(Object o) |
throws NumberFormatException, ParseException |
{ |
String s = preparse(o); |
return (s == null) |
? null : new BigDecimal(NumberFormat.getInstance().parse(s).doubleValue()); |
} |
public static String toNumber(Number n) |
{ |
if(n == null) |
return null; |
else |
return (new DecimalFormat("0")).format(n); |
} |
public static BigDecimal parseCurrency(Object o) |
throws NumberFormatException, ParseException |
{ |
78,6 → 94,21 |
return DateFormat.getDateInstance().format(d); |
} |
public static Date parseDateTime(Object o) |
throws NumberFormatException, ParseException |
{ |
String s = preparse(o); |
return (s == null) ? null : DateFormat.getDateTimeInstance().parse(s); |
} |
public static String toDateTime(Date d) |
{ |
if(d == null) |
return null; |
else |
return DateFormat.getDateTimeInstance().format(d); |
} |
public static String toString(Object o) |
{ |
if(o == null) |