Search in sources :

Example 1 with ContestPersistence

use of cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence 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 2 with ContestPersistence

use of cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence 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 3 with ContestPersistence

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

use of cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence in project zoj by licheng.

the class BaseAction method checkLastLoginIP.

protected ActionForward checkLastLoginIP(ActionMapping mapping, ContextAdapter context, boolean isProblemset) throws Exception {
    String ip = context.getRequest().getRemoteHost();
    long contestId = context.getContest().getId();
    String ipSessionKey = "last_submit_ip" + contestId;
    String lastIp = (String) context.getSessionAttribute(ipSessionKey);
    if (lastIp == null) {
        ContestPersistence contestPersistence = PersistenceManager.getInstance().getContestPersistence();
        long userId = context.getUserProfile().getId();
        lastIp = contestPersistence.getLastSubmitIP(userId, contestId);
        if (lastIp == null) {
            // first submit
            contestPersistence.setLastSubmitIP(userId, contestId, ip);
            context.setSessionAttribute(ipSessionKey, lastIp);
            return null;
        }
        context.setSessionAttribute(ipSessionKey, lastIp);
    }
    if (!lastIp.equals(ip)) {
        ActionMessages messages = new ActionMessages();
        messages.add("message", new ActionMessage("onlinejudge.submit.invalid_ip"));
        this.saveErrors(context.getRequest(), messages);
        context.setAttribute("back", "contestInfo.do?contestId=" + contestId);
        return this.handleFailure(mapping, context, messages, "nopermission");
    }
    return null;
}
Also used : ContestPersistence(cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage)

Example 5 with ContestPersistence

use of cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence in project zoj by licheng.

the class ContestManager method getContest.

public AbstractContest getContest(long contestId) throws PersistenceException {
    Object key = new Long(contestId);
    synchronized (this.contestCache) {
        AbstractContest contest = this.contestCache.get(key);
        if (contest == null) {
            ContestPersistence contestPersistence = PersistenceManager.getInstance().getContestPersistence();
            contest = contestPersistence.getContest(contestId);
            this.contestCache.put(key, contest);
        }
        return contest;
    }
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ContestPersistence(cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence)

Aggregations

ContestPersistence (cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence)6 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)5 ActionMessage (org.apache.struts.action.ActionMessage)4 ActionMessages (org.apache.struts.action.ActionMessages)4 ActionForward (org.apache.struts.action.ActionForward)3 ContestForm (cn.edu.zju.acm.onlinejudge.form.ContestForm)2