Search in sources :

Example 16 with Submission

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

the class ShowRunsAction method rejudge.

private void rejudge(List<Submission> runs) throws Exception {
    for (Submission submission : runs) {
        if (!submission.getJudgeReply().equals(JudgeReply.OUT_OF_CONTEST_TIME)) {
            submission.setJudgeReply(JudgeReply.QUEUING);
            submission.setMemoryConsumption(0);
            submission.setTimeConsumption(0);
            PersistenceManager.getInstance().getSubmissionPersistence().updateSubmission(submission, 1);
            JudgeService.getInstance().judge(submission, Priority.LOW);
        }
    }
}
Also used : Submission(cn.edu.zju.acm.onlinejudge.bean.Submission)

Example 17 with Submission

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

the class ShowSubmissionAction method execute.

/**
     * ShowSourceAction.
     * 
     * @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 {
    HttpServletResponse response = context.getResponse();
    long id = Utility.parseLong(context.getRequest().getParameter("submissionId"));
    Submission submission = ContestManager.getInstance().getSubmission(id);
    if (submission == null) {
        response.sendError(404);
        return null;
    }
    // user can always view their own submission
    UserProfile user = context.getUserProfile();
    if (user == null || user.getId() != submission.getUserProfileId()) {
        Problem problem = ContestManager.getInstance().getProblem(submission.getProblemId());
        context.setAttribute("problem", problem);
        ActionForward forward = this.checkProblemViewSourecPermission(mapping, context, null);
        if (forward != null) {
            response.sendError(404);
            return null;
        }
    }
    response.setContentType("text/plain");
    boolean download = "true".equalsIgnoreCase(context.getRequest().getParameter("download"));
    if (download) {
        response.setHeader("Content-disposition", "attachment; filename=" + id + "." + submission.getLanguage().getOptions());
    }
    response.getOutputStream().write(submission.getContent().getBytes());
    response.getOutputStream().close();
    return null;
}
Also used : Submission(cn.edu.zju.acm.onlinejudge.bean.Submission) UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) HttpServletResponse(javax.servlet.http.HttpServletResponse) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ActionForward(org.apache.struts.action.ActionForward)

Example 18 with Submission

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

the class SubmissionPersistenceImplTest method testGetSubmission3.

/**
	 * Tests getSubmission method
	 * @throws Exception to JUnit
	 */
public void testGetSubmission3() throws Exception {
    Submission submission = persistence.getSubmission(submission3.getId());
    checkSubmission(submission3, submission);
}
Also used : ExtendedSubmission(cn.edu.zju.acm.onlinejudge.bean.ExtendedSubmission) Submission(cn.edu.zju.acm.onlinejudge.bean.Submission)

Example 19 with Submission

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

the class SubmissionPersistenceImplTest method testGetSubmission1.

/*

	private Language language3 = new Language(3, "language3", "Language 3", "compiler3", "options3");
	
	

	private JudgeReply judgeReply1 = new JudgeReply(1, "judgeReply1", "JudgeReply 1", "style1", true);
	submission1 = newSubmission(1, problem1.getId(), userProfile1.getId(), language1, judgeReply1);
	submission2 = newSubmission(2, problem2.getId(), userProfile1.getId(), language2, judgeReply2);
	submission2.setJudgeDate(null);
	submission2.setSubmitDate(null);
	submission3 = newSubmission(3, problem2.getId(), userProfile2.getId(), language3, judgeReply3);
	submission4 = newSubmission(4, problem2.getId(), userProfile1.getId(), language1, judgeReply2);
	 */
/**
	 * Tests getSubmission method
	 * @throws Exception to JUnit
	 */
public void testGetSubmission1() throws Exception {
    Submission submission = persistence.getSubmission(submission1.getId());
    checkSubmission(submission1, submission);
}
Also used : ExtendedSubmission(cn.edu.zju.acm.onlinejudge.bean.ExtendedSubmission) Submission(cn.edu.zju.acm.onlinejudge.bean.Submission)

Example 20 with Submission

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

the class SubmitAction method execute.

