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