Package cn.edu.zju.acm.onlinejudge.bean

Examples of cn.edu.zju.acm.onlinejudge.bean.Problem


                ps.setLong(1, id);
                ResultSet rs = ps.executeQuery();
                if (!rs.next()) {
                    return null;
                }
                Problem problem = this.populateProblem(rs);
                long limitId = rs.getLong(DatabaseConstants.PROBLEM_LIMITS_ID);
                ps = conn.prepareStatement(ProblemPersistenceImpl.GET_LIMIT);
                ps.setLong(1, limitId);
                rs = ps.executeQuery();
                if (rs.next()) {
                    Limit limit = this.populateLimit(rs);
                    problem.setLimit(limit);
                }
                return problem;
            } finally {
                Database.dispose(ps);
            }
View Full Code Here


     * @param rs
     * @return an Problem instance
     * @throws SQLException
     */
    private Problem populateProblem(ResultSet rs) throws SQLException {
        Problem problem = new Problem();
        problem.setId(rs.getLong(DatabaseConstants.PROBLEM_PROBLEM_ID));
        problem.setTitle(rs.getString(DatabaseConstants.PROBLEM_TITLE));
        problem.setContestId(rs.getLong(DatabaseConstants.PROBLEM_CONTEST_ID));
        problem.setCode(rs.getString(DatabaseConstants.PROBLEM_CODE));
        problem.setAuthor(rs.getString(DatabaseConstants.PROBLEM_AUTHOR));
        problem.setSource(rs.getString(DatabaseConstants.PROBLEM_SOURCE));
        problem.setContest(rs.getString(DatabaseConstants.PROBLEM_CONTEST));
        problem.setChecker(rs.getBoolean(DatabaseConstants.PROBLEM_CHECKER));
        problem.setRevision(rs.getInt(DatabaseConstants.PROBLEM_REVISION));
        problem.setColor(rs.getString(DatabaseConstants.PROBLEM_COLOR));
        problem.setScore(rs.getInt(DatabaseConstants.PROBLEM_SCORE));
        return problem;
    }
View Full Code Here

            try {
                ps = conn.prepareStatement(this.buildSearchQuery(criteria, offset, count));
                ResultSet rs = ps.executeQuery();
                List<Problem> problems = new ArrayList<Problem>();
                while (rs.next()) {
                    Problem problem = this.populateProblem(rs);
                    Limit limit = this.populateLimit(rs);
                    problem.setLimit(limit);
                    problems.add(problem);
                }
                return problems;
            } finally {
                Database.dispose(ps);
View Full Code Here

        ActionForward forward = this.checkProblemViewPermission(mapping, context, isProblemset);
        if (forward != null) {
            return forward;
        }

        Problem problem = context.getProblem();
        byte[] text = ContestManager.getInstance().getDescription(problem.getId());

        // StringBuffer sb = new StringBuffer();
        context.setAttribute("text", text);

        return this.handleSuccess(mapping, context, "success");
View Full Code Here

        ActionForward forward = this.checkProblemViewPermission(mapping, context, isProblemset);
        if (forward != null) {
            return forward;
        }

        Problem problem = context.getProblem();
        String orderBy = context.getRequest().getParameter("orderBy");
        if (!"date".equals(orderBy) && !"memory".equals(orderBy)) {
            orderBy = "time";
        }
        if (problem != null) {
            ProblemStatistics statistics =
                    StatisticsManager.getInstance().getProblemStatistics(problem.getId(), orderBy, 20);
            context.setAttribute("ProblemStatistics", statistics);

        }

        return this.handleSuccess(mapping, context, "success");
View Full Code Here

    }

    protected ActionForward checkProblemPermission(ActionMapping mapping, ContextAdapter context, Boolean isProblemset,
                                                   PermissionLevel level) throws Exception {

        Problem problem = context.getProblem();
        AbstractContest contest = null;

        if (problem != null) {
            contest = ContestManager.getInstance().getContest(problem.getContestId());
        }

        if (problem == null || contest == null || isProblemset != null &&
            (contest instanceof Contest || contest instanceof Course) == isProblemset.booleanValue()) {
            ActionMessages messages = new ActionMessages();
View Full Code Here

        }

        ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
        AbstractContest contest = context.getContest();

        Problem problem = problemForm.toProblem();
        if (problemForm.isUseContestDefault()) {
            problem.getLimit().setId(contest.getLimit().getId());
        }

        long userId = context.getUserSecurity().getId();
        // create problem
        problemPersistence.createProblem(problem, userId);

        // cprete problem reference, i.e. text, input, output, checker, judge solution, checker source
        this.createReference(ReferenceType.DESCRIPTION, problemForm.getDescription(), problem.getId(), userId);
        this.createReference(ReferenceType.INPUT, problemForm.getInputData(), problem.getId(), userId);
        this.createReference(ReferenceType.OUTPUT, problemForm.getOutputData(), problem.getId(), userId);
        this.createReference(ReferenceType.HEADER, problemForm.getChecker(), problem.getId(), userId);
        this.createReference(ReferenceType.CHECKER_SOURCE, problemForm.getCheckerSource(), problem.getId(), userId);
        this.createReference(ReferenceType.JUDGE_SOLUTION, problemForm.getJudgeSolution(), problem.getId(), userId);

        ContestManager.getInstance().refreshContest(problem.getContestId());

        return this.handleSuccess(mapping, context, "success", "?contestId=" + contest.getId());
    }
