Search in sources :

Example 6 with Contest

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

the class SubmissionPersistenceImplTest method newContest.

/**
	 * Creates a new contest.
	 * @param id the id
	 * @param forumId the forum id
	 * @param limit the limit
	 * @param languages  a list of languages
	 * @return a new Contest instance
	 */
private Contest newContest(long id, long forumId, Limit limit, List languages) {
    Contest contest = new Contest();
    contest.setId(id);
    contest.setDescription("desc" + id);
    contest.setLimit(limit);
    contest.setLanguages(languages);
    contest.setTitle("title" + id);
    contest.setForumId(forumId);
    contest.setStartTime(new Date(id * 1000));
    contest.setEndTime(new Date(id * 2000));
    return contest;
}
Also used : Contest(cn.edu.zju.acm.onlinejudge.bean.Contest) Date(java.util.Date)

Example 7 with Contest

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

the class BaseAction method checkContestPermission.

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;
}
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) 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 8 with Contest

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

the class ProblemPersistenceImplTest method newContest.

/**
	 * Creates a new contest.
	 * @param id the id
	 * @param forumId the forum id
	 * @param limit the limit
	 * @param languages  a list of languages
	 * @return a new Contest instance
	 */
private Contest newContest(long id, long forumId, Limit limit, List languages) {
    Contest contest = new Contest();
    contest.setId(id);
    contest.setDescription("desc" + id);
    contest.setLimit(limit);
    contest.setLanguages(languages);
    contest.setTitle("title" + id);
    contest.setForumId(forumId);
    contest.setStartTime(new Date(id * 1000));
    contest.setEndTime(new Date(id * 2000));
    return contest;
}
Also used : Contest(cn.edu.zju.acm.onlinejudge.bean.Contest) Date(java.util.Date)

Example 9 with Contest

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

the class ContestPersistenceImplTest method newContest.

/**
	 * Creates a new contest.
	 * @param id the id
	 * @param forumId the forum id
	 * @param limit the limit
	 * @param languages  a list of languages
	 * @return a new Contest instance
	 */
private Contest newContest(long id, long forumId, Limit limit, List languages) {
    Contest contest = new Contest();
    contest.setId(id);
    contest.setDescription("desc" + id);
    contest.setLimit(limit);
    contest.setLanguages(languages);
    contest.setTitle("title" + id);
    contest.setForumId(forumId);
    contest.setStartTime(new Date(id * 1000));
    contest.setEndTime(new Date(id * 2000));
    return contest;
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest) Date(java.util.Date)

Example 10 with Contest

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

the class ContestPersistenceImplTest method testGetAllContests.

/**
	 * Tests getAllContests method
	 * @throws Exception to JUnit
	 */
public void testGetAllContests() throws Exception {
    List contests = persistence.getAllContests();
    assertEquals("wrong size", 2, contests.size());
    Contest contest = (Contest) contests.get(0);
    checkAbstractContest(contest1, contest);
    assertEquals("wrong start time", contest.getStartTime(), contest1.getStartTime());
    assertEquals("wrong end time", contest.getEndTime(), contest1.getEndTime());
    contest = (Contest) contests.get(1);
    checkAbstractContest(contest2, contest);
    assertEquals("wrong start time", contest.getStartTime(), contest2.getStartTime());
    assertEquals("wrong end time", contest.getEndTime(), contest2.getEndTime());
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest)

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