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

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


    }

    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;
    }
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();
            messages.add("message", new ActionMessage("onlinejudge.showproblem.noproblemid"));
            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);
        context.setAttribute("problem", problem);

        // 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.PARTICIPATECANVIEWSOURCE) {
            hasPermisstion = userSecurity.canViewSource(contest.getId());
        } else if (level == PermissionLevel.VIEW) {
            hasPermisstion = userSecurity.canViewContest(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 (userSecurity.canAdminContest(contest.getId())) {
            return null;
        } else {
            return this.checkContestStart(mapping, context, contest);
        }
View Full Code Here

        if (errors.size() > 0) {
            return this.handleFailure(mapping, context, errors);
        }

        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

        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");

    }
View Full Code Here

        }

        ContestForm contestForm = (ContestForm) form;

        if (contestForm.getId() == null) {
            AbstractContest contest = context.getContest();
            contestForm.populate(contest);
            return this.handleSuccess(mapping, context);
        } else {
            ContestPersistence persistence = PersistenceManager.getInstance().getContestPersistence();
            AbstractContest contest = contestForm.toContest();
            persistence.updateContest(contest, context.getUserSecurity().getId());
            ContestManager.getInstance().refreshContest(contest.getId());

            ActionMessages messages = new ActionMessages();
            messages.add("message", new ActionMessage("onlinejudge.editContest.success"));
            this.saveErrors(context.getRequest(), messages);
            context.setAttribute("back", (isProblemset ? "problemsetInfo.do" : "contestInfo.do") + "?contestId=" +
                contest.getId());

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

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

        AbstractContest contest = context.getContest();
        ContestPersistence contestPersistence = PersistenceManager.getInstance().getContestPersistence();
        contestPersistence.deleteContest(contest.getId(), context.getUserSecurity().getId());

        ContestManager.getInstance().refreshContest(contest.getId());

        ActionMessages messages = new ActionMessages();
        if (isProblemset) {
            messages.add("message", new ActionMessage("onlinejudge.deleteProblemset.success"));
        } else {
View Full Code Here

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

        AbstractContest contest = context.getContest();
        List<Problem> problems = ContestManager.getInstance().getContestProblems(contest.getId());

        HttpServletResponse response = context.getResponse();
        response.setContentType("application/zip");
        response.setHeader("Content-disposition", "attachment; filename=" + this.convertFilename(contest.getTitle()) +
            ".zip");

        ZipOutputStream out = null;
        StringBuilder sb = new StringBuilder();
        try {
View Full Code Here

        }

        if (contestId < 0) {
            return null;
        }
        AbstractContest contest = ContestManager.getInstance().getContest(contestId);
        this.setAttribute("contest", contest);

        return contest;
    }
View Full Code Here

        return problem;
    }

    public List<Problem> getProblems() throws PersistenceException {

        AbstractContest contest = this.getContest();
        if (contest == null) {
            return new ArrayList<Problem>();
        }
        return ContestManager.getInstance().getContestProblems(contest.getId());

    }
View Full Code Here

        }

        if (forward != null) {
            return forward;
        }
        AbstractContest contest = context.getContest();
        long uid = Utility.parseLong(context.getRequest().getParameter("userProfileId"));
        long pid = Utility.parseLong(context.getRequest().getParameter("problemId"));

        String status = context.getRequest().getParameter("status");
        if (pid != -1 && uid != -1) {
            PersistenceManager.getInstance().getSubmissionPersistence().changeQQStatus(pid, uid, status);
        }
        return this.handleSuccess(mapping, context, "success", "?contestId=" + contest.getId());

    }
View Full Code Here

TOP

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

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.