Search in sources :

Example 6 with AbstractContest

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

the class ChangeQQStatusAction 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.checkProblemAdminPermission(mapping, context, false);
    if (forward != null) {
        return forward;
    }
    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());
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ActionForward(org.apache.struts.action.ActionForward)

Example 7 with AbstractContest

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

the class ShowUserStatusAction method execute.

/**
     * Method execute
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
    UserProfile user = null;
    String handle = context.getRequest().getParameter("handle");
    if (handle != null && handle.length() > 0) {
        // TODO cache?
        user = PersistenceManager.getInstance().getUserPersistence().getUserProfileByHandle(handle);
    } else if (context.getRequest().getParameter("userId") != null) {
        long userId = Utility.parseLong(context.getRequest().getParameter("userId"));
        if (userId != -1) {
            user = PersistenceManager.getInstance().getUserPersistence().getUserProfile(userId);
        }
    } else {
        user = context.getUserProfile();
    }
    AbstractContest contest = null;
    if (user != null) {
        long contestId = Utility.parseLong(context.getRequest().getParameter("contestId"));
        if (contestId == -1) {
            contestId = ShowUserStatusAction.defaultProblemSetId;
        }
        contest = ContestManager.getInstance().getContest(contestId);
    }
    if (contest != null) {
        context.setAttribute("contest", contest);
        ActionForward forward = this.checkContestViewPermission(mapping, context, null, true);
        if (forward != null) {
            contest = null;
        }
    }
    UserStatistics statistics = null;
    UserPreference pref = null;
    if (contest != null && user != null) {
        // TODO cache?
        pref = PersistenceManager.getInstance().getUserPersistence().getUserPreference(user.getId());
        statistics = StatisticsManager.getInstance().getUserStatistics(contest.getId(), user.getId());
    }
    context.setAttribute("user", user);
    context.setAttribute("preference", pref);
    context.setAttribute("contest", contest);
    context.setAttribute("UserStatistics", statistics);
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) UserStatistics(cn.edu.zju.acm.onlinejudge.util.UserStatistics) UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) UserPreference(cn.edu.zju.acm.onlinejudge.bean.UserPreference) ActionForward(org.apache.struts.action.ActionForward)

Example 8 with AbstractContest

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

the class ContestForm method populate.

public void populate(AbstractContest contest) {
    this.id = String.valueOf(contest.getId());
    this.name = contest.getTitle();
    this.description = contest.getDescription();
    this.forumId = String.valueOf(contest.getForumId());
    if (contest instanceof Contest) {
        this.contestType = 0;
    } else if (contest instanceof Problemset) {
        this.contestType = 1;
    } else {
        this.contestType = 2;
    }
    if (contest.getStartTime() != null) {
        this.startTime = Utility.toTimestamp(contest.getStartTime());
        this.contestLength = contest.getHours() + ":" + contest.getMinutes() + ":" + contest.getSeconds();
    } else {
        this.startTime = "";
        this.contestLength = "";
    }
    this.checkIp = contest.isCheckIp();
    Limit limit = contest.getLimit();
    this.useGlobalDefault = limit.getId() == Limit.DEFAULT_LIMIT_ID;
    this.timeLimit = String.valueOf(limit.getTimeLimit());
    this.memoryLimit = String.valueOf(limit.getMemoryLimit());
    this.submissionLimit = String.valueOf(limit.getSubmissionLimit());
    this.outputLimit = String.valueOf(limit.getOutputLimit());
    this.languageIds = new String[contest.getLanguages().size()];
    for (int i = 0; i < this.languageIds.length; ++i) {
        this.languageIds[i] = String.valueOf(contest.getLanguages().get(i).getId());
    }
}
Also used : 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)

Example 9 with AbstractContest

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

the class EditProblemAction method execute.

/**
     * EditProblemAction.
     * 
     * @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("editProblem.do");
    ActionForward forward = this.checkProblemAdminPermission(mapping, context, isProblemset);
    if (forward != null) {
        return forward;
    }
    ProblemForm problemForm = (ProblemForm) form;
    if (problemForm == null || problemForm.getName() == null) {
        Problem problem = context.getProblem();
        problemForm.populate(problem, context.getContest());
        this.setReference("DescriptionRef", ReferenceType.DESCRIPTION, problem.getId(), context);
        this.setReference("InputRef", ReferenceType.INPUT, problem.getId(), context);
        this.setReference("OutputRef", ReferenceType.OUTPUT, problem.getId(), context);
        this.setReference("JudgeSolutionRef", ReferenceType.JUDGE_SOLUTION, problem.getId(), context);
        this.setReference("HeaderRef", ReferenceType.HEADER, problem.getId(), context);
        this.setReference("CheckerSourceRef", ReferenceType.CHECKER_SOURCE, problem.getId(), context);
        return this.handleSuccess(mapping, context, "failure");
    }
    // check title and code
    ActionMessages errors = this.validate(problemForm, context);
    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());
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ProblemForm(cn.edu.zju.acm.onlinejudge.form.ProblemForm) ActionMessages(org.apache.struts.action.ActionMessages) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ActionForward(org.apache.struts.action.ActionForward) ProblemPersistence(cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)

Example 10 with AbstractContest

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

the class EditRoleAction method execute.

/**
     * Edit Role.
     * 
     * <pre>
     * </pre>
     * 
     * @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;
    }
    RoleForm roleForm = (RoleForm) form;
    AuthorizationPersistence authorizationPersistence = PersistenceManager.getInstance().getAuthorizationPersistence();
    if (roleForm.getId() == null || roleForm.getId().trim().length() == 0) {
        long roleId = Utility.parseLong(context.getRequest().getParameter("roleId"));
        RoleSecurity role = authorizationPersistence.getRole(roleId);
        if (role == null) {
            return this.handleSuccess(mapping, context, "success");
        }
        // add contest names
        Map<Long, String> contestNames = new TreeMap<Long, String>();
        for (AbstractContest contest : ContestManager.getInstance().getAllContests()) {
            contestNames.put(contest.getId(), contest.getTitle());
        }
        for (AbstractContest contest : ContestManager.getInstance().getAllProblemsets()) {
            contestNames.put(contest.getId(), contest.getTitle());
        }
        for (AbstractContest contest : ContestManager.getInstance().getAllCourses()) {
            contestNames.put(contest.getId(), contest.getTitle());
        }
        context.setAttribute("ContestNames", contestNames);
        // TODO add forums
        Map<Long, String> forumNames = new TreeMap<Long, String>();
        forumNames.put(1L, "ZOJ Forum");
        context.setAttribute("ForumNames", forumNames);
        roleForm.populate(role);
        return this.handleSuccess(mapping, context, "failure");
    }
    RoleSecurity role = roleForm.toRole();
    authorizationPersistence.updateRole(role, context.getUserProfile().getId());
    if (role.getId() == 1) {
        ContextAdapter.resetDefaultUserSecurity();
    }
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) AuthorizationPersistence(cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence) RoleForm(cn.edu.zju.acm.onlinejudge.form.RoleForm) TreeMap(java.util.TreeMap) ActionForward(org.apache.struts.action.ActionForward) RoleSecurity(cn.edu.zju.acm.onlinejudge.security.RoleSecurity)

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