Search in sources :

Example 11 with ActionMessages

use of org.apache.struts.action.ActionMessages in project zoj by licheng.

the class DeleteContestAction 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 {
    // check contest
    boolean isProblemset = context.getRequest().getRequestURI().endsWith("deleteProblemset.do");
    ActionForward forward = this.checkContestAdminPermission(mapping, context, isProblemset, false);
    if (forward != null) {
        return forward;
    }
    AbstractContest contest = context.getContest();
    ContestPersistence contestPersistence = PersistenceManager.getInstance().getContestPersistence();
    contestPersistence.deleteContest(contest.getId(), context.getUserSecurity().getId());
    ContestManager.getInstance().refreshContest(contest.getId());
    ActionMessages messages = new ActionMessages();
    if (isProblemset) {
        messages.add("message", new ActionMessage("onlinejudge.deleteProblemset.success"));
    } else {
        messages.add("message", new ActionMessage("onlinejudge.deleteContest.success"));
    }
    this.saveErrors(context.getRequest(), messages);
    context.setAttribute("back", isProblemset ? "showProblemsets.do" : "showContests.do");
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ContestPersistence(cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) ActionForward(org.apache.struts.action.ActionForward)

Example 12 with ActionMessages

use of org.apache.struts.action.ActionMessages 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");
    }
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ContestForm(cn.edu.zju.acm.onlinejudge.form.ContestForm) ContestPersistence(cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) ActionForward(org.apache.struts.action.ActionForward)

Example 13 with ActionMessages

use of org.apache.struts.action.ActionMessages in project zoj by licheng.

the class BaseAction method checkProblemPermission.

protected ActionForward checkProblemPermission(ActionMapping mapping, ContextAdapter context, Boolean isProblemset, PermissionLevel level) throws Exception {
    Problem problem = context.getProblem();
    AbstractContest contest = null;
    if (problem != null) {
        contest = ContestManager.getInstance().getContest(problem.getContestId());
    }
    if (problem == null || contest == null || isProblemset != null && (contest instanceof Contest || contest instanceof Course) == isProblemset.booleanValue()) {
        ActionMessages messages = new ActionMessages();
        messages.add("message", new ActionMessage("onlinejudge.showproblem.noproblemid"));
        this.saveErrors(context.getRequest(), messages);
        if (isProblemset != null) {
            context.setAttribute("back", isProblemset ? "showProblemsets.do" : "showContests.do");
        }
        return this.handleFailure(mapping, context, messages, "nopermission");
    }
    context.setAttribute("contest", contest);
    context.setAttribute("problem", problem);
    // check contest permission
    UserSecurity userSecurity = context.getUserSecurity();
    boolean hasPermisstion = false;
    if (level == PermissionLevel.ADMIN) {
        hasPermisstion = userSecurity.canAdminContest(contest.getId());
    } else if (level == PermissionLevel.PARTICIPATE) {
        hasPermisstion = userSecurity.canParticipateContest(contest.getId());
    } else if (level == PermissionLevel.PARTICIPATECANVIEWSOURCE) {
        hasPermisstion = userSecurity.canViewSource(contest.getId());
    } else if (level == PermissionLevel.VIEW) {
        hasPermisstion = userSecurity.canViewContest(contest.getId());
    }
    if (!hasPermisstion) {
        ActionMessages messages = new ActionMessages();
        messages.add("message", new ActionMessage("onlinejudge.showcontest.nopermission"));
        this.saveErrors(context.getRequest(), messages);
        if (isProblemset != null) {
            context.setAttribute("back", isProblemset ? "showProblemsets.do" : "showContests.do");
        }
        return this.handleFailure(mapping, context, messages, "nopermission");
    }
    // check start time
    if (userSecurity.canAdminContest(contest.getId())) {
        return null;
    } else {
        return this.checkContestStart(mapping, context, contest);
    }
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) UserSecurity(cn.edu.zju.acm.onlinejudge.security.UserSecurity) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest) Course(cn.edu.zju.acm.onlinejudge.bean.Course)

Example 14 with ActionMessages

use of org.apache.struts.action.ActionMessages in project zoj by licheng.

the class BaseAction method checkContestStart.

