use of cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence 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.persistence.ProblemPersistence in project zoj by licheng.
the class ContestManager method getProblem.
public Problem getProblem(long problemId) throws PersistenceException {
Object key = new Long(problemId);
synchronized (this.problemCache) {
Problem problem = this.problemCache.get(key);
if (problem == null) {
ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
problem = problemPersistence.getProblem(problemId);
this.problemCache.put(key, problem);
}
return problem;
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence in project zoj by licheng.
the class ProblemImportAction method createProblems.
private static void createProblems(ProblemPackage pack, long cid) throws Exception {
ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
ProblemEntry[] problems = pack.getProblemEntries();
for (int i = 0; i < problems.length; ++i) {
// info
problems[i].getProblem().setContestId(cid);
problemPersistence.createProblem(problems[i].getProblem(), 0);
long problemId = problems[i].getProblem().getId();
ProblemImportAction.createReference(ReferenceType.DESCRIPTION, problems[i].getText(), problemId, 0, ProblemManager.PROBLEM_TEXT_FILE, null);
ProblemImportAction.createReference(ReferenceType.INPUT, problems[i].getInput(), problemId, 0, ProblemManager.INPUT_FILE, null);
ProblemImportAction.createReference(ReferenceType.OUTPUT, problems[i].getOutput(), problemId, 0, ProblemManager.OUTPUT_FILE, null);
ProblemImportAction.createReference(ReferenceType.HEADER, problems[i].getChecker(), problemId, 0, ProblemManager.CHECKER_FILE, null);
ProblemImportAction.createReference(ReferenceType.CHECKER_SOURCE, problems[i].getCheckerSource(), problemId, 0, ProblemManager.CHECKER_SOURCE_FILE, problems[i].getCheckerSourceType());
ProblemImportAction.createReference(ReferenceType.JUDGE_SOLUTION, problems[i].getSolution(), problemId, 0, ProblemManager.JUDGE_SOLUTION_FILE, problems[i].getSolutionType());
// images
}
Map<String, byte[]> images = pack.getImages();
String imagesPath = ConfigManager.getImagePath();
for (String string : images.keySet()) {
String name = string;
String path = imagesPath + "/" + name;
byte[] image = images.get(name);
FileOutputStream out = new FileOutputStream(path);
try {
CopyUtils.copy(new ByteArrayInputStream(image), out);
} catch (Exception e) {
out.close();
throw e;
}
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence 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.persistence.ProblemPersistence 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