use of cn.edu.zju.acm.onlinejudge.form.ContestForm in project zoj by licheng.
the class CreateContestAction method execute.
/**
* Register.
*
* @param mapping
* action mapping
* @param form
* action form
* @param request
* http servlet request
* @param response
* http servlet response
*
* @return action forward instance
*
* @throws Exception
* any errors happened
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
ActionForward forward = this.checkAdmin(mapping, context);
if (forward != null) {
return forward;
}
ContestPersistence contestPersistence = PersistenceManager.getInstance().getContestPersistence();
ContestForm contestForm = (ContestForm) form;
if (contestForm == null || contestForm.getId() == null) {
return this.handleSuccess(mapping, context, "failure");
}
context.setAttribute("ContestForm", contestForm);
// create user profile
AbstractContest contest = contestForm.toContest();
contestPersistence.createContest(contest, context.getUserProfile().getId());
ContestManager.getInstance().refreshContest(contest.getId());
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.createContest.success"));
this.saveErrors(context.getRequest(), messages);
context.setAttribute("back", "manageContests.do");
return this.handleSuccess(mapping, context, "success");
}
use of cn.edu.zju.acm.onlinejudge.form.ContestForm in project zoj by licheng.
the class EditContestAction method execute.
/**
* Edit Contest.
*
* <pre>
* </pre>
*
* @param mapping
* action mapping
* @param form
* action form
* @param request
* http servlet request
* @param response
* http servlet response
*
* @return action forward instance
*
* @throws Exception
* any errors happened
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
boolean isProblemset = context.getRequest().getRequestURI().endsWith("editProblemset.do");
ActionForward forward = this.checkContestAdminPermission(mapping, context, isProblemset, false);
if (forward != null) {
return forward;
}
ContestForm contestForm = (ContestForm) form;
if (contestForm.getId() == null) {
AbstractContest contest = context.getContest();
contestForm.populate(contest);
return this.handleSuccess(mapping, context);
} else {
ContestPersistence persistence = PersistenceManager.getInstance().getContestPersistence();
AbstractContest contest = contestForm.toContest();
persistence.updateContest(contest, context.getUserSecurity().getId());
ContestManager.getInstance().refreshContest(contest.getId());
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.editContest.success"));
this.saveErrors(context.getRequest(), messages);
context.setAttribute("back", (isProblemset ? "problemsetInfo.do" : "contestInfo.do") + "?contestId=" + contest.getId());
return this.handleSuccess(mapping, context, "success");
}
}
Aggregations