/it-ru/trunk/src/ak/kickup/core/action/AdminApartmentAction.java |
---|
0,0 → 1,102 |
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.Apartment; |
import ak.kickup.core.model.ApartmentManager; |
public final class AdminApartmentAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
if("list".equals(mapping.getParameter())) { |
List list = new ArrayList(ApartmentManager.getInstance().listApartments()); |
Collections.sort(list, ApartmentManager.NAME_COMPARATOR); |
request.setAttribute("apartments", list); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long apartmentId = StringConverter.parseLong(theForm.get("id")); |
Apartment apartment; |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "ApartmentEditForm"); |
if(apartmentId == null) { |
apartment = ApartmentManager.getInstance().create(); |
} |
else { |
apartment = ApartmentManager.getInstance().get(apartmentId); |
showForm.set("name", apartment.getName()); |
showForm.set("address", apartment.getAddress()); |
showForm.set("price", StringConverter.toCurrency(apartment.getPrice())); |
showForm.set("url", apartment.getUrl()); |
showForm.set("comment", apartment.getComment()); |
} |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long apartmentId = StringConverter.parseLong(theForm.get("id")); |
Apartment apartment = ApartmentManager.getInstance().get(apartmentId); |
ApartmentManager.getInstance().delete(apartment); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long apartmentId = StringConverter.parseLong(theForm.get("id")); |
Apartment apartment; |
if(apartmentId == null) { |
apartment = ApartmentManager.getInstance().create(); |
} |
else { |
apartment = ApartmentManager.getInstance().get(apartmentId); |
} |
String name = (String)theForm.get("name"); |
if(ApartmentManager.getInstance().nameExists(apartment, name)) { |
throw new UserException("ak.kickup.core.apartment.name.nonunique"); |
} |
apartment.setName(name); |
apartment.setAddress((String)theForm.get("address")); |
apartment.setPrice(StringConverter.parseCurrency(theForm.get("price"))); |
apartment.setUrl((String)theForm.get("url")); |
apartment.setComment((String)theForm.get("comment")); |
ApartmentManager.getInstance().save(apartment); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
} |
/it-ru/trunk/src/ak/kickup/core/action/ObjectList.java |
---|
0,0 → 1,23 |
package ak.kickup.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/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"); |
} |
} |
} |
/it-ru/trunk/src/ak/kickup/core/action/AdminEventAction.java |
---|
0,0 → 1,221 |
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; |
import ak.kickup.core.model.EventAct; |
import ak.kickup.core.model.EventApartment; |
import ak.kickup.core.model.Act; |
import ak.kickup.core.model.ActManager; |
import ak.kickup.core.model.Apartment; |
import ak.kickup.core.model.ApartmentManager; |
import ak.kickup.core.form.EventActBean; |
import ak.kickup.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 |
{ |
if("list".equals(mapping.getParameter())) { |
List list = new ArrayList(EventManager.getInstance().listEvents(false)); |
Collections.sort(list, EventManager.START_COMPARATOR); |
request.setAttribute("events", list); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long eventId = StringConverter.parseLong(theForm.get("id")); |
Event event; |
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) { |
event = EventManager.getInstance().create(); |
showForm.set("enabled", Boolean.TRUE); |
} |
else { |
event = EventManager.getInstance().get(eventId); |
showForm.set("name", event.getName()); |
showForm.set("place", event.getPlace()); |
showForm.set("address", event.getAddress()); |
showForm.set("transport", event.getTransportDesc()); |
showForm.set("start", StringConverter.toDate(event.getStart())); |
showForm.set("stop", StringConverter.toDate(event.getStop())); |
showForm.set("lastreg", StringConverter.toDate(event.getLastRegister())); |
showForm.set("lastunreg", StringConverter.toDate(event.getLastUnregister())); |
showForm.set("price", StringConverter.toCurrency(event.getPrice())); |
showForm.set("account", event.getMoneyAccount()); |
showForm.set("enabled", event.getEnabled()); |
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++) { |
Act act = (Act)acts.get(i); |
a[i] = new EventActBean(act, (event == null) ? null : event.getAct(act.getId())); |
} |
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())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long eventId = StringConverter.parseLong(theForm.get("id")); |
Event event = EventManager.getInstance().get(eventId); |
EventManager.getInstance().delete(event); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long eventId = StringConverter.parseLong(theForm.get("id")); |
Event event; |
if(eventId == null) { |
event = EventManager.getInstance().create(); |
} |
else { |
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.kickup.core.event.name.nonunique"); |
} |
event.setName(name); |
// others |
event.setPlace((String)theForm.get("place")); |
event.setAddress((String)theForm.get("address")); |
event.setTransportDesc((String)theForm.get("transport")); |
event.setStart(StringConverter.parseDate(theForm.get("start"))); |
event.setStop(StringConverter.parseDate(theForm.get("stop"))); |
event.setLastRegister(StringConverter.parseDate(theForm.get("lastreg"))); |
event.setLastUnregister(StringConverter.parseDate(theForm.get("lastunreg"))); |
event.setPrice(StringConverter.parseCurrency(theForm.get("price"))); |
event.setMoneyAccount((String)theForm.get("account")); |
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; |
} |
else { |
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/kickup/core/action/UserExceptionHandler.java |
---|
0,0 → 1,62 |
package ak.kickup.core.action; |
import javax.servlet.ServletException; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
import org.apache.struts.Globals; |
import org.apache.struts.action.ActionError; |
import org.apache.struts.action.ActionErrors; |
import org.apache.struts.action.ActionMessages; |
import org.apache.struts.action.ExceptionHandler; |
import org.apache.struts.action.ActionMapping; |
import org.apache.struts.action.ActionForm; |
import org.apache.struts.action.ActionForward; |
import org.apache.struts.config.ExceptionConfig; |
import org.apache.log4j.Logger; |
import ak.strutsx.ErrorHandlerX; |
import ak.kickup.util.UserException; |
import ak.kickup.util.FormException; |
public final class UserExceptionHandler |
extends ExceptionHandler |
{ |
private static final Logger logger = Logger.getLogger(UserExceptionHandler.class); |
public ActionForward execute(Exception ex, ExceptionConfig config, |
ActionMapping mapping, ActionForm formInstance, |
HttpServletRequest request, HttpServletResponse response) |
throws ServletException |
{ |
if(!(ex instanceof UserException)) |
throw new ServletException("Unknown type of exception: " + ex.getClass()); |
UserException userEx = (UserException)ex; |
logger.info("begin exception handle:" + userEx.getMessage()); |
// try to get property for this exception if any |
String property = ActionMessages.GLOBAL_MESSAGE; |
if(userEx instanceof FormException) { |
FormException formEx = (FormException)userEx; |
if(formEx.getProperty() != null) |
property = formEx.getProperty(); |
} |
// create new error message |
ActionErrors errors = (ActionErrors)request.getAttribute(Globals.ERROR_KEY); |
if(errors == null) { |
errors = new ActionErrors(); |
request.setAttribute(Globals.ERROR_KEY, errors); |
} |
errors.add(property, new ActionError(userEx.getMessage(), userEx.getValues())); |
// find forward |
if(mapping.getInput() == null) |
return mapping.findForward("error"); |
else |
return mapping.getInputForward(); |
} |
} |
/it-ru/trunk/src/ak/kickup/core/action/AdminActAction.java |
---|
0,0 → 1,96 |
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.Act; |
import ak.kickup.core.model.ActManager; |
public final class AdminActAction |
extends Action |
{ |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
HttpServletRequest request, HttpServletResponse response) |
throws Exception |
{ |
if("list".equals(mapping.getParameter())) { |
List list = new ArrayList(ActManager.getInstance().listActs()); |
Collections.sort(list, ActManager.NAME_COMPARATOR); |
request.setAttribute("acts", list); |
return mapping.findForward("default"); |
} |
else if("edit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long actId = StringConverter.parseLong(theForm.get("id")); |
Act act; |
DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm( |
this, request, "ActEditForm"); |
if(actId == null) { |
act = ActManager.getInstance().create(); |
} |
else { |
act = ActManager.getInstance().get(actId); |
showForm.set("name", act.getName()); |
showForm.set("comment", act.getComment()); |
} |
return mapping.findForward("default"); |
} |
else if("delete".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long actId = StringConverter.parseLong(theForm.get("id")); |
Act act = ActManager.getInstance().get(actId); |
ActManager.getInstance().delete(act); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long actId = StringConverter.parseLong(theForm.get("id")); |
Act act; |
if(actId == null) { |
act = ActManager.getInstance().create(); |
} |
else { |
act = ActManager.getInstance().get(actId); |
} |
String name = (String)theForm.get("name"); |
if(ActManager.getInstance().nameExists(act, name)) { |
throw new UserException("ak.kickup.core.act.name.nonunique"); |
} |
act.setName(name); |
act.setComment((String)theForm.get("comment")); |
ActManager.getInstance().save(act); |
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
else { |
throw new Exception("unknown mapping parameter"); |
} |
} |
} |