View Full Code Here

        ZipOutputStream out = null;
        StringBuilder sb = new StringBuilder();
        try {
            out = new ZipOutputStream(response.getOutputStream());
            for (Object obj : problems) {
                Problem p = (Problem) obj;
                this.zipReference(p, "text", ReferenceType.DESCRIPTION, out);
                this.zipReference(p, "input", ReferenceType.INPUT, out);
                this.zipReference(p, "output", ReferenceType.OUTPUT, out);
                this.zipReference(p, "solution", ReferenceType.JUDGE_SOLUTION, out);
                this.zipReference(p, "checker", ReferenceType.HEADER, out);
                this.zipReference(p, "checker", ReferenceType.CHECKER_SOURCE, out);

               
                sb.append(toCsvString(p.getCode())).append(",");
                sb.append(toCsvString(p.getTitle())).append(",");
                sb.append(p.isChecker()).append(",");
                sb.append(p.getLimit().getTimeLimit()).append(",");
                sb.append(p.getLimit().getMemoryLimit()).append(",");
                sb.append(p.getLimit().getOutputLimit()).append(",");
                sb.append(p.getLimit().getSubmissionLimit()).append(",");
                sb.append(toCsvString(p.getAuthor())).append(",");
                sb.append(toCsvString(p.getSource())).append(",");
                sb.append(toCsvString(p.getContest())).append("\n");
            }
            out.putNextEntry(new ZipEntry("problems.csv"));
            out.write(sb.toString().getBytes());

        } catch (IOException e) {
View Full Code Here

            PreparedStatement ps = null;
            List<Long> problemIds = new ArrayList<Long>();
            Map<Long, Integer> problemIndexes = new HashMap<Long, Integer>();
            int index = 0;
            for (Problem problem2 : problems) {
                Problem problem = (Problem) problem2;
                problemIds.add(new Long(problem.getId()));
                problemIndexes.put(new Long(problem.getId()), new Integer(index));
                index++;
            }
            String userIdsCon = "";
            if (roleId >= 0) {
                // TODO performance issue!!
View Full Code Here

        }

        if (problemId < 0) {
            return null;
        }
        Problem problem = ContestManager.getInstance().getProblem(problemId);
        this.setAttribute("problem", problem);
        return problem;
    }
View Full Code Here

TOP

Related Classes of cn.edu.zju.acm.onlinejudge.bean.Problem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.