use of cn.edu.zju.acm.onlinejudge.form.ProblemForm 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.form.ProblemForm in project zoj by licheng.
the class AddProblemAction method execute.
/**
* AddProblemAction.
*
* @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("addProblem.do");
ActionForward forward = this.checkContestAdminPermission(mapping, context, isProblemset, false);
if (forward != null) {
return forward;
}
ProblemForm problemForm = (ProblemForm) form;
if (problemForm == null || problemForm.getProblemId() == null) {
return this.handleSuccess(mapping, context);
}
// 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.createProblem(problem, userId);
// cprete problem reference, i.e. text, input, output, checker, judge solution, checker source
this.createReference(ReferenceType.DESCRIPTION, problemForm.getDescription(), problem.getId(), userId);
this.createReference(ReferenceType.INPUT, problemForm.getInputData(), problem.getId(), userId);
this.createReference(ReferenceType.OUTPUT, problemForm.getOutputData(), problem.getId(), userId);
this.createReference(ReferenceType.HEADER, problemForm.getChecker(), problem.getId(), userId);
this.createReference(ReferenceType.CHECKER_SOURCE, problemForm.getCheckerSource(), problem.getId(), userId);
this.createReference(ReferenceType.JUDGE_SOLUTION, problemForm.getJudgeSolution(), problem.getId(), userId);
ContestManager.getInstance().refreshContest(problem.getContestId());
return this.handleSuccess(mapping, context, "success", "?contestId=" + contest.getId());
}
Aggregations