Search in sources :

Example 11 with Problem

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

the class JudgeClientInstanceUnitTest method init.

@BeforeClass
public static void init() throws Exception {
    ReflectionUtil.setFieldValue(DAOFactory.class, "languageDAO", new MockLanguageDAO());
    ReflectionUtil.setFieldValue(DAOFactory.class, "problemDAO", new MockProblemDAO());
    ReflectionUtil.setFieldValue(DAOFactory.class, "submissionDAO", new MockSubmissionDAO());
    ReflectionUtil.setFieldValue(DAOFactory.class, "referenceDAO", new MockReferenceDAO());
    Problem problem = new Problem();
    problem.setId(0);
    problem.setRevision(0);
    Limit limit = new Limit();
    limit.setTimeLimit(1);
    limit.setMemoryLimit(1024);
    limit.setOutputLimit(1);
    problem.setLimit(limit);
    Reference reference = new Reference();
    reference.setReferenceType(ReferenceType.INPUT);
    reference.setContent("0 0\n1 2\n2 3\n".getBytes("ASCII"));
    DAOFactory.getReferenceDAO().save(reference, 0);
    DAOFactory.getReferenceDAO().save(reference, 1);
    reference = new Reference();
    reference.setReferenceType(ReferenceType.OUTPUT);
    reference.setContent("0\n3\n5\n".getBytes("ASCII"));
    DAOFactory.getReferenceDAO().save(reference, 0);
    DAOFactory.getReferenceDAO().save(reference, 1);
    DAOFactory.getProblemDAO().update(problem);
}
Also used : Reference(cn.edu.zju.acm.onlinejudge.bean.Reference) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) Limit(cn.edu.zju.acm.onlinejudge.bean.Limit) BeforeClass(org.junit.BeforeClass)

Example 12 with Problem

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

the class ContestManager method getProblem.

public Problem getProblem(long problemId) throws PersistenceException {
    Object key = new Long(problemId);
    synchronized (this.problemCache) {
        Problem problem = this.problemCache.get(key);
        if (problem == null) {
            ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
            problem = problemPersistence.getProblem(problemId);
            this.problemCache.put(key, problem);
        }
        return problem;
    }
}
Also used : Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ProblemPersistence(cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)

Example 13 with Problem

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

the class StatisticsManager method getRankList.

public RankList getRankList(long contestId, long roleId) throws PersistenceException {
    List<Long> key = new ArrayList<Long>();
    key.add(contestId);
    key.add(roleId);
    synchronized (this.ranklistCache) {
        RankList ranklist = this.ranklistCache.get(key);
        if (ranklist == null) {
            ranklist = new RankList();
            List<RoleSecurity> roles = PersistenceManager.getInstance().getAuthorizationPersistence().getContestRoles(contestId);
            ranklist.setRoles(roles);
            for (RoleSecurity role : roles) {
                if (role.getId() == roleId) {
                    ranklist.setRole(role);
                    break;
                }
            }
            if (roleId < 0 || ranklist.getRole() != null) {
                AbstractContest contest = ContestManager.getInstance().getContest(contestId);
                List<Problem> problems = ContestManager.getInstance().getContestProblems(contestId);
                List<RankListEntry> entries = PersistenceManager.getInstance().getSubmissionPersistence().getRankList(problems, contest.getStartTime().getTime(), roleId);
                for (RankListEntry entry : entries) {
                    entry.setUserProfile(UserManager.getInstance().getUserProfile(entry.getUserProfile().getId()));
                }
                ranklist.setEntries(entries);
            }
            this.ranklistCache.put(key, ranklist);
        }
        return ranklist;
    }
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ArrayList(java.util.ArrayList) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) RoleSecurity(cn.edu.zju.acm.onlinejudge.security.RoleSecurity)

Example 14 with Problem

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

the class ProblemPersistenceImplTest method testUpdateProblem2.

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

Example 15 with Problem

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

the class ProblemPersistenceImplTest method testGetProblem1.

/**
	 * Tests getProblem method
	 * @throws Exception to JUnit
	 */
public void testGetProblem1() throws Exception {
    Problem problem = persistence.getProblem(problem1.getId());
    checkProblem(problem1, problem);
}
Also used : Problem(cn.edu.zju.acm.onlinejudge.bean.Problem)

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