Search in sources :

Example 1 with SubmissionCriteria

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

the class ShowRunsAction method execute.

/**
     * ShowRunsAction.
     * 
     * @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("showRuns.do");
    ActionForward forward = this.checkContestViewPermission(mapping, context, isProblemset, true);
    if (forward != null) {
        return forward;
    }
    context.setAttribute("judgeReplies", context.isAdmin() ? this.adminJudgeReplies : this.judgeReplies);
    // check contest
    boolean isRejudge = "true".equalsIgnoreCase(context.getRequest().getParameter("rejudge"));
    if (isRejudge) {
        this.checkContestAdminPermission(mapping, context, isProblemset, true);
    } else {
        this.checkContestViewPermission(mapping, context, isProblemset, true);
    }
    if (forward != null) {
        return forward;
    }
    SubmissionSearchForm serachForm = (SubmissionSearchForm) form;
    ActionMessages errors = serachForm.check();
    if (errors.size() > 0) {
        // TODO
        context.setAttribute("runs", new ArrayList<Submission>());
        return this.handleFailure(mapping, context, errors);
    }
    long lastId = Utility.parseLong(serachForm.getLastId());
    long firstId = -1;
    if (lastId < 0) {
        lastId = Long.MAX_VALUE;
        firstId = Utility.parseLong(serachForm.getFirstId());
    }
    int RUNS_PER_PAGE = 15;
    SubmissionCriteria criteria = serachForm.toSubmissionCriteria();
    if (isRejudge) {
        int maxN = 100;
        List<Submission> allRuns = PersistenceManager.getInstance().getSubmissionPersistence().searchSubmissions(criteria, -1, Long.MAX_VALUE, maxN + 1, true);
        if (allRuns.size() > maxN) {
        // TODO
        }
        this.rejudge(allRuns);
    // TODO
    }
    List<Submission> runs = StatisticsManager.getInstance().getSubmissions(criteria, firstId, lastId, RUNS_PER_PAGE + 1);
    long newLastId = -1;
    long newFirstId = -1;
    long nextId = -1;
    long startId = -1;
    if (runs.size() > 0) {
        startId = runs.get(0).getContestOrder();
    }
    if (runs.size() > RUNS_PER_PAGE) {
        nextId = runs.get(runs.size() - 2).getContestOrder();
        runs = runs.subList(0, runs.size() - 1);
    }
    if (firstId > -1) {
        runs = new ArrayList<Submission>(runs);
        Collections.reverse(runs);
    }
    if (runs.size() > 0) {
        if (lastId == Long.MAX_VALUE && firstId == -1) {
            newLastId = nextId;
        } else if (firstId == -1) {
            newLastId = nextId;
            newFirstId = startId;
        } else {
            newFirstId = nextId;
            newLastId = startId;
        }
    }
    context.setAttribute("runs", runs);
    if (newFirstId > -1) {
        context.setAttribute("firstId", newFirstId);
    }
    if (newLastId > -1) {
        context.setAttribute("lastId", newLastId);
    }
    return this.handleSuccess(mapping, context, "success");
}
Also used : Submission(cn.edu.zju.acm.onlinejudge.bean.Submission) ActionMessages(org.apache.struts.action.ActionMessages) SubmissionSearchForm(cn.edu.zju.acm.onlinejudge.form.SubmissionSearchForm) ActionForward(org.apache.struts.action.ActionForward) SubmissionCriteria(cn.edu.zju.acm.onlinejudge.bean.request.SubmissionCriteria)

Example 2 with SubmissionCriteria

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

the class SubmissionSearchForm method toSubmissionCriteria.

public SubmissionCriteria toSubmissionCriteria() throws ParseException, NumberFormatException, PersistenceException {
    SubmissionCriteria criteria = new SubmissionCriteria();
    if (this.contestId != null && this.contestId.trim().length() > 0) {
        criteria.setContestId(Long.valueOf(this.contestId.trim()));
    }
    if (this.problemCode != null && this.problemCode.trim().length() > 0) {
        criteria.setProblemCode(this.problemCode);
    }
    if (this.handle != null && this.handle.trim().length() > 0) {
        criteria.setHandle(this.handle);
    }
    if (this.idStart != null && this.idStart.trim().length() > 0) {
        criteria.setIdStart(Long.valueOf(this.idStart.trim()));
    }
    if (this.idEnd != null && this.idEnd.trim().length() > 0) {
        criteria.setIdEnd(Long.valueOf(this.idEnd.trim()));
    }
    if (this.timeStart != null && this.timeStart.trim().length() > 0) {
        criteria.setTimeStart(Utility.parseTimestamp(this.timeStart));
    }
    if (this.timeEnd != null && this.timeEnd.trim().length() > 0) {
        criteria.setTimeEnd(Utility.parseTimestamp(this.timeEnd));
    }
    if (this.languageIds != null && this.languageIds.length > 0) {
        LanguagePersistence persistence = PersistenceManager.getInstance().getLanguagePersistence();
        List<Language> languages = new ArrayList<Language>();
        for (int i = 0; i < this.languageIds.length; ++i) {
            languages.add(persistence.getLanguage(Long.parseLong(this.languageIds[i])));
        }
        criteria.setLanguages(languages);
    }
    if (this.judgeReplyIds != null && this.judgeReplyIds.length > 0) {
        List<JudgeReply> judgeReplies = new ArrayList<JudgeReply>();
        for (int i = 0; i < this.judgeReplyIds.length; ++i) {
            judgeReplies.add(JudgeReply.findById(Long.parseLong(this.judgeReplyIds[i])));
        }
        criteria.setJudgeReplies(judgeReplies);
    }
    return criteria;
}
Also used : Language(cn.edu.zju.acm.onlinejudge.bean.enumeration.Language) JudgeReply(cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply) ArrayList(java.util.ArrayList) SubmissionCriteria(cn.edu.zju.acm.onlinejudge.bean.request.SubmissionCriteria) LanguagePersistence(cn.edu.zju.acm.onlinejudge.persistence.LanguagePersistence)

Example 3 with SubmissionCriteria

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

the class SubmissionPersistenceImplTest method testSearchSubmissions5.

/**
	 * Tests searchSubmissions method
	 * @throws Exception to JUnit
	 */
