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