Search in sources :

Example 6 with ProblemPersistence

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

the class DeleteProblemAction 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 problem
    boolean isProblemset = context.getRequest().getRequestURI().endsWith("deleteProblem.do");
    ActionForward forward = this.checkProblemAdminPermission(mapping, context, isProblemset);
    if (forward != null) {
        return forward;
    }
    Problem problem = context.getProblem();
    ActionMessages messages = new ActionMessages();
    ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
    problemPersistence.deleteProblem(problem.getId(), context.getUserProfile().getId());
    messages.add("message", new ActionMessage("onlinejudge.deleteProblem.success"));
    this.saveErrors(context.getRequest(), messages);
    String back = isProblemset ? "showProblems" : "showContestProblems";
    context.setAttribute("back", back + ".do?contestId=" + context.getContest().getId());
    ContestManager.getInstance().refreshContest(context.getContest().getId());
    return this.handleSuccess(mapping, context, "success");
}
Also used : ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ActionForward(org.apache.struts.action.ActionForward) ProblemPersistence(cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)

Example 7 with ProblemPersistence

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

the class ContestManager method getProblemsCount.

public int getProblemsCount(long contestId) throws PersistenceException {
    Object key = new Long(contestId);
    synchronized (this.problemCountCache) {
        Integer count = this.problemCountCache.get(key);
        if (count == null) {
            ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
            int ret = problemPersistence.getProblemsCount(contestId);
            this.problemCountCache.put(key, ret);
            return ret;
        }
        return count.intValue();
    }
}
Also used : ProblemPersistence(cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)

Example 8 with ProblemPersistence

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

the class ContestManager method searchProblems.

public List<Problem> searchProblems(ProblemCriteria criteria, int offset, int count) throws PersistenceException {
    List<Object> key = new ArrayList<Object>();
    key.add(criteria);
    key.add(new Integer(offset));
    key.add(new Integer(count));
    synchronized (this.contestProblemsCache) {
        List<Problem> problems = this.contestProblemsCache.get(key);
        if (problems == null) {
            ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
            problems = problemPersistence.searchProblems(criteria, offset, count);
            this.contestProblemsCache.put(key, problems);
        }
        return problems;
    }
}
Also used : ArrayList(java.util.ArrayList) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ProblemPersistence(cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)

Aggregations

ProblemPersistence (cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)8 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)6 ActionForward (org.apache.struts.action.ActionForward)3 ActionMessages (org.apache.struts.action.ActionMessages)3 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)2 ProblemForm (cn.edu.zju.acm.onlinejudge.form.ProblemForm)2 ArrayList (java.util.ArrayList)2 ProblemCriteria (cn.edu.zju.acm.onlinejudge.bean.request.ProblemCriteria)1 ProblemEntry (cn.edu.zju.acm.onlinejudge.util.ProblemEntry)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 List (java.util.List)1 ActionMessage (org.apache.struts.action.ActionMessage)1