Search in sources :

Example 31 with Problem

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

the class ProblemPersistenceImplTest method newProblem.

/**
	 * Creates a new problem.
	 * @param id the id
	 * @param forumId the forum id
	 * @param limit the limit
	 * @param languages  a list of languages
	 * @return a new Problem instance
	 */
private Problem newProblem(long id, long contestId, Limit limit) {
    Problem problem = new Problem();
    problem.setId(id);
    problem.setContestId(contestId);
    problem.setCode("code" + id);
    problem.setAuthor("author" + id);
    problem.setChecker(id % 2 == 1);
    problem.setContest("contest" + id);
    problem.setLimit(limit);
    problem.setRevision((int) id * 10);
    problem.setSource("source" + id);
    problem.setTitle("title" + id);
    return problem;
}
Also used : Problem(cn.edu.zju.acm.onlinejudge.bean.Problem)

Example 32 with Problem

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

the class ProblemPersistenceImplTest method testUpdateProblem3.

/**
	 * Tests updateProblem method
	 * @throws Exception to JUnit
	 */
public void testUpdateProblem3() throws Exception {
    long id = problem3.getId();
    problem3.setContestId(problemset.getId());
    problem3.setCode("new" + id);
    problem3.setAuthor("new author" + id);
    problem3.setChecker(id % 2 != 1);
    problem3.setContest("new contest" + id);
    problem3.setLimit(limit1);
    problem3.setRevision((int) id * 300);
    problem3.setSource("new source" + id);
    problem3.setTitle("new title" + id);
    persistence.updateProblem(problem3, 11);
    Problem problem = (Problem) persistence.getProblem(problem3.getId());
    checkProblem(problem3, problem);
}
Also used : Problem(cn.edu.zju.acm.onlinejudge.bean.Problem)

Example 33 with Problem

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

the class SubmissionPersistenceImplTest method newProblem.

/**
	 * Creates a new problem.
	 * @param id the id
	 * @param forumId the forum id
	 * @param limit the limit
	 * @param languages  a list of languages
	 * @return a new Problem instance
	 */
private Problem newProblem(long id, long contestId, Limit limit) {
    Problem problem = new Problem();
    problem.setId(id);
    problem.setContestId(contestId);
    problem.setCode("code" + id);
    problem.setAuthor("author" + id);
    problem.setChecker(id % 2 == 1);
    problem.setContest("contest" + id);
    problem.setLimit(limit);
    problem.setRevision((int) id * 10);
    problem.setSource("source" + id);
    problem.setTitle("title" + id);
    return problem;
}
Also used : Problem(cn.edu.zju.acm.onlinejudge.bean.Problem)

Example 34 with Problem

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

Example 35 with Problem

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

the class TestSubmitAction 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 {
        Random ran = new Random();
        submission.setJudgeReply(ran.nextInt() % 2 == 0 ? JudgeReply.WRONG_ANSWER : JudgeReply.ACCEPTED);
        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) Random(java.util.Random) 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

Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)44 ActionForward (org.apache.struts.action.ActionForward)11 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)10 ArrayList (java.util.ArrayList)9 Limit (cn.edu.zju.acm.onlinejudge.bean.Limit)8 ActionMessage (org.apache.struts.action.ActionMessage)7 ProblemPersistence (cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)6 ActionMessages (org.apache.struts.action.ActionMessages)6 Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)5 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)5 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)4 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)3 RankListEntry (cn.edu.zju.acm.onlinejudge.util.RankListEntry)3 List (java.util.List)3 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)2 ProblemForm (cn.edu.zju.acm.onlinejudge.form.ProblemForm)2