this.session = HibernateSessions.getSessionFactory().openSession();
try {
PlaytGameForm form=(PlaytGameForm)af;
form.setMyUserId(webUser.getId());
if (req.getParameter("cancelChangesSubmit")!=null) {
form.reset();
return am.findForward("cancel");
}
MessageBean.addSpeedOMeterCheckPoint(req, "point2");
long id=Long.parseLong(req.getParameter("id"));
GameHiber g=GameDao.findGameHiber(id,session);
Game g2=GameDao.findGame(id,session);
form.setGame(g2);
MessageBean.addSpeedOMeterCheckPoint(req, "point3");
if (req.getParameter("simulateSMS")!=null) {
if (!SecurityCenter.canIManualyInsertPlayingResults(webUser.getId(), g,session)) {
MessageBean.setMyMessage(req, ("Error: Insufficient privileges."));
form.reset();
return am.findForward("list");
}
int achieved=form.getSimulatedScore();
long msisdn=-1;
String userFriendlyName=msisdn+"";
//entered phone number
if (form.getSimulatedUserNumber()!=null)
if (!form.getSimulatedUserNumber().equals("")) {
try {
msisdn=Long.parseLong(form.getSimulatedUserNumber());
userFriendlyName=msisdn+"";
} catch (Exception e) {
}
}
//selected user
if (msisdn==-1) {
try {
User u=UserDao.findUser(form.getSimulatedUser(), session);
msisdn=u.getMsisdn();
userFriendlyName=u.getLastName()+" "+u.getFirstName();
} catch (Exception e) {
}
}
ReceivedSms sms=new ReceivedSms();
sms.setSender(msisdn+"");
sms.setContent(g.getId()+" "+achieved);
//send message to MDB
sendSMS(req, sms);
MessageBean.setMyMessage(req, ("User "+userFriendlyName+" achieved "+achieved+" point(s) in game "+g.getName()+"."));
form.reset();
MessageBean.addSpeedOMeterCheckPoint(req, "point4");
return am.findForward("list");
} else if (req.getParameter("simulateSeveralSMS")!=null) {
//send several SMSs
if (!SecurityCenter.canIManualyInsertPlayingResults(webUser.getId(), g,session)) {
MessageBean.setMyMessage(req, ("Error: Insufficient privileges."));
form.reset();
return am.findForward("list");
}
long[] users={form.getSimulatedUser1(),form.getSimulatedUser2(),form.getSimulatedUser3(),form.getSimulatedUser4(),
form.getSimulatedUser5(),form.getSimulatedUser6(),form.getSimulatedUser7(),form.getSimulatedUser8(),
form.getSimulatedUser9(),form.getSimulatedUser10()};
int[] scores={form.getSimulatedScore1(),form.getSimulatedScore2(),form.getSimulatedScore3(),form.getSimulatedScore4(),
form.getSimulatedScore5(),form.getSimulatedScore6(),form.getSimulatedScore7(),form.getSimulatedScore8(),
form.getSimulatedScore9(),form.getSimulatedScore10()};
for (int i=0;i<10;i++) {
int achieved=scores[i];
long msisdn=-1;
String userFriendlyName=msisdn+"";
if (achieved<0) continue;
//selected user
if (msisdn==-1) {
try {
User u=UserDao.findUser(users[i], session);
msisdn=u.getMsisdn();
userFriendlyName=u.getLastName()+" "+u.getFirstName();
} catch (Exception e) {
}
}
ReceivedSms sms=new ReceivedSms();
sms.setSender(msisdn+"");
sms.setContent(g.getId()+" "+achieved);
//send message to MDB
sendSMS(req, sms);
}
MessageBean.setMyMessage(req, ("Several scores entered successfuly."));
form.reset();
MessageBean.addSpeedOMeterCheckPoint(req, "point5");
return am.findForward("list");
} else {
//fill the users arraylist
MessageBean.addSpeedOMeterCheckPoint(req, "point6");
form.setUsers(new ArrayList<User>());
MessageBean.addSpeedOMeterCheckPoint(req, "point7");
/*
User u=new User();
u.setId(-1);
u.setUsername(" --- select user ---");
form.getUsers().add(u);
form.setMyUserId(-1l);
*/
if (req.getParameter("showDropDowns")!=null) {
//only if simulation is showed
ArrayList<User> all=UserDao.getAllUsers(session);
for (User user : all) {
if (SecurityCenter.canIPlayGame(user.getId(), g, session))
form.getUsers().add(user);
}
}
//for performance sake do it directly...