private ActionForward checkContestStart(ActionMapping mapping, ContextAdapter context, AbstractContest contest) throws PersistenceException {
    if (contest.getStartTime() == null) {
        return null;
    }
    if (contest.getStartTime().getTime() > System.currentTimeMillis()) {
        ActionMessages messages = new ActionMessages();
        messages.add("message", new ActionMessage("onlinejudge.showcontest.nostarted"));
        this.saveErrors(context.getRequest(), messages);
        context.setAttribute("back", "contestInfo.do?contestId=" + contest.getId());
        return this.handleFailure(mapping, context, messages, "nopermission");
    }
    return null;
}
Also used : ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage)

Example 15 with ActionMessages

use of org.apache.struts.action.ActionMessages in project zoj by licheng.

the class EditProblemAction method execute.

/**
     * EditProblemAction.
     * 
     * @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 {
    // check contest
    boolean isProblemset = context.getRequest().getRequestURI().endsWith("editProblem.do");
    ActionForward forward = this.checkProblemAdminPermission(mapping, context, isProblemset);
    if (forward != null) {
        return forward;
    }
    ProblemForm problemForm = (ProblemForm) form;
    if (problemForm == null || problemForm.getName() == null) {
        Problem problem = context.getProblem();
        problemForm.populate(problem, context.getContest());
        this.setReference("DescriptionRef", ReferenceType.DESCRIPTION, problem.getId(), context);
        this.setReference("InputRef", ReferenceType.INPUT, problem.getId(), context);
        this.setReference("OutputRef", ReferenceType.OUTPUT, problem.getId(), context);
        this.setReference("JudgeSolutionRef", ReferenceType.JUDGE_SOLUTION, problem.getId(), context);
        this.setReference("HeaderRef", ReferenceType.HEADER, problem.getId(), context);
        this.setReference("CheckerSourceRef", ReferenceType.CHECKER_SOURCE, problem.getId(), context);
        return this.handleSuccess(mapping, context, "failure");
    }
    // check title and code
    ActionMessages errors = this.validate(problemForm, context);
    if (errors.size() > 0) {
        return this.handleFailure(mapping, context, errors);
    }
    ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
    AbstractContest contest = context.getContest();
    Problem problem = problemForm.toProblem();
    if (problemForm.isUseContestDefault()) {
        problem.getLimit().setId(contest.getLimit().getId());
    }
    long userId = context.getUserSecurity().getId();
    // create problem
    problemPersistence.updateProblem(problem, userId);
    // cprete problem reference, i.e. text, input, output, checker, judge solution, checker source
    this.updateReference(ReferenceType.DESCRIPTION, problemForm.getDescription(), problem.getId(), userId);
    this.updateReference(ReferenceType.INPUT, problemForm.getInputData(), problem.getId(), userId);
    this.updateReference(ReferenceType.OUTPUT, problemForm.getOutputData(), problem.getId(), userId);
    this.updateReference(ReferenceType.HEADER, problemForm.getChecker(), problem.getId(), userId);
    this.updateReference(ReferenceType.CHECKER_SOURCE, problemForm.getCheckerSource(), problem.getId(), userId);
    this.updateReference(ReferenceType.JUDGE_SOLUTION, problemForm.getJudgeSolution(), problem.getId(), userId);
    ContestManager.getInstance().refreshProblem(problem);
    return this.handleSuccess(mapping, context, "success", "?contestId=" + contest.getId());
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ProblemForm(cn.edu.zju.acm.onlinejudge.form.ProblemForm) ActionMessages(org.apache.struts.action.ActionMessages) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ActionForward(org.apache.struts.action.ActionForward) ProblemPersistence(cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)

Aggregations

ActionMessages (org.apache.struts.action.ActionMessages)47 ActionMessage (org.apache.struts.action.ActionMessage)31 JspException (javax.servlet.jsp.JspException)15 ActionForward (org.apache.struts.action.ActionForward)14 Iterator (java.util.Iterator)11 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)10 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)6 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)6 ContestPersistence (cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence)4 UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)4 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)4 Date (java.util.Date)4 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)3 UserPreference (cn.edu.zju.acm.onlinejudge.bean.UserPreference)3 ProblemPersistence (cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)3 Contest (cn.edu.zju.acm.onlinejudge.bean.Contest)2 Course (cn.edu.zju.acm.onlinejudge.bean.Course)2 Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)2 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)2 LogCriteria (cn.edu.zju.acm.onlinejudge.bean.request.LogCriteria)2