Search in sources :

Example 96 with ActionForward

use of org.apache.struts.action.ActionForward in project zoj by licheng.

the class ShowUserRoleAction method execute.

/**
 * ShowRunsAction.
 *
 * @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 admin
    ActionForward forward = this.checkAdmin(mapping, context);
    if (forward != null) {
        return forward;
    }
    long userId = Utility.parseLong(String.valueOf(context.getRequest().getParameter("userId")));
    UserProfile user = UserManager.getInstance().getUserProfile(userId);
    if (user == null) {
        return this.handleSuccess(mapping, context, "failure");
    }
    context.getRequest().setAttribute("User", user);
    context.getRequest().setAttribute("Roles", PersistenceManager.getInstance().getAuthorizationPersistence().getAllRoles());
    context.getRequest().setAttribute("UserRoles", PersistenceManager.getInstance().getAuthorizationPersistence().getUserSecurity(userId).getRoles());
    return this.handleSuccess(mapping, context, "success");
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) ActionForward(org.apache.struts.action.ActionForward)

Example 97 with ActionForward

use of org.apache.struts.action.ActionForward in project zoj by licheng.

the class SubmitAction method execute.

/**
 * SubmitAction.
 *
 * @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 {
    if (!this.isLogin(context, true)) {
        return this.handleSuccess(mapping, context, "login");
    }
    boolean isProblemset = context.getRequest().getRequestURI().endsWith("submit.do");
    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);
        submissionPersistence.createSubmission(submission, user.getId());
    } else {
        submission.setJudgeReply(JudgeReply.QUEUING);
        submissionPersistence.createSubmission(submission, user.getId());
        JudgeService.getInstance().judge(submission, Priority.NORMAL);
    }
    context.setAttribute("contestOrder", submission.getContestOrder());
    if (submitCache != null) {
        submitCache.put(user.getId(), user.getId());
    }
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) Submission(cn.edu.zju.acm.onlinejudge.bean.Submission) Reference(cn.edu.zju.acm.onlinejudge.bean.Reference) SubmissionPersistence(cn.edu.zju.acm.onlinejudge.persistence.SubmissionPersistence) ActionForward(org.apache.struts.action.ActionForward) Date(java.util.Date) Language(cn.edu.zju.acm.onlinejudge.bean.enumeration.Language) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) List(java.util.List)

Example 98 with ActionForward

use of org.apache.struts.action.ActionForward in project zoj by licheng.

the class UserSearchAction method execute.

/**
 * ShowRunsAction.
 *
 * @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.checkAdmin(mapping, context);
    if (forward != null) {
        return forward;
    }
    context.setAttribute("UserSearchForm", form);
    context.getRequest().setAttribute("Countries", PersistenceManager.getInstance().getUserPersistence().getAllCountries());
    context.getRequest().setAttribute("Roles", PersistenceManager.getInstance().getAuthorizationPersistence().getAllRoles());
    UserSearchForm userForm = (UserSearchForm) form;
    if (this.empty(userForm.getCountryId()) && this.empty(userForm.getEmail()) && this.empty(userForm.getFirstName()) && this.empty(userForm.getHandle()) && this.empty(userForm.getLastName()) && this.empty(userForm.getRoleId()) && this.empty(userForm.getSchool())) {
        return this.handleSuccess(mapping, context, "success");
    }
    UserCriteria criteria = userForm.toUserCriteria();
    String export = context.getRequest().getParameter("exportFormat");
    if ("txt".equalsIgnoreCase(export)) {
        List<UserProfile> users = PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, 0, Integer.MAX_VALUE);
        return this.export(context, criteria, users, export);
    } else if ("xls".equalsIgnoreCase(export)) {
        List<UserProfile> users = PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, 0, Integer.MAX_VALUE);
        return this.export(context, criteria, users, export);
    }
    long paging = Utility.parseLong(userForm.getPaging(), 10, 50);
    ;
    long usersNumber = PersistenceManager.getInstance().getUserPersistence().searchUserProfilesCount(criteria);
    if (usersNumber == 0) {
        context.setAttribute("users", new ArrayList<UserProfile>());
        context.setAttribute("pageNumber", new Long(0));
        context.setAttribute("totalPages", new Long(0));
        context.setAttribute("paging", new Long(paging));
        context.setAttribute("total", new Long(0));
        return this.handleSuccess(mapping, context, "success");
    }
    long totalPages = (usersNumber - 1) / paging + 1;
    long pageNumber = Utility.parseLong(userForm.getPageNumber(), 1, totalPages);
    long startIndex = paging * (pageNumber - 1);
    List<UserProfile> users = PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, (int) startIndex, (int) paging);
    context.setAttribute("users", users);
    context.setAttribute("pageNumber", new Long(pageNumber));
    context.setAttribute("totalPages", new Long(totalPages));
    context.setAttribute("paging", new Long(paging));
    context.setAttribute("total", new Long(usersNumber));
    return this.handleSuccess(mapping, context, "success");
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) UserCriteria(cn.edu.zju.acm.onlinejudge.bean.request.UserCriteria) UserSearchForm(cn.edu.zju.acm.onlinejudge.form.UserSearchForm) ArrayList(java.util.ArrayList) List(java.util.List) ActionForward(org.apache.struts.action.ActionForward)

Example 99 with ActionForward

use of org.apache.struts.action.ActionForward in project zoj by licheng.

the class ShowProblemAction method execute.

/**
 * ShowProblemAction.
 *
 * @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("showProblem.do");
    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");
}
Also used : Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ActionForward(org.apache.struts.action.ActionForward)

Example 100 with ActionForward

use of org.apache.struts.action.ActionForward 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)

Aggregations

ActionForward (org.apache.struts.action.ActionForward)125 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)16 ActionMessages (org.apache.struts.action.ActionMessages)14 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)11 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)11 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)9 ActionMessage (org.apache.struts.action.ActionMessage)9 KualiDocumentFormBase (org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase)8 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)7 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)7 ActionMapping (org.apache.struts.action.ActionMapping)7 UserContext (org.mifos.security.util.UserContext)7 IOException (java.io.IOException)6 Date (java.util.Date)6 AuthorizationPersistence (cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Cookie (javax.servlet.http.Cookie)5 IWantDocumentService (edu.cornell.kfs.module.purap.document.service.IWantDocumentService)4