Search in sources :

Example 1 with AbstractContest

use of cn.edu.zju.acm.onlinejudge.bean.AbstractContest in project zoj by licheng.

the class ContextAdapter method getContest.

public AbstractContest getContest() throws PersistenceException {
    if (this.getAttribute("contest") instanceof AbstractContest) {
        return (AbstractContest) this.getAttribute("contest");
    }
    long contestId = -1;
    String stringId = null;
    if (this.request.getParameter("contestId") != null) {
        stringId = this.request.getParameter("contestId");
    } else if (this.request.getParameter("id") != null) {
        stringId = this.request.getParameter("id");
    }
    this.setAttribute("contestId", stringId);
    if (stringId != null) {
        try {
            contestId = Long.parseLong(stringId);
        } catch (NumberFormatException e) {
        }
    }
    if (contestId < 0) {
        return null;
    }
    AbstractContest contest = ContestManager.getInstance().getContest(contestId);
    this.setAttribute("contest", contest);
    return contest;
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest)

Example 2 with AbstractContest

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

Example 3 with AbstractContest

use of cn.edu.zju.acm.onlinejudge.bean.AbstractContest 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 4 with AbstractContest

use of cn.edu.zju.acm.onlinejudge.bean.AbstractContest 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 5 with AbstractContest

use of cn.edu.zju.acm.onlinejudge.bean.AbstractContest 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)

Aggregations

AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)31 ActionForward (org.apache.struts.action.ActionForward)16 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)10 ActionMessages (org.apache.struts.action.ActionMessages)10 ArrayList (java.util.ArrayList)8 ActionMessage (org.apache.struts.action.ActionMessage)8 Contest (cn.edu.zju.acm.onlinejudge.bean.Contest)5 ContestPersistence (cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence)5 Course (cn.edu.zju.acm.onlinejudge.bean.Course)4 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)4 Date (java.util.Date)4 Limit (cn.edu.zju.acm.onlinejudge.bean.Limit)3 Problemset (cn.edu.zju.acm.onlinejudge.bean.Problemset)3 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)3 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)2 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)2 ContestForm (cn.edu.zju.acm.onlinejudge.form.ContestForm)2