Search in sources :

Example 1 with Contest

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

the class BaseAction method checkProblemPermission.

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);
    }
}
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) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest) Course(cn.edu.zju.acm.onlinejudge.bean.Course)

Example 2 with Contest

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

the class ContestPersistenceImplTest method testUpdateContest1.

/**
 * Tests updateContest method
 * @throws Exception to JUnit
 */
public void testUpdateContest1() throws Exception {
    contest1.setDescription("new");
    contest1.setTitle("new");
    contest1.setLanguages(null);
    contest1.setLimit(null);
    contest1.setForumId(forum2.getId());
    contest1.setStartTime(new Date(20000));
    contest1.setEndTime(new Date(30000));
    persistence.updateContest(contest1, 11);
    Contest contest = (Contest) persistence.getContest(contest1.getId());
    checkAbstractContest(contest1, contest);
    assertEquals("wrong start time", contest.getStartTime(), contest1.getStartTime());
    assertEquals("wrong end time", contest.getEndTime(), contest1.getEndTime());
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest) Date(java.util.Date)

Example 3 with Contest

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

the class ContestPersistenceImplTest method testGetContest1.

/**
 * Tests getContest method
 * @throws Exception to JUnit
 */
public void testGetContest1() throws Exception {
    Contest contest = (Contest) persistence.getContest(contest1.getId());
    checkAbstractContest(contest1, contest);
    assertEquals("wrong start time", contest.getStartTime(), contest1.getStartTime());
    assertEquals("wrong end time", contest.getEndTime(), contest1.getEndTime());
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest)

Example 4 with Contest

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

the class ContestPersistenceImpl method populateContest.

/**
 * Populates an AbstractContest with given ResultSet.
 *
 * @param rs
 * @return an AbstractContest instance
 * @throws SQLException
 */
private AbstractContest populateContest(ResultSet rs) throws SQLException {
    AbstractContest contest = null;
    int contestType = rs.getInt(DatabaseConstants.CONTEST_PROBLEMSET);
    if (contestType == 1) {
        contest = new Problemset();
    } else if (contestType == 0) {
        contest = new Contest();
    } else {
        contest = new Course();
    }
    if (rs.getTimestamp(DatabaseConstants.CONTEST_START_TIME) != null) {
        contest.setStartTime(new Date(rs.getTimestamp(DatabaseConstants.CONTEST_START_TIME).getTime()));
    }
    if (rs.getTimestamp(DatabaseConstants.CONTEST_END_TIME) != null) {
        contest.setEndTime(new Date(rs.getTimestamp(DatabaseConstants.CONTEST_END_TIME).getTime()));
    }
    contest.setId(rs.getLong(DatabaseConstants.CONTEST_CONTEST_ID));
    contest.setTitle(rs.getString(DatabaseConstants.CONTEST_TITLE));
    contest.setDescription(rs.getString(DatabaseConstants.CONTEST_DESCRIPTION));
    contest.setForumId(rs.getLong(DatabaseConstants.CONTEST_FORUM_ID));
    contest.setCheckIp(rs.getBoolean(DatabaseConstants.CONTEST_CHECK_IP));
    Limit limit = new Limit();
    limit.setId(rs.getLong(DatabaseConstants.LIMITS_LIMITS_ID));
    limit.setTimeLimit(rs.getInt(DatabaseConstants.LIMITS_TIME_LIMIT));
    limit.setMemoryLimit(rs.getInt(DatabaseConstants.LIMITS_MEMORY_LIMIT));
    limit.setSubmissionLimit(rs.getInt(DatabaseConstants.LIMITS_SUBMISSION_LIMIT));
    limit.setOutputLimit(rs.getInt(DatabaseConstants.LIMITS_OUTPUT_LIMIT));
    contest.setLimit(limit);
    return contest;
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) 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) Course(cn.edu.zju.acm.onlinejudge.bean.Course) Date(java.util.Date)

Example 5 with Contest

use of cn.edu.zju.acm.onlinejudge.bean.Contest 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)

Aggregations

Contest (cn.edu.zju.acm.onlinejudge.bean.Contest)13 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)11 Date (java.util.Date)7 Course (cn.edu.zju.acm.onlinejudge.bean.Course)4 Limit (cn.edu.zju.acm.onlinejudge.bean.Limit)3 Problemset (cn.edu.zju.acm.onlinejudge.bean.Problemset)3 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)2 ArrayList (java.util.ArrayList)2 ActionMessage (org.apache.struts.action.ActionMessage)2 ActionMessages (org.apache.struts.action.ActionMessages)2 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)1 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)1 LanguagePersistence (cn.edu.zju.acm.onlinejudge.persistence.LanguagePersistence)1 List (java.util.List)1