public ActionForward defaultMethod(ActionMapping am, ActionForm af, HttpServletRequest req, HttpServletResponse res) {
//we use transactions here
//super.defaultMethod(am, af, req, res);
AddNewGameForm form=(AddNewGameForm)af;
form.setMyUserId(webUser.getId());
if (req.getParameter("cancelChangesSubmit")!=null) {
form.reset();
return am.findForward("cancel");
}
GameHiber likeGame=null;
if (form.isLikeMe()) {
likeGame=GameDao.findGameHiber(form.getLikeId(),session);
if (!SecurityCenter.canICopyGame(webUser.getId(), likeGame)) {
MessageBean.setMyMessage(req, ("Error: Insufficient privileges."));
form.reset();
return am.findForward("ok");
}
}
GameHiber g=null;
if (form.isModifyMe()) {
//modify existing
g=GameDao.findGameHiber(form.getModifyId(),session);
if (!SecurityCenter.canIEditGame(webUser.getId(), g.getId(),session)) {
MessageBean.setMyMessage(req, ("Error: Insufficient privileges."));
form.reset();
return am.findForward("ok");
}
} else {
//add new
g=new GameHiber();
g.setCreator(webUser.getId());
if (!SecurityCenter.canICreateGame(webUser.getId(),session)) {
MessageBean.setMyMessage(req, ("Error: Insufficient privileges."));
form.reset();
return am.findForward("ok");
}
}
g.setName(form.getName());
g.setDescription(form.getDescription());
g.setInstructions(form.getInstructions());
g.setDC_contributor(form.getDC_contributor());
g.setDC_coverage(form.getDC_coverage());
g.setDC_creator(form.getDC_creator());
g.setDC_date(form.getDC_date());
g.setDC_description(form.getDC_description());
g.setDC_format(form.getDC_format());
g.setDC_identifier(form.getDC_identifier());
g.setDC_language(form.getDC_language());
g.setDC_publisher(form.getDC_publisher());
g.setDC_relation(form.getDC_relation());
g.setDC_rights(form.getDC_rights());
g.setDC_source(form.getDC_source());
g.setDC_subject(form.getDC_subject());
g.setDC_title(form.getDC_title());
g.setDC_type(form.getDC_type());
g.setDC_contributor_manual(req.getParameter("DC_contributor_manual")!=null);
g.setDC_coverage_manual(req.getParameter("DC_coverage_manual")!=null);
g.setDC_creator_manual(req.getParameter("DC_creator_manual")!=null);
g.setDC_date_manual(req.getParameter("DC_date_manual")!=null);
g.setDC_description_manual(req.getParameter("DC_description_manual")!=null);
g.setDC_format_manual(req.getParameter("DC_format_manual")!=null);
g.setDC_identifier_manual(req.getParameter("DC_identifier_manual")!=null);
g.setDC_language_manual(req.getParameter("DC_language_manual")!=null);
g.setDC_publisher_manual(req.getParameter("DC_publisher_manual")!=null);
g.setDC_relation_manual(req.getParameter("DC_relation_manual")!=null);
g.setDC_rights_manual(req.getParameter("DC_rights_manual")!=null);
g.setDC_source_manual(req.getParameter("DC_source_manual")!=null);
g.setDC_subject_manual(req.getParameter("DC_subject_manual")!=null);
g.setDC_title_manual(req.getParameter("DC_title_manual")!=null);
g.setDC_type_manual(req.getParameter("DC_type_manual")!=null);
boolean imageset=false;
if (form.getLogo().getFileName()!=null)
if (!form.getLogo().getFileName().equals("")) {
try {
g.setLogo(Hibernate.createBlob(form.getLogo().getInputStream()));
g.setLogoType(form.getLogo().getContentType());
imageset=true;
} catch (Exception e) {
// TODO Wo image
}
}
g.setBasedOnTemplate(GameTemplateDao.findGameTemplate(form.getTemplateToUse(),session));
if (form.isModifyMe()) {
GameDao.updateGame(g,session);
MessageBean.setMyMessage(req, "Game updated successfuly.");
} else {
boolean createAppAndBlog=false;
if (form.isLikeMe()) {
g.setCreator(webUser.getId());
g.setRemoved(req.getParameter("createEnabled")==null);
g.setAvailableFrom(likeGame.getAvailableFrom());
g.setAvailableTo(likeGame.getAvailableTo());
g.setMaksimumScore(likeGame.getMaksimumScore());
if (!imageset) {
//copy image if needed
if (likeGame.getLogo()!=null){
try {
g.setLogoType(likeGame.getLogoType());
g.setLogo(Hibernate.createBlob(likeGame.getLogo().getBinaryStream()));
} catch (Exception e) {
// TODO Wo handle exception
}
}
}
//TODO Wo when duplicating game, duplicate content also...
g.setCreationTime(new GregorianCalendar());
g.setStatus(Game.STATUS_IN_PREPARATION);
g.setMaxScore("Game not played yet.");
g.setAvgScore("Game not played yet.");
g.setSecuritySummary("Advanced security not set.");
g.setMaksimumScore(-1);
} else {
//adding new one
g.setCreator(webUser.getId());
g.setRemoved(req.getParameter("createEnabled")==null);
g.setCreationTime(new GregorianCalendar());
g.setStatus(Game.STATUS_IN_PREPARATION);
g.setMaxScore("Game not played yet.");
g.setAvgScore("Game not played yet.");
g.setSecuritySummary("Advanced security not set.");
g.setMaksimumScore(-1);
createAppAndBlog=true;
}
GameDao.persistGame(g,session);
if (createAppAndBlog) {
//create new blog & application
DbManager dbm=new DbManager(locale,session);
//UserManager um=new UserManager(locale,session);
// for now, all professors and students have permissions on blog...
// ArrayList<Role> rols=new ArrayList<Role>();
// rols.add(um.getRole("teacher"));
// rols.add(um.getRole("student"));
g.setApplication(dbm.createApplication("Game("+g.getId()+"): "+g.getName()));
// g.setBlog(dbm.createBlog("Game: "+g.getName(), rols, rols, rols));
String[] labels = new String[] {g.getBasedOnTemplate().getGameType()};
g.setArticle(dbm.createGameBlogArticle(g, webUser, labels));
GameDao.persistGame(g,session);
}
//allow all to creator
GameSecurityDao.allow(Game.asGameObject(g), GameSecurity.TARGET_TYPE_USER, webUser.getId(), GameSecurityDao.SECURITY_TYPE_ALL,req,session);
MessageBean.setMyMessage(req, "Game created successfuly.");
}
form.reset();
if (req.getParameter("applyAndGoToEditing")!=null) {
try {
res.sendRedirect("auth"+g.getBasedOnTemplate().getAuthoringHandlerCode()+".do?id="+g.getId()+"&startAuthoring=1");
} catch (Exception e) {