use of cn.edu.zju.acm.onlinejudge.bean.Problem in project zoj by licheng.
the class EditProblemAction method validate.
/**
* Validates the form.
*
* @param mapping
* the action mapping.
* @param request
* the user request.
*
* @return collection of validation errors.
*/
public ActionErrors validate(ProblemForm form, ContextAdapter context) throws Exception {
ActionErrors errors = new ActionErrors();
this.checkInteger(form.getProblemId(), 0, Integer.MAX_VALUE, "id", errors);
String name = form.getName();
String code = form.getCode();
if (name == null || name.trim().length() == 0) {
errors.add("name", new ActionMessage("ProblemForm.name.required"));
}
if (code == null || code.trim().length() == 0) {
errors.add("code", new ActionMessage("ProblemForm.code.required"));
}
if (!form.isUseContestDefault()) {
this.checkInteger(form.getTimeLimit(), 0, 3600, "timeLimit", errors);
this.checkInteger(form.getMemoryLimit(), 0, 1024 * 1024, "memoryLimit", errors);
this.checkInteger(form.getOutputLimit(), 0, 100 * 1024, "outputLimit", errors);
this.checkInteger(form.getSubmissionLimit(), 0, 10 * 1024, "submissionLimit", errors);
}
List<Problem> problems = ContestManager.getInstance().getContestProblems(context.getContest().getId());
/*for (Object obj : problems) {
Problem p = (Problem) obj;
if (!form.getProblemId().equals("" + p.getId()) && p.getTitle().equals(name)) {
errors.add("name", new ActionMessage("ProblemForm.name.used"));
break;
}
}*/
for (Object obj : problems) {
Problem p = (Problem) obj;
if (!form.getProblemId().equals("" + p.getId()) && p.getCode().equals(code)) {
errors.add("code", new ActionMessage("ProblemForm.code.used"));
break;
}
}
return errors;
}
use of cn.edu.zju.acm.onlinejudge.bean.Problem in project zoj by licheng.
the class ExportProblemsAction method execute.
/**
* ExportProblemsAction.
*
* @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("exportProblems.do");
ActionForward forward = this.checkContestAdminPermission(mapping, context, isProblemset, false);
if (forward != null) {
return forward;
}
AbstractContest contest = context.getContest();
List<Problem> problems = ContestManager.getInstance().getContestProblems(contest.getId());
HttpServletResponse response = context.getResponse();
response.setContentType("application/zip");
response.setHeader("Content-disposition", "attachment; filename=" + this.convertFilename(contest.getTitle()) + ".zip");
ZipOutputStream out = null;
StringBuilder sb = new StringBuilder();
try {
out = new ZipOutputStream(response.getOutputStream());
for (Object obj : problems) {
Problem p = (Problem) obj;
this.zipReference(p, "text", ReferenceType.DESCRIPTION, out);
this.zipReference(p, "input", ReferenceType.INPUT, out);
this.zipReference(p, "output", ReferenceType.OUTPUT, out);
this.zipReference(p, "solution", ReferenceType.JUDGE_SOLUTION, out);
this.zipReference(p, "checker", ReferenceType.HEADER, out);
this.zipReference(p, "checker", ReferenceType.CHECKER_SOURCE, out);
sb.append(toCsvString(p.getCode())).append(",");
sb.append(toCsvString(p.getTitle())).append(",");
sb.append(p.isChecker()).append(",");
sb.append(p.getLimit().getTimeLimit()).append(",");
sb.append(p.getLimit().getMemoryLimit()).append(",");
sb.append(p.getLimit().getOutputLimit()).append(",");
sb.append(p.getLimit().getSubmissionLimit()).append(",");
sb.append(toCsvString(p.getAuthor())).append(",");
sb.append(toCsvString(p.getSource())).append(",");
sb.append(toCsvString(p.getContest())).append("\n");
}
out.putNextEntry(new ZipEntry("problems.csv"));
out.write(sb.toString().getBytes());
} catch (IOException e) {
throw e;
} finally {
if (out != null) {
out.close();
}
}
return null;
}
use of cn.edu.zju.acm.onlinejudge.bean.Problem 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());
}
use of cn.edu.zju.acm.onlinejudge.bean.Problem in project zoj by licheng.
the class AddProblemAction method validate.
/**
* Validates the form.
*
* @param mapping
* the action mapping.
* @param request
* the user request.
*
* @return collection of validation errors.
*/
public ActionErrors validate(ProblemForm form, ContextAdapter context) throws Exception {
ActionErrors errors = new ActionErrors();
this.checkInteger(form.getProblemId(), 0, Integer.MAX_VALUE, "id", errors);
String name = form.getName();
String code = form.getCode();
if (name == null || name.trim().length() == 0) {
errors.add("name", new ActionMessage("ProblemForm.name.required"));
}
if (code == null || code.trim().length() == 0) {
errors.add("code", new ActionMessage("ProblemForm.code.required"));
}
if (!form.isUseContestDefault()) {
this.checkInteger(form.getTimeLimit(), 0, 3600, "timeLimit", errors);
this.checkInteger(form.getMemoryLimit(), 0, 1024 * 1024, "memoryLimit", errors);
this.checkInteger(form.getOutputLimit(), 0, 100 * 1024, "outputLimit", errors);
this.checkInteger(form.getSubmissionLimit(), 0, 10 * 1024, "submissionLimit", errors);
}
List<Problem> problems = ContestManager.getInstance().getContestProblems(context.getContest().getId());
/*for (Object problem : problems) {
if (((Problem) problem).getTitle().equals(name)) {
errors.add("name", new ActionMessage("ProblemForm.name.used"));
break;
}
}*/
for (Object problem : problems) {
if (((Problem) problem).getCode().equals(code)) {
errors.add("code", new ActionMessage("ProblemForm.code.used"));
break;
}
}
return errors;
}
use of cn.edu.zju.acm.onlinejudge.bean.Problem in project zoj by licheng.
the class ContextAdapter method getProblem.
public Problem getProblem() throws PersistenceException {
if (this.getAttribute("problem") instanceof Problem) {
return (Problem) this.getAttribute("problem");
}
long problemId = -1;
String stringCode = this.request.getParameter("problemCode");
String stringId = this.request.getParameter("problemId");
if (stringCode != null) {
ProblemCriteria pc = new ProblemCriteria();
pc.setContestId(new Long(ConfigManager.getDefaultProblemSetId()));
pc.setCode(stringCode);
ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
List problems = problemPersistence.searchProblems(pc, 0, 1);
if (problems.size() != 0) {
problemId = ((Problem) (problems.get(0))).getId();
stringId = "" + problemId;
}
}
this.setAttribute("problemId", stringId);
if (stringId != null) {
try {
problemId = Long.parseLong(stringId);
} catch (NumberFormatException e) {
}
}
if (problemId < 0) {
return null;
}
Problem problem = ContestManager.getInstance().getProblem(problemId);
this.setAttribute("problem", problem);
return problem;
}
Aggregations