Search in sources :

Example 11 with AbstractContest

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

the class ShowQQAction method execute.

/**
     * ShowQQAction.
     * 
     * @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 {
    ActionForward forward = this.checkContestAdminPermission(mapping, context, false, true);
    if (forward != null) {
        return forward;
    }
    AbstractContest contest = context.getContest();
    List<QQ> qqs = PersistenceManager.getInstance().getSubmissionPersistence().searchQQs(contest.getId());
    context.setAttribute("qqs", qqs);
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) QQ(cn.edu.zju.acm.onlinejudge.bean.QQ) ActionForward(org.apache.struts.action.ActionForward)

Example 12 with AbstractContest

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

the class ShowRankListAction method execute.

/**
     * ShowRankListAction.
     * 
     * @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("showRankList.do");
    ActionForward forward = this.checkContestViewPermission(mapping, context, isProblemset, true);
    if (forward != null) {
        return forward;
    }
    AbstractContest contest = context.getContest();
    if (!isProblemset) {
        List<Problem> problems = context.getProblems();
        context.setAttribute("problems", problems);
        long roleId = Utility.parseLong(context.getRequest().getParameter("roleId"));
        RankList ranklist = StatisticsManager.getInstance().getRankList(contest.getId(), roleId);
        String export = context.getRequest().getParameter("export");
        if ("txt".equalsIgnoreCase(export)) {
            return this.export(context, contest, problems, ranklist, export);
        } else if ("xls".equalsIgnoreCase(export)) {
            return this.export(context, contest, problems, ranklist, export);
        }
        context.setAttribute("RankList", ranklist);
    } else {
        int from = Utility.parseInt(context.getRequest().getParameter("from"));
        if (from < 0) {
            from = 0;
        }
        int count = 30;
        String sort = context.getRequest().getParameter("order");
        if (sort == null || !sort.equalsIgnoreCase("submit")) {
            sort = "ac";
        }
        ProblemsetRankList ranklist = StatisticsManager.getInstance().getProblemsetRankList(contest.getId(), from, count, sort);
        if (from > 0) {
            context.setAttribute("previousFrom", from - count > 0 ? from - count : 0);
        }
        if (ranklist.getSolved().length == count) {
            context.setAttribute("nextFrom", from + count);
        }
        context.setAttribute("RankList", ranklist);
    }
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ProblemsetRankList(cn.edu.zju.acm.onlinejudge.util.ProblemsetRankList) RankList(cn.edu.zju.acm.onlinejudge.util.RankList) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ProblemsetRankList(cn.edu.zju.acm.onlinejudge.util.ProblemsetRankList) ActionForward(org.apache.struts.action.ActionForward)

Example 13 with AbstractContest

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

the class ShowStatisticsAction method execute.

/**
     * ShowStatisticsAction.
     * 
     * @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("showStatistics.do");
    ActionForward forward = this.checkContestViewPermission(mapping, context, isProblemset, true);
    if (forward != null) {
        return forward;
    }
    AbstractContest contest = context.getContest();
    ContestStatistics statistics = StatisticsManager.getInstance().getContestStatistics(contest.getId());
    context.setAttribute("ContestStatistics", statistics);
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ActionForward(org.apache.struts.action.ActionForward) ContestStatistics(cn.edu.zju.acm.onlinejudge.util.ContestStatistics)

Example 14 with AbstractContest

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

the class ProblemImportAction method execute.

/**
     * ProblemImportAction.
     * 
     * @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("importProblems.do");
    ActionForward forward = this.checkContestAdminPermission(mapping, context, isProblemset, false);
    if (forward != null) {
        return forward;
    }
    ProblemPackage pack = (ProblemPackage) context.getSessionAttribute("ProblemPackage");
    context.setSessionAttribute("ProblemPackage", null);
    AbstractContest contest = context.getContest();
    InputStream in = null;
    String filePath = context.getRequest().getParameter("problemFilePath");
    FormFile file = ((ProblemImportForm) form).getProblemFile();
    if (filePath != null && filePath.trim().length() > 0) {
        in = new FileInputStream(filePath);
    } else if (file != null) {
        in = file.getInputStream();
    }
    if (in != null) {
        ActionMessages messages = new ActionMessages();
        pack = ProblemManager.importProblem(in, messages);
        if (messages.size() > 0) {
            return this.handleFailure(mapping, context, messages);
        }
        context.setSessionAttribute("ProblemPackage", pack);
        return this.handleSuccess(mapping, context, "preview");
    }
    if (pack == null) {
        return this.handleSuccess(mapping, context, "selectcontest");
    }
    try {
        ProblemImportAction.createProblems(pack, contest.getId());
        /*
             * ProblemCriteria criteria = new ProblemCriteria(); criteria.setContestId(new Long(contest.getId()));
             * 
             * // remove List oldProblems = problemPersistence.searchProblems(criteria); for (Iterator it =
             * oldProblems.iterator(); it.hasNext();) { problemPersistence.deleteProblem(((Problem) it.next()).getId(),
             * 0); }
             */
        ContestManager.getInstance().refreshContest(contest.getId());
    } catch (Exception pe) {
        this.error(pe);
        ActionMessages messages = new ActionMessages();
        messages.add("message", new ActionMessage("onlinejudge.importProblems.failure"));
        this.saveErrors(context.getRequest(), messages);
        context.setAttribute("back", "editContest.do?contestId=" + contest.getId());
        return this.handleSuccess(mapping, context, "success");
    }
    ActionMessages messages = new ActionMessages();
    messages.add("message", new ActionMessage("onlinejudge.importProblems.success"));
    this.saveErrors(context.getRequest(), messages);
    context.setAttribute("back", "showContestProblems.do?contestId=" + contest.getId());
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ProblemImportForm(cn.edu.zju.acm.onlinejudge.form.ProblemImportForm) ProblemPackage(cn.edu.zju.acm.onlinejudge.util.ProblemPackage) ActionMessages(org.apache.struts.action.ActionMessages) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ActionMessage(org.apache.struts.action.ActionMessage) ActionForward(org.apache.struts.action.ActionForward) FileInputStream(java.io.FileInputStream) FormFile(org.apache.struts.upload.FormFile)

Example 15 with AbstractContest

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

the class ContestPersistenceImpl method populateContest.

/**
     * Populates an AbstractContest with given ResultSet.
     * 
     * @param rs
     * @return an AbstractContest instance
     * @throws SQLException
     */
private AbstractContest populateContest(ResultSet rs) throws SQLException {
    AbstractContest contest = null;
    int contestType = rs.getInt(DatabaseConstants.CONTEST_PROBLEMSET);
    if (contestType == 1) {
        contest = new Problemset();
    } else if (contestType == 0) {
        contest = new Contest();
    } else {
        contest = new Course();
    }
    if (rs.getTimestamp(DatabaseConstants.CONTEST_START_TIME) != null) {
        contest.setStartTime(new Date(rs.getTimestamp(DatabaseConstants.CONTEST_START_TIME).getTime()));
    }
    if (rs.getTimestamp(DatabaseConstants.CONTEST_END_TIME) != null) {
        contest.setEndTime(new Date(rs.getTimestamp(DatabaseConstants.CONTEST_END_TIME).getTime()));
    }
    contest.setId(rs.getLong(DatabaseConstants.CONTEST_CONTEST_ID));
    contest.setTitle(rs.getString(DatabaseConstants.CONTEST_TITLE));
    contest.setDescription(rs.getString(DatabaseConstants.CONTEST_DESCRIPTION));
    contest.setForumId(rs.getLong(DatabaseConstants.CONTEST_FORUM_ID));
    contest.setCheckIp(rs.getBoolean(DatabaseConstants.CONTEST_CHECK_IP));
    Limit limit = new Limit();
    limit.setId(rs.getLong(DatabaseConstants.LIMITS_LIMITS_ID));
    limit.setTimeLimit(rs.getInt(DatabaseConstants.LIMITS_TIME_LIMIT));
    limit.setMemoryLimit(rs.getInt(DatabaseConstants.LIMITS_MEMORY_LIMIT));
    limit.setSubmissionLimit(rs.getInt(DatabaseConstants.LIMITS_SUBMISSION_LIMIT));
    limit.setOutputLimit(rs.getInt(DatabaseConstants.LIMITS_OUTPUT_LIMIT));
    contest.setLimit(limit);
    return contest;
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest) Limit(cn.edu.zju.acm.onlinejudge.bean.Limit) Problemset(cn.edu.zju.acm.onlinejudge.bean.Problemset) Course(cn.edu.zju.acm.onlinejudge.bean.Course) Date(java.util.Date)

Aggregations

AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)31 ActionForward (org.apache.struts.action.ActionForward)16 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)10 ActionMessages (org.apache.struts.action.ActionMessages)10 ArrayList (java.util.ArrayList)8 ActionMessage (org.apache.struts.action.ActionMessage)8 Contest (cn.edu.zju.acm.onlinejudge.bean.Contest)5 ContestPersistence (cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence)5 Course (cn.edu.zju.acm.onlinejudge.bean.Course)4 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)4 Date (java.util.Date)4 Limit (cn.edu.zju.acm.onlinejudge.bean.Limit)3 Problemset (cn.edu.zju.acm.onlinejudge.bean.Problemset)3 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)3 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)2 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)2 ContestForm (cn.edu.zju.acm.onlinejudge.form.ContestForm)2