Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 12 → Rev 13

/kickup/trunk/src/ak/kickup/core/action/AdminParticipantAction.java
0,0 → 1,156
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 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");
}
}
}