/**
     * SubmitAction.
     * 
     * @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 {
    if (!this.isLogin(context, true)) {
        return this.handleSuccess(mapping, context, "login");
    }
    boolean isProblemset = context.getRequest().getRequestURI().endsWith("submit.do");
    ActionForward forward = this.checkProblemParticipatePermission(mapping, context, isProblemset);
    if (forward != null) {
        return forward;
    }
    AbstractContest contest = context.getContest();
    Problem problem = context.getProblem();
    long languageId = Utility.parseLong(context.getRequest().getParameter("languageId"));
    Language language = PersistenceManager.getInstance().getLanguagePersistence().getLanguage(languageId);
    if (language == null) {
        return this.handleSuccess(mapping, context, "submit");
    }
    String source = context.getRequest().getParameter("source");
    if (source == null || source.length() == 0) {
        return this.handleSuccess(mapping, context, "submit");
    }
    List refrance = PersistenceManager.getInstance().getReferencePersistence().getProblemReferences(problem.getId(), ReferenceType.HEADER);
    if (refrance.size() != 0) {
        Reference r = (Reference) refrance.get(0);
        String percode = new String(r.getContent());
        source = percode + "\n" + source;
    }
    UserProfile user = context.getUserProfile();
    if (submitCache != null && submitCache.contains(user.getId())) {
        ActionMessages messages = new ActionMessages();
        messages.add("message", new ActionMessage("onlinejudge.submit.interval"));
        this.saveErrors(context.getRequest(), messages);
        context.setAttribute("source", source);
        return handleSuccess(mapping, context, "submit");
    }
    if (contest.isCheckIp()) {
        forward = this.checkLastLoginIP(mapping, context, isProblemset);
        if (forward != null) {
            return forward;
        }
    }
    Submission submission = new Submission();
    submission.setContestId(contest.getId());
    submission.setLanguage(language);
    submission.setProblemId(problem.getId());
    submission.setUserProfileId(user.getId());
    submission.setContent(source);
    submission.setMemoryConsumption(0);
    submission.setTimeConsumption(0);
    submission.setSubmitDate(new Date());
    SubmissionPersistence submissionPersistence = PersistenceManager.getInstance().getSubmissionPersistence();
    if (contest.getEndTime() != null && new Date().after(contest.getEndTime())) {
        submission.setJudgeReply(JudgeReply.OUT_OF_CONTEST_TIME);
        submissionPersistence.createSubmission(submission, user.getId());
    } else if (source.getBytes().length > problem.getLimit().getSubmissionLimit() * 1024) {
        submission.setContent(source.substring(0, problem.getLimit().getSubmissionLimit() * 1024));
        submission.setJudgeReply(JudgeReply.SUBMISSION_LIMIT_EXCEEDED);
        submissionPersistence.createSubmission(submission, user.getId());
    } else {
        submission.setJudgeReply(JudgeReply.QUEUING);
        submissionPersistence.createSubmission(submission, user.getId());
        JudgeService.getInstance().judge(submission, Priority.NORMAL);
    }
    context.setAttribute("contestOrder", submission.getContestOrder());
    if (submitCache != null) {
        submitCache.put(user.getId(), user.getId());
    }
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) Submission(cn.edu.zju.acm.onlinejudge.bean.Submission) Reference(cn.edu.zju.acm.onlinejudge.bean.Reference) SubmissionPersistence(cn.edu.zju.acm.onlinejudge.persistence.SubmissionPersistence) ActionForward(org.apache.struts.action.ActionForward) Date(java.util.Date) Language(cn.edu.zju.acm.onlinejudge.bean.enumeration.Language) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) List(java.util.List)

Aggregations

Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)33 Test (org.junit.Test)8 ExtendedSubmission (cn.edu.zju.acm.onlinejudge.bean.ExtendedSubmission)7 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)7 ArrayList (java.util.ArrayList)5 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)4 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)4 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 Date (java.util.Date)4 ActionForward (org.apache.struts.action.ActionForward)4 Before (org.junit.Before)4 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)3 SubmissionPersistence (cn.edu.zju.acm.onlinejudge.persistence.SubmissionPersistence)3 ActionMessages (org.apache.struts.action.ActionMessages)3 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)2 Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)2 List (java.util.List)2