use of cn.edu.zju.acm.onlinejudge.form.SubmissionSearchForm in project zoj by licheng.
the class ShowRunsAction method execute.
/**
* ShowRunsAction.
*
* @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("showRuns.do");
ActionForward forward = this.checkContestViewPermission(mapping, context, isProblemset, true);
if (forward != null) {
return forward;
}
context.setAttribute("judgeReplies", context.isAdmin() ? this.adminJudgeReplies : this.judgeReplies);
// check contest
boolean isRejudge = "true".equalsIgnoreCase(context.getRequest().getParameter("rejudge"));
if (isRejudge) {
this.checkContestAdminPermission(mapping, context, isProblemset, true);
} else {
this.checkContestViewPermission(mapping, context, isProblemset, true);
}
if (forward != null) {
return forward;
}
SubmissionSearchForm serachForm = (SubmissionSearchForm) form;
ActionMessages errors = serachForm.check();
if (errors.size() > 0) {
// TODO
context.setAttribute("runs", new ArrayList<Submission>());
return this.handleFailure(mapping, context, errors);
}
long lastId = Utility.parseLong(serachForm.getLastId());
long firstId = -1;
if (lastId < 0) {
lastId = Long.MAX_VALUE;
firstId = Utility.parseLong(serachForm.getFirstId());
}
int RUNS_PER_PAGE = 15;
SubmissionCriteria criteria = serachForm.toSubmissionCriteria();
if (isRejudge) {
int maxN = 100;
List<Submission> allRuns = PersistenceManager.getInstance().getSubmissionPersistence().searchSubmissions(criteria, -1, Long.MAX_VALUE, maxN + 1, true);
if (allRuns.size() > maxN) {
// TODO
}
this.rejudge(allRuns);
// TODO
}
List<Submission> runs = StatisticsManager.getInstance().getSubmissions(criteria, firstId, lastId, RUNS_PER_PAGE + 1);
long newLastId = -1;
long newFirstId = -1;
long nextId = -1;
long startId = -1;
if (runs.size() > 0) {
startId = runs.get(0).getContestOrder();
}
if (runs.size() > RUNS_PER_PAGE) {
nextId = runs.get(runs.size() - 2).getContestOrder();
runs = runs.subList(0, runs.size() - 1);
}
if (firstId > -1) {
runs = new ArrayList<Submission>(runs);
Collections.reverse(runs);
}
if (runs.size() > 0) {
if (lastId == Long.MAX_VALUE && firstId == -1) {
newLastId = nextId;
} else if (firstId == -1) {
newLastId = nextId;
newFirstId = startId;
} else {
newFirstId = nextId;
newLastId = startId;
}
}
context.setAttribute("runs", runs);
if (newFirstId > -1) {
context.setAttribute("firstId", newFirstId);
}
if (newLastId > -1) {
context.setAttribute("lastId", newLastId);
}
return this.handleSuccess(mapping, context, "success");
}
Aggregations