public void testSearchSubmissions5() throws Exception {
    List submissions = null;
    SubmissionCriteria criteria = new SubmissionCriteria();
    criteria.setTimeEnd(submission3.getSubmitDate());
    criteria.setTimeStart(null);
    submissions = persistence.searchSubmissions(criteria, 0, 100);
    checkSubmissions(Arrays.asList(new Object[] { submission1, submission3 }), submissions);
    criteria.setTimeStart(submission3.getSubmitDate());
    criteria.setTimeEnd(null);
    submissions = persistence.searchSubmissions(criteria, 0, 100);
    checkSubmissions(Arrays.asList(new Object[] { submission3, submission4 }), submissions);
    criteria.setTimeStart(submission1.getSubmitDate());
    criteria.setTimeEnd(submission3.getSubmitDate());
    submissions = persistence.searchSubmissions(criteria, 0, 100);
    checkSubmissions(Arrays.asList(new Object[] { submission1, submission3 }), submissions);
    criteria.setTimeEnd(new Date(-1000));
    criteria.setTimeStart(null);
    submissions = persistence.searchSubmissions(criteria, 0, 100);
    checkSubmissions(new ArrayList(), submissions);
    criteria.setTimeStart(new Date(submission4.getSubmitDate().getTime() + 1000));
    criteria.setTimeEnd(null);
    submissions = persistence.searchSubmissions(criteria, 0, 100);
    checkSubmissions(new ArrayList(), submissions);
    criteria.setTimeStart(submission3.getSubmitDate());
    criteria.setTimeEnd(submission1.getSubmitDate());
    submissions = persistence.searchSubmissions(criteria, 0, 100);
    checkSubmissions(new ArrayList(), submissions);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Date(java.util.Date) SubmissionCriteria(cn.edu.zju.acm.onlinejudge.bean.request.SubmissionCriteria)

Example 4 with SubmissionCriteria

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

the class SubmissionPersistenceImplTest method testSearchSubmissions8.

/**
	 * Tests searchSubmissions method
	 * @throws Exception to JUnit
	 */
public void testSearchSubmissions8() throws Exception {
    List submissions = null;
    SubmissionCriteria criteria = new SubmissionCriteria();
    criteria.setProblemId(new Long(problem2.getId()));
    criteria.setContestId(new Long(contest.getId()));
    criteria.setHandle(userProfile2.getHandle());
    criteria.setIdStart(new Long(submission1.getId()));
    criteria.setIdEnd(new Long(submission4.getId()));
    criteria.setTimeStart(submission1.getSubmitDate());
    criteria.setTimeEnd(submission4.getSubmitDate());
    criteria.setJudgeReplies(Arrays.asList(new Object[] { judgeReply1, judgeReply2, judgeReply3 }));
    criteria.setLanguages(Arrays.asList(new Object[] { language1, language2, language3 }));
    submissions = persistence.searchSubmissions(criteria, 0, 100);
    checkSubmissions(Arrays.asList(new Object[] { submission3 }), submissions);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) SubmissionCriteria(cn.edu.zju.acm.onlinejudge.bean.request.SubmissionCriteria)

Example 5 with SubmissionCriteria

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

the class SubmissionPersistenceImplTest method testSearchSubmissions7.

/**
	 * Tests searchSubmissions method
	 * @throws Exception to JUnit
	 */
public void testSearchSubmissions7() throws Exception {
    List submissions = null;
    SubmissionCriteria criteria = new SubmissionCriteria();
    criteria.setJudgeReplies(Arrays.asList(new Object[] { judgeReply1, judgeReply3 }));
    submissions = persistence.searchSubmissions(criteria, 0, 100);
    checkSubmissions(Arrays.asList(new Object[] { submission1, submission3 }), submissions);
    criteria.setJudgeReplies(Arrays.asList(new Object[] { judgeReply2 }));
    submissions = persistence.searchSubmissions(criteria, 0, 100);
    checkSubmissions(Arrays.asList(new Object[] { submission2, submission4 }), submissions);
    criteria.setJudgeReplies(Arrays.asList(new Object[] { new JudgeReply(4, "x", "x", "x", true) }));
    submissions = persistence.searchSubmissions(criteria, 0, 100);
    checkSubmissions(new ArrayList(), submissions);
    criteria.setJudgeReplies(new ArrayList());
    submissions = persistence.searchSubmissions(criteria, 0, 100);
    checkSubmissions(new ArrayList(), submissions);
}
Also used : JudgeReply(cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SubmissionCriteria(cn.edu.zju.acm.onlinejudge.bean.request.SubmissionCriteria)

Aggregations

SubmissionCriteria (cn.edu.zju.acm.onlinejudge.bean.request.SubmissionCriteria)12 ArrayList (java.util.ArrayList)11 List (java.util.List)10 JudgeReply (cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply)2 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)2 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)1 SubmissionSearchForm (cn.edu.zju.acm.onlinejudge.form.SubmissionSearchForm)1 LanguagePersistence (cn.edu.zju.acm.onlinejudge.persistence.LanguagePersistence)1 Date (java.util.Date)1 ActionForward (org.apache.struts.action.ActionForward)1 ActionMessages (org.apache.struts.action.ActionMessages)1