@Override
public ActionForward defaultMethod(ActionMapping am, ActionForm af, HttpServletRequest req, HttpServletResponse res) {
//we use transactions here
//super.defaultMethod(am, af, req, res);
AOGSimulationForm form=(AOGSimulationForm)af;
form.setMyUserId(webUser.getId());
if (req.getParameter("cancelChangesSubmit")!=null) {
form.reset();
return am.findForward("cancel");
}
long id=Long.parseLong(req.getParameter("id"));
long lid=Long.parseLong(req.getParameter("levelId"));
long cid=Long.parseLong(req.getParameter("cardId"));
GameHiber g=GameDao.findGameHiber(id,session);
form.setGh(g);
form.setG(GameDao.findGame(id,session));
AOGGameHiber ag=AOGGameDao.findGameHiberForGame(g.getId(), session);
form.setAh(ag);
AOGGameLevelHiber level=AOGGameLevelDao.findGameLevelHiber(lid, session);
form.setLh(level);
AOGGameCardHiber card=AOGGameCardDao.findGameCardHiber(cid, session);
form.setCh(card);
//insert new picture
if (req.getParameter("newPictureSubmit")!=null){
AOGGamePicturesHiber newOne=new AOGGamePicturesHiber();
if (form.getPicture().getFileName()!=null)
if (!form.getPicture().getFileName().equals("")) {
try {
newOne.setData(Hibernate.createBlob(form.getPicture().getInputStream()));
newOne.setDataType(form.getPicture().getContentType());
newOne.setPictureName(req.getParameter("pictureName"));
} catch (Exception e) {
}
}
session.persist(newOne);
ag.getPictures().add(newOne);
AOGGameDao.updateGame(ag, session);
}
//delete picture?
if (req.getParameter("deletePicture")!=null){
String deletePicture=req.getParameter("deletePicture");
long pictureId=Long.parseLong(deletePicture);
Set<AOGGamePicturesHiber> pctrs=ag.getPictures();
for (Iterator iterator = pctrs.iterator(); iterator.hasNext();) {
AOGGamePicturesHiber l = (AOGGamePicturesHiber) iterator.next();
if (l.getId()==pictureId) {
iterator.remove();
session.delete(l);
ag.setRepublishNeeded(true);
AOGGameDao.updateGame(ag, session);
break;
}
}
}
form.setPictures(new ArrayList<AOGGamePicturesHiber>(ag.getPictures()));
//fill tables
AOGGameCardHiber[] orderedSimulations=AOGGameCardDao.getOrderedCardsInSimulation(card);
AOGGameCardHiber[] orderedIncidents0=AOGGameCardDao.getOrderedCardsInSimulation(orderedSimulations[0]);
AOGGameCardHiber[] orderedIncidents1=AOGGameCardDao.getOrderedCardsInSimulation(orderedSimulations[1]);
AOGGameCardHiber[] orderedIncidents2=AOGGameCardDao.getOrderedCardsInSimulation(orderedSimulations[2]);
AOGGameCardHiber[] orderedIncidents3=AOGGameCardDao.getOrderedCardsInSimulation(orderedSimulations[3]);
//save data
if (req.getParameter("changeData")!=null) {
fillDataFromRequest( req,orderedSimulations,orderedIncidents0,orderedIncidents1,orderedIncidents2,orderedIncidents3);
//handle case data copying
handleCaseCopying( req,orderedSimulations,orderedIncidents0,orderedIncidents1,orderedIncidents2,orderedIncidents3);
AOGGameCardDao.updateGameCardRecursively(card,session);
ag.setRepublishNeeded(true);
AOGGameDao.updateGame(ag, session);
}
form.setCh(card);
form.setOrderedSimulations(orderedSimulations);
form.setOrderedIncidents0(orderedIncidents0);
form.setOrderedIncidents1(orderedIncidents1);
form.setOrderedIncidents2(orderedIncidents2);
form.setOrderedIncidents3(orderedIncidents3);
return am.findForward("ok");
}