public ActionForward defaultMethod(ActionMapping am, ActionForm af, HttpServletRequest req, HttpServletResponse res) {
//we use transactions here
//super.defaultMethod(am, af, req, res);
ApplyLabelToGameForm form=(ApplyLabelToGameForm)af;
//Apply the label
if (req.getParameter("cancelChangesSubmit")!=null) {
form.reset();
return am.findForward("cancel");
}
GameHiber g=GameDao.findGameHiber(Long.parseLong(req.getParameter("game")), session);
if (!SecurityCenter.canIEditGame(webUser.getId(), g.getId(), session)){
MessageBean.setMyMessage(req, ("Error: Insufficient privileges."));
form.reset();
return am.findForward("ok");
}
if (req.getParameter("removeLabel")!=null) {
//remove label
long labelId=Long.parseLong(req.getParameter("removeLabel"));
GameLabelHiber glh=GameLabelDao.findGameLabel(labelId, session);
g.getGameLabels().remove(glh);
GameDao.updateGame(g,session);
} else {
//apply label
if (req.getParameter("ApplyNewOne")!=null) {
//create new label
GameLabelHiber glh=new GameLabelHiber();
glh.setCreator(webUser.getId());
glh.setDescription(form.getDescription());
glh.setName(form.getName());
glh.setShared(form.isShared());
GameLabelDao.persistGameLabel(glh,session);
g.getGameLabels().add(glh);
GameDao.updateGame(g,session);
} else {
//apply existing label
GameLabelHiber glh=GameLabelDao.findGameLabel(Long.parseLong(req.getParameter("labelId")), session);
g.getGameLabels().add(glh);
GameDao.updateGame(g,session);
}
}
form.reset();
return am.findForward("ok");
}