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

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


            this.languageIds[i] = String.valueOf(contest.getLanguages().get(i).getId());
        }
    }

    public AbstractContest toContest() throws ParseException, NumberFormatException, PersistenceException {
        AbstractContest contest = null;
        if (this.contestType == 1) {
            contest = new Problemset();
        } else if (this.contestType == 0) {
            contest = new Contest();
        } else {
          contest = new Course();
        }
        if (this.startTime != null && this.startTime.trim().length() > 0) {
            contest.setStartTime(Utility.parseTimestamp(this.startTime));
            contest.setEndTime(new Date(Utility.parseTimestamp(this.startTime).getTime() +
                Utility.parseTime(this.contestLength) * 1000));
        }

        try {
            if (this.id != null) {
                contest.setId(Long.parseLong(this.id));
            }
        } catch (NumberFormatException e) {}

        contest.setTitle(this.name);
        contest.setDescription(this.description);
        contest.setCheckIp(this.checkIp);
        Limit limit = new Limit();
        if (this.useGlobalDefault) {
            limit.setId(1);
        } else {
            limit.setTimeLimit(Integer.parseInt(this.timeLimit));
            limit.setMemoryLimit(Integer.parseInt(this.memoryLimit));
            limit.setSubmissionLimit(Integer.parseInt(this.submissionLimit));
            limit.setOutputLimit(Integer.parseInt(this.outputLimit));
        }
        contest.setLimit(limit);
        contest.setForumId(Long.parseLong(this.forumId));

        List<Language> languages = new ArrayList<Language>();
        LanguagePersistence languagePersistence = PersistenceManager.getInstance().getLanguagePersistence();
        if (this.languageIds != null) {
            for (int i = 0; i < this.languageIds.length; ++i) {
                Language language = languagePersistence.getLanguage(Long.parseLong(this.languageIds[i]));
                if (language != null) {
                    languages.add(language);
                }
            }
        }
        contest.setLanguages(languages);

        return contest;
    }
View Full Code Here


        }

        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);
            // seePackage(pack, 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");

    }
View Full Code Here

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

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

        long languageId = Utility.parseLong(context.getRequest().getParameter("languageId"));
        Language language = PersistenceManager.getInstance().getLanguagePersistence().getLanguage(languageId);
        if (language == null) {
            return this.handleSuccess(mapping, context, "submit");
        }
        String source = context.getRequest().getParameter("source");
        if (source == null || source.length() == 0) {
            return this.handleSuccess(mapping, context, "submit");
        }
       
        List refrance = PersistenceManager.getInstance().getReferencePersistence().getProblemReferences(problem.getId(), ReferenceType.HEADER);
        if(refrance.size()!=0) {
          Reference r = (Reference)refrance.get(0);
          String percode = new String(r.getContent());
          source=percode+"\n"+source;
        }
       
        UserProfile user = context.getUserProfile();
        if (submitCache != null && submitCache.contains(user.getId())) {
          
          ActionMessages messages = new ActionMessages();      
            messages.add("message", new ActionMessage("onlinejudge.submit.interval"));
            this.saveErrors(context.getRequest(), messages);
           
            context.setAttribute("source", source);
           
          return handleSuccess(mapping, context, "submit");
        }
       
        if (contest.isCheckIp()) {
            forward = this.checkLastLoginIP(mapping, context, isProblemset);
            if (forward != null) {
                return forward;
            }
        }
        Submission submission = new Submission();
        submission.setContestId(contest.getId());
        submission.setLanguage(language);
        submission.setProblemId(problem.getId());
        submission.setUserProfileId(user.getId());
        submission.setContent(source);
        submission.setMemoryConsumption(0);
        submission.setTimeConsumption(0);
        submission.setSubmitDate(new Date());
        SubmissionPersistence submissionPersistence = PersistenceManager.getInstance().getSubmissionPersistence();

        if (contest.getEndTime() != null && new Date().after(contest.getEndTime())) {
            submission.setJudgeReply(JudgeReply.OUT_OF_CONTEST_TIME);
            submissionPersistence.createSubmission(submission, user.getId());
        } else if (source.getBytes().length > problem.getLimit().getSubmissionLimit() * 1024) {
            submission.setContent(source.substring(0, problem.getLimit().getSubmissionLimit() * 1024));
            submission.setJudgeReply(JudgeReply.SUBMISSION_LIMIT_EXCEEDED);
View Full Code Here

        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");
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.updateProblem(problem, userId);

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

        ContestManager.getInstance().refreshProblem(problem);

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

                        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);
View Full Code Here

    //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);
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.