Search in sources :

Example 16 with AbstractContest

use of cn.edu.zju.acm.onlinejudge.bean.AbstractContest 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 17 with AbstractContest

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

the class ContestPersistenceImplTest method testGetContest5.

/**
	 * Tests getContest method
	 * @throws Exception to JUnit
	 */
public void testGetContest5() throws Exception {
    AbstractContest contest = (AbstractContest) persistence.getContest(1234567890l);
    assertNull("no such contest", contest);
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest)

Example 18 with AbstractContest

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

the class SearchProblemAction method execute.

@Override
protected ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
    //System.out.println("SearchProblemAction begin");
    List<Problem> TitleQueryResult = new ArrayList<Problem>();
    List<Problem> AuthorQueryResult = new ArrayList<Problem>();
    List<Problem> SourceQueryResult = new ArrayList<Problem>();
    AbstractContest contest = context.getContest();
    String query = context.getRequest().getParameter("query").toLowerCase();
    String temp = context.getRequest().getParameter("titlefrom");
    int titlefrom = Integer.parseInt(temp);
    temp = context.getRequest().getParameter("authorfrom");
    int authorfrom = Integer.parseInt(temp);
    temp = context.getRequest().getParameter("sourcefrom");
    int sourcefrom = Integer.parseInt(temp);
    List<Problem> problems = ContestManager.getInstance().getContestProblems(contest.getId());
    for (int i = 0; i < problems.size(); ++i) {
        Problem p = problems.get(i);
        if (p.getTitle() != null) {
            if (p.getTitle().toLowerCase().indexOf(query) >= 0) {
                TitleQueryResult.add(p);
            }
        }
        if (p.getAuthor() != null) {
            if (p.getAuthor().toLowerCase().indexOf(query) >= 0) {
                AuthorQueryResult.add(p);
            }
        }
        if (p.getSource() != null) {
            if (p.getSource().toLowerCase().indexOf(query) >= 0) {
                SourceQueryResult.add(p);
            }
        }
    }
    context.setAttribute("TitleQueryResultCount", TitleQueryResult.size());
    if (titlefrom * 50 + 49 > TitleQueryResult.size()) {
        context.setAttribute("TitleQueryResult", TitleQueryResult.subList(titlefrom * 50, TitleQueryResult.size()));
    } else {
        context.setAttribute("TitleQueryResult", TitleQueryResult.subList(titlefrom * 50, titlefrom * 50 + 49));
    }
    context.setAttribute("titlefrom", titlefrom);
    context.setAttribute("AuthorQueryResultCount", AuthorQueryResult.size());
    if (authorfrom * 50 + 49 > AuthorQueryResult.size()) {
        context.setAttribute("AuthorQueryResult", AuthorQueryResult.subList(authorfrom * 50, AuthorQueryResult.size()));
    } else {
        context.setAttribute("AuthorQueryResult", AuthorQueryResult.subList(authorfrom * 50, authorfrom * 50 + 49));
    }
    context.setAttribute("authorfrom", authorfrom);
    context.setAttribute("SourceQueryResultCount", SourceQueryResult.size());
    if (sourcefrom * 50 + 49 > SourceQueryResult.size()) {
        context.setAttribute("SourceQueryResult", SourceQueryResult.subList(sourcefrom * 50, SourceQueryResult.size()));
    } else {
        context.setAttribute("SourceQueryResult", SourceQueryResult.subList(sourcefrom * 50, sourcefrom * 50 + 49));
    }
    context.setAttribute("sourcefrom", sourcefrom);
    context.setAttribute("query", query);
    //System.out.println("SearchProblemAction end");
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ArrayList(java.util.ArrayList) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem)

Example 19 with AbstractContest

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

the class ShowProblemsAction method execute.

/**
     * ShowProblemsAction.
     * 
     * @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
    //System.out.println("in show problems");
    boolean isProblemset = context.getRequest().getRequestURI().endsWith("showProblems.do");
    //boolean isCourse=context.getRequest().getRequestURI().endsWith("showCourseProblems.do");
    ActionForward forward = this.checkContestViewPermission(mapping, context, isProblemset, true);
    if (forward != null) {
        return forward;
    }
    AbstractContest contest = context.getContest();
    //System.out.println("" + contest.getId());
    long problemsCount = ContestManager.getInstance().getProblemsCount(contest.getId());
    long pageNumber = Utility.parseLong(context.getRequest().getParameter("pageNumber"));
    if (pageNumber < 1) {
        pageNumber = 1;
    }
    long problemsPerPage = 100;
    if (problemsCount <= (pageNumber - 1) * problemsPerPage) {
        pageNumber = 1;
    }
    long totalPages = 1;
    if (problemsCount > 0) {
        totalPages = (problemsCount - 1) / problemsPerPage + 1;
    }
    List<Problem> oproblems = ContestManager.getInstance().getContestProblems(contest.getId(), (int) ((pageNumber - 1) * problemsPerPage), (int) problemsPerPage);
    List<Problem> problems = new ArrayList<Problem>();
    problems.addAll(oproblems);
    ContestStatistics contestStatistics = null;
    contestStatistics = StatisticsManager.getInstance().getContestStatistics(contest.getId(), (int) ((pageNumber - 1) * problemsPerPage), (int) problemsPerPage);
    for (int i = 0; i < problems.size(); ++i) {
        Problem p = (Problem) problems.get(i);
        int ac = contestStatistics.getCount(i, 0);
        int total = contestStatistics.getProblemCount(i);
        p.setTotal(total);
        p.setAC(ac);
        if (total == 0) {
            p.setRatio(0);
        } else {
            p.setRatio((double) ac / (double) total);
        }
    }
    String order = context.getRequest().getParameter("order");
    if (order != null) {
        if (order.equalsIgnoreCase("ratio")) {
            Collections.sort(problems, new Comparator() {

                public int compare(Object o1, Object o2) {
                    return (((Problem) o2).getRatio() - ((Problem) o1).getRatio()) > 0 ? 1 : -1;
                }
            });
        } else if (order.equalsIgnoreCase("ac")) {
            Collections.sort(problems, new Comparator() {

                public int compare(Object o1, Object o2) {
                    return ((Problem) o2).getAC() - ((Problem) o1).getAC();
                }
            });
        } else if (order.equalsIgnoreCase("all")) {
            Collections.sort(problems, new Comparator() {

                public int compare(Object o1, Object o2) {
                    return ((Problem) o2).getTotal() - ((Problem) o1).getTotal();
                }
            });
        }
    }
    UserStatistics userStatistics = null;
    if (context.getUserProfile() != null && problems.size() > 0) {
        userStatistics = StatisticsManager.getInstance().getUserStatistics(contest.getId(), context.getUserProfile().getId());
    }
    context.setAttribute("problems", problems);
    context.setAttribute("pageNumber", (new Long(pageNumber)).toString());
    context.setAttribute("ContestStatistics", contestStatistics);
    context.setAttribute("UserStatistics", userStatistics);
    context.setAttribute("totalPages", new Long(totalPages));
    context.setAttribute("currentPage", new Long(pageNumber));
    if (this.checkContestAdminPermission(mapping, context, isProblemset, true) == null && "true".equalsIgnoreCase(context.getRequest().getParameter("check"))) {
        List<String> checkMessages = new ArrayList<String>();
        for (Object obj : problems) {
            Problem p = (Problem) obj;
            this.checkExists("Text", this.getReferenceLength(p, ReferenceType.DESCRIPTION), "ERROR", checkMessages, p);
            this.checkExists("Input", this.getReferenceLength(p, ReferenceType.INPUT), "ERROR", checkMessages, p);
            if (p.isChecker()) {
                this.checkExists("Output", this.getReferenceLength(p, ReferenceType.OUTPUT), "WARNING", checkMessages, p);
                // checkExists("Checker", getReferenceLength(p, ReferenceType.CHECKER), "WARNING", checkMessages,
                // p);
                this.checkExists("Checker source", this.getReferenceLength(p, ReferenceType.CHECKER_SOURCE), "ERROR", checkMessages, p);
            } else {
                this.checkExists("Output", this.getReferenceLength(p, ReferenceType.OUTPUT), "ERROR", checkMessages, p);
            }
            this.checkExists("Judge solution", this.getReferenceLength(p, ReferenceType.JUDGE_SOLUTION), "WARNING", checkMessages, p);
        }
        context.setAttribute("CheckMessages", checkMessages);
    }
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ArrayList(java.util.ArrayList) ActionForward(org.apache.struts.action.ActionForward) UserStatistics(cn.edu.zju.acm.onlinejudge.util.UserStatistics) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ContestStatistics(cn.edu.zju.acm.onlinejudge.util.ContestStatistics)

Example 20 with AbstractContest

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

the class BaseAction method checkContestPermission.

protected ActionForward checkContestPermission(ActionMapping mapping, ContextAdapter context, Boolean isProblemset, boolean checkStart, PermissionLevel level) throws Exception {
    // get the contest
    AbstractContest contest = context.getContest();
    if (contest == null || isProblemset != null && (contest instanceof Contest || contest instanceof Course) == isProblemset.booleanValue()) {
        context.setAttribute("contest", null);
        ActionMessages messages = new ActionMessages();
        messages.add("message", new ActionMessage("onlinejudge.showcontest.nocontestid"));
        this.saveErrors(context.getRequest(), messages);
        if (isProblemset != null) {
            context.setAttribute("back", isProblemset ? "showProblemsets.do" : "showContests.do");
        }
        return this.handleFailure(mapping, context, messages, "nopermission");
    }
    context.setAttribute("contest", contest);
    // check contest permission
    UserSecurity userSecurity = context.getUserSecurity();
    boolean hasPermisstion = false;
    if (level == PermissionLevel.ADMIN) {
        hasPermisstion = userSecurity.canAdminContest(contest.getId());
    } else if (level == PermissionLevel.PARTICIPATE) {
        hasPermisstion = userSecurity.canParticipateContest(contest.getId());
    } else if (level == PermissionLevel.VIEW) {
        hasPermisstion = userSecurity.canViewContest(contest.getId());
    } else if (level == PermissionLevel.PARTICIPATECANVIEWSOURCE) {
        hasPermisstion = userSecurity.canViewSource(contest.getId());
    }
    if (!hasPermisstion) {
        ActionMessages messages = new ActionMessages();
        messages.add("message", new ActionMessage("onlinejudge.showcontest.nopermission"));
        this.saveErrors(context.getRequest(), messages);
        if (isProblemset != null) {
            context.setAttribute("back", isProblemset ? "showProblemsets.do" : "showContests.do");
        }
        return this.handleFailure(mapping, context, messages, "nopermission");
    }
    // check start time
    if (checkStart && !userSecurity.canAdminContest(contest.getId())) {
        return this.checkContestStart(mapping, context, contest);
    }
    return null;
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) UserSecurity(cn.edu.zju.acm.onlinejudge.security.UserSecurity) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest) Course(cn.edu.zju.acm.onlinejudge.bean.Course)

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