package hirondelle.fish.main.rsvp;
import hirondelle.web4j.action.ActionTemplateShowAndApply;
import hirondelle.web4j.action.ResponsePage;
import hirondelle.web4j.database.SqlId;
import hirondelle.web4j.model.AppException;
import hirondelle.web4j.model.Id;
import hirondelle.web4j.model.ModelCtorException;
import hirondelle.web4j.model.ModelFromRequest;
import hirondelle.web4j.request.RequestParameter;
import hirondelle.web4j.request.RequestParser;
import hirondelle.web4j.util.Util;
import java.util.logging.Logger;
public final class RsvpUpdate extends ActionTemplateShowAndApply {
public RsvpUpdate(RequestParser aRequestParser){
super(FORWARD, REDIRECT, aRequestParser);
fVisitId = aRequestParser.toId(RsvpAdd.VISIT_ID);
fMemberId = aRequestParser.toId(RsvpAdd.MEMBER_ID);
fRsvpDAO = new RsvpDAO();
fLogger.fine("VisitId : " + Util.quote(fVisitId) + ", MemberId: " + Util.quote(fMemberId) );
}
public static final SqlId RSVP_FETCH_FOR_CHANGE = new SqlId("RSVP_FETCH_FOR_CHANGE");
public static final SqlId RSVP_CHANGE = new SqlId("RSVP_CHANGE");
public static final RequestParameter VISIT_ID = RsvpAdd.VISIT_ID;
public static final RequestParameter MEMBER_ID = RsvpAdd.MEMBER_ID;
public static final RequestParameter RESPONSE = RsvpAdd.RESPONSE;
protected void show() throws AppException {
fRsvp = fRsvpDAO.fetchForChange(fVisitId, fMemberId);
fLogger.fine("Fetched for change : " + fRsvp);
addToRequest(ITEM_FOR_EDIT, fRsvp);
}
protected void validateUserInput() throws AppException {
try {
ModelFromRequest builder = new ModelFromRequest(getRequestParser());
fRsvp = builder.build(Rsvp.class, VISIT_ID, MEMBER_ID, null, RESPONSE);
if ( fRsvp.getResponse() == null ) {
addError("Please make a selection.");
}
}
catch (ModelCtorException ex){
addError(ex);
}
}
protected void apply() throws AppException {
fRsvpDAO.update(fRsvp);
}
private Id fVisitId;
private Id fMemberId;
private Rsvp fRsvp;
private RsvpDAO fRsvpDAO;
private static final ResponsePage FORWARD = new ResponsePage("Rsvp Update", "RsvpUpdate.jsp", RsvpUpdate.class);
private static final ResponsePage REDIRECT = new ResponsePage("RsvpShow.show");
private static final Logger fLogger = Util.getLogger(RsvpUpdate.class);
}