Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 15 → Rev 16

/kickup/trunk/src/ak/kickup/core/action/EventAction.java
0,0 → 1,60
package ak.kickup.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.kickup.util.StringConverter;
import ak.kickup.util.UserException;
import ak.kickup.core.model.Event;
import ak.kickup.core.model.EventManager;
 
public final class EventAction
extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
if("list".equals(mapping.getParameter())) {
List list = new ArrayList(EventManager.getInstance().listEvents(true));
Collections.sort(list, EventManager.START_COMPARATOR);
request.setAttribute("events", list);
return mapping.findForward("default");
}
else if("show".equals(mapping.getParameter())) {
DynaActionForm theForm = (DynaActionForm)form;
Long eventId = StringConverter.parseLong(theForm.get("id"));
Event event = EventManager.getInstance().get(eventId, true);
List acts = new ArrayList(event.getActCollection());
List apartments = new ArrayList(event.getApartmentCollection());
 
request.setAttribute("event", event);
Collections.sort(acts, EventManager.ACT_NAME_COMPARATOR);
request.setAttribute("acts", acts);
Collections.sort(apartments, EventManager.APARTMENT_NAME_COMPARATOR);
request.setAttribute("apartments", apartments);
 
return mapping.findForward("default");
}
else {
throw new Exception("unknown mapping parameter");
}
}
}
/kickup/trunk/src/ak/kickup/core/action/AdminParticipantAction.java
38,7 → 38,7
if("submit".equals(mapping.getParameter())) {
DynaActionForm theForm = (DynaActionForm)form;
Long eventId = StringConverter.parseLong(theForm.get("event"));
Event event = EventManager.getInstance().get(eventId);
Event event = EventManager.getInstance().get(eventId, false);
Long participantId = StringConverter.parseLong(theForm.get("id"));
Participant participant;
if(participantId == null) {
59,8 → 59,8
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));
Event event = EventManager.getInstance().get(eventId, false);
List list = new ArrayList(event.getParticipantCollection());
Collections.sort(list, ParticipantManager.NICK_COMPARATOR);
request.setAttribute("participants", list);
request.setAttribute("event", event);
69,7 → 69,7
else if("edit".equals(mapping.getParameter())) {
DynaActionForm theForm = (DynaActionForm)form;
Long eventId = StringConverter.parseLong(theForm.get("event"));
Event event = EventManager.getInstance().get(eventId);
Event event = EventManager.getInstance().get(eventId, false);
Long participantId = StringConverter.parseLong(theForm.get("id"));
Participant participant;
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
118,7 → 118,7
 
if(participantId == null) {
Long eventId = StringConverter.parseLong(theForm.get("event"));
Event event = EventManager.getInstance().get(eventId);
Event event = EventManager.getInstance().get(eventId, false);
 
participant = ParticipantManager.getInstance().create();
participant.setIdent(ParticipantManager.getInstance().generateIdent());
/kickup/trunk/src/ak/kickup/core/action/AdminEventAction.java
70,7 → 70,7
showForm.set("enabled", Boolean.TRUE);
}
else {
event = EventManager.getInstance().get(eventId);
event = EventManager.getInstance().get(eventId, false);
showForm.set("name", event.getName());
showForm.set("place", event.getPlace());
showForm.set("address", event.getAddress());
110,7 → 110,7
else if("delete".equals(mapping.getParameter())) {
DynaActionForm theForm = (DynaActionForm)form;
Long eventId = StringConverter.parseLong(theForm.get("id"));
Event event = EventManager.getInstance().get(eventId);
Event event = EventManager.getInstance().get(eventId, false);
 
EventManager.getInstance().delete(event);
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
125,14 → 125,12
event = EventManager.getInstance().create();
}
else {
event = EventManager.getInstance().get(eventId);
event = EventManager.getInstance().get(eventId, false);
}
 
// 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);
155,8 → 153,6
// 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);
172,7 → 168,15
eventApartment.setApartment(apartment);
event.addApartment(eventApartment);
}
eventApartment.setDistance(StringConverter.parseNumber(apartments[i].getDistance()));
 
try {
eventApartment.setDistance(StringConverter.parseNumber(apartments[i].getDistance()));
}
catch(Exception ex) { // the distance cannot be parsed
initLists(request);
throw new UserException("ak.kickup.core.event.edit.distance.wrong");
}
 
eventApartment.setComment(apartments[i].getComment());
}
}
180,6 → 184,7
// name
String name = (String)theForm.get("name");
if(EventManager.getInstance().nameExists(event, name)) {
initLists(request);
throw new UserException("ak.kickup.core.event.name.nonunique");
}
event.setName(name);
/kickup/trunk/src/ak/kickup/core/action/ApartmentAction.java
0,0 → 1,46
package ak.kickup.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.kickup.util.StringConverter;
import ak.kickup.core.model.Event;
import ak.kickup.core.model.EventManager;
import ak.kickup.core.model.Participant;
import ak.kickup.core.model.ParticipantManager;
 
public final class ApartmentAction
extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
DynaActionForm theForm = (DynaActionForm)form;
Long eventId = StringConverter.parseLong(theForm.get("event"));
Event event = EventManager.getInstance().get(eventId, true);
List list = new ArrayList(ParticipantManager.getInstance().listFreeSleep(event));
List apartments = new ArrayList(event.getApartmentCollection());
 
Collections.sort(list, ParticipantManager.NICK_COMPARATOR);
request.setAttribute("participants", list);
request.setAttribute("event", event);
Collections.sort(apartments, EventManager.APARTMENT_NAME_COMPARATOR);
request.setAttribute("apartments", apartments);
 
return mapping.findForward("default");
}
}
/kickup/trunk/src/ak/kickup/core/action/TransportAction.java
0,0 → 1,41
package ak.kickup.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.kickup.util.StringConverter;
import ak.kickup.core.model.Event;
import ak.kickup.core.model.EventManager;
import ak.kickup.core.model.Participant;
import ak.kickup.core.model.ParticipantManager;
 
public final class TransportAction
extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
DynaActionForm theForm = (DynaActionForm)form;
Long eventId = StringConverter.parseLong(theForm.get("event"));
Event event = EventManager.getInstance().get(eventId, true);
List list = new ArrayList(ParticipantManager.getInstance().listFreeTransport(event));
Collections.sort(list, ParticipantManager.NICK_COMPARATOR);
request.setAttribute("participants", list);
request.setAttribute("event", event);
return mapping.findForward("default");
}
}
/kickup/trunk/src/ak/kickup/core/action/ParticipantAction.java
0,0 → 1,160
package ak.kickup.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.kickup.util.StringConverter;
import ak.kickup.util.UserException;
import ak.kickup.core.model.Participant;
import ak.kickup.core.model.ParticipantManager;
import ak.kickup.core.model.Event;
import ak.kickup.core.model.EventManager;
 
public final class ParticipantAction
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, true);
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, true);
List list = new ArrayList(event.getParticipantCollection());
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, true);
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, true);
 
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");
}
}
}
/kickup/trunk/src/ak/kickup/core/CoreResources.properties
10,6 → 10,7
ak.kickup.core.event.edit.lastreg.wrong=Дата окончания регистрации должна быть в виде ДД.ММ.ГГГГ
ak.kickup.core.event.edit.lastunreg.wrong=Последний срок отказа должен быть в виде ДД.ММ.ГГГГ
ak.kickup.core.event.edit.price.wrong=Цена должна быть числом, например 12,35
ak.kickup.core.event.edit.distance.wrong=Расстояние должно быть числом, например 4,5
ak.kickup.core.act.edit.id.wrong=Неизвестное мероприятие, выбирайти из списка
ak.kickup.core.act.edit.name.required=Название обязательно
ak.kickup.core.apartment.edit.id.wrong=Неизвестная гостиница, выбирайти из списка
/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
/kickup/trunk/src/ak/kickup/core/taglib/ExtendedWriteTag.java
0,0 → 1,48
// based on Jakarta Struts
package ak.kickup.core.taglib;
 
import javax.servlet.jsp.JspException;
import org.apache.struts.util.RequestUtils;
import org.apache.struts.util.ResponseUtils;
import org.apache.struts.taglib.bean.WriteTag;
 
public class ExtendedWriteTag extends WriteTag
{
protected boolean filterBr = false;
 
public boolean getFilterBr()
{
return filterBr;
}
 
public void setFilterBr(boolean filterBr)
{
this.filterBr = filterBr;
}
 
public int doStartTag()
throws JspException
{
if(ignore) {
if(RequestUtils.lookup(pageContext, name, scope) == null)
return SKIP_BODY;
}
 
Object value = RequestUtils.lookup(pageContext, name, property, scope);
if(value == null) return SKIP_BODY;
 
String output = formatValue(value);
if(filter) output = ResponseUtils.filter(output);
if(filterBr) output = output.replaceAll("\n", "<br>");
 
ResponseUtils.write(pageContext, output);
 
return SKIP_BODY;
}
 
public void release()
{
super.release();
filterBr = false;
}
}
/kickup/trunk/src/ak/kickup/util/StringConverter.java
60,7 → 60,7
if(n == null)
return null;
else
return (new DecimalFormat("0")).format(n);
return (new DecimalFormat()).format(n);
}
 
public static BigDecimal parseCurrency(Object o)