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;
}
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;
}
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;
}
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;
}
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());
}
Aggregations