use of cn.edu.zju.acm.onlinejudge.bean.AbstractContest in project zoj by licheng.
the class ShowQQAction 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.checkContestAdminPermission(mapping, context, false, true);
if (forward != null) {
return forward;
}
AbstractContest contest = context.getContest();
List<QQ> qqs = PersistenceManager.getInstance().getSubmissionPersistence().searchQQs(contest.getId());
context.setAttribute("qqs", qqs);
return this.handleSuccess(mapping, context, "success");
}
use of cn.edu.zju.acm.onlinejudge.bean.AbstractContest in project zoj by licheng.
the class ShowRankListAction method execute.
/**
* ShowRankListAction.
*
* @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("showRankList.do");
ActionForward forward = this.checkContestViewPermission(mapping, context, isProblemset, true);
if (forward != null) {
return forward;
}
AbstractContest contest = context.getContest();
if (!isProblemset) {
List<Problem> problems = context.getProblems();
context.setAttribute("problems", problems);
long roleId = Utility.parseLong(context.getRequest().getParameter("roleId"));
RankList ranklist = StatisticsManager.getInstance().getRankList(contest.getId(), roleId);
String export = context.getRequest().getParameter("export");
if ("txt".equalsIgnoreCase(export)) {
return this.export(context, contest, problems, ranklist, export);
} else if ("xls".equalsIgnoreCase(export)) {
return this.export(context, contest, problems, ranklist, export);
}
context.setAttribute("RankList", ranklist);
} else {
int from = Utility.parseInt(context.getRequest().getParameter("from"));
if (from < 0) {
from = 0;
}
int count = 30;
String sort = context.getRequest().getParameter("order");
if (sort == null || !sort.equalsIgnoreCase("submit")) {
sort = "ac";
}
ProblemsetRankList ranklist = StatisticsManager.getInstance().getProblemsetRankList(contest.getId(), from, count, sort);
if (from > 0) {
context.setAttribute("previousFrom", from - count > 0 ? from - count : 0);
}
if (ranklist.getSolved().length == count) {
context.setAttribute("nextFrom", from + count);
}
context.setAttribute("RankList", ranklist);
}
return this.handleSuccess(mapping, context, "success");
}
use of cn.edu.zju.acm.onlinejudge.bean.AbstractContest in project zoj by licheng.
the class ShowStatisticsAction method execute.
/**
* ShowStatisticsAction.
*
* @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("showStatistics.do");
ActionForward forward = this.checkContestViewPermission(mapping, context, isProblemset, true);
if (forward != null) {
return forward;
}
AbstractContest contest = context.getContest();
ContestStatistics statistics = StatisticsManager.getInstance().getContestStatistics(contest.getId());
context.setAttribute("ContestStatistics", statistics);
return this.handleSuccess(mapping, context, "success");
}
use of cn.edu.zju.acm.onlinejudge.bean.AbstractContest in project zoj by licheng.
the class ProblemImportAction method execute.
/**
* ProblemImportAction.
*
* @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("importProblems.do");
ActionForward forward = this.checkContestAdminPermission(mapping, context, isProblemset, false);
if (forward != null) {
return forward;
}
ProblemPackage pack = (ProblemPackage) context.getSessionAttribute("ProblemPackage");
context.setSessionAttribute("ProblemPackage", null);
AbstractContest contest = context.getContest();
InputStream in = null;
String filePath = context.getRequest().getParameter("problemFilePath");
FormFile file = ((ProblemImportForm) form).getProblemFile();
if (filePath != null && filePath.trim().length() > 0) {
in = new FileInputStream(filePath);
} else if (file != null) {
in = file.getInputStream();
}
if (in != null) {
ActionMessages messages = new ActionMessages();
pack = ProblemManager.importProblem(in, messages);
if (messages.size() > 0) {
return this.handleFailure(mapping, context, messages);
}
context.setSessionAttribute("ProblemPackage", pack);
return this.handleSuccess(mapping, context, "preview");
}
if (pack == null) {
return this.handleSuccess(mapping, context, "selectcontest");
}
try {
ProblemImportAction.createProblems(pack, contest.getId());
/*
* ProblemCriteria criteria = new ProblemCriteria(); criteria.setContestId(new Long(contest.getId()));
*
* // remove List oldProblems = problemPersistence.searchProblems(criteria); for (Iterator it =
* oldProblems.iterator(); it.hasNext();) { problemPersistence.deleteProblem(((Problem) it.next()).getId(),
* 0); }
*/
ContestManager.getInstance().refreshContest(contest.getId());
} catch (Exception pe) {
this.error(pe);
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.importProblems.failure"));
this.saveErrors(context.getRequest(), messages);
context.setAttribute("back", "editContest.do?contestId=" + contest.getId());
return this.handleSuccess(mapping, context, "success");
}
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.importProblems.success"));
this.saveErrors(context.getRequest(), messages);
context.setAttribute("back", "showContestProblems.do?contestId=" + contest.getId());
return this.handleSuccess(mapping, context, "success");
}
use of cn.edu.zju.acm.onlinejudge.bean.AbstractContest in project zoj by licheng.
the class ContestPersistenceImpl method populateContest.
/**
* Populates an AbstractContest with given ResultSet.
*
* @param rs
* @return an AbstractContest instance
* @throws SQLException
*/
private AbstractContest populateContest(ResultSet rs) throws SQLException {
AbstractContest contest = null;
int contestType = rs.getInt(DatabaseConstants.CONTEST_PROBLEMSET);
if (contestType == 1) {
contest = new Problemset();
} else if (contestType == 0) {
contest = new Contest();
} else {
contest = new Course();
}
if (rs.getTimestamp(DatabaseConstants.CONTEST_START_TIME) != null) {
contest.setStartTime(new Date(rs.getTimestamp(DatabaseConstants.CONTEST_START_TIME).getTime()));
}
if (rs.getTimestamp(DatabaseConstants.CONTEST_END_TIME) != null) {
contest.setEndTime(new Date(rs.getTimestamp(DatabaseConstants.CONTEST_END_TIME).getTime()));
}
contest.setId(rs.getLong(DatabaseConstants.CONTEST_CONTEST_ID));
contest.setTitle(rs.getString(DatabaseConstants.CONTEST_TITLE));
contest.setDescription(rs.getString(DatabaseConstants.CONTEST_DESCRIPTION));
contest.setForumId(rs.getLong(DatabaseConstants.CONTEST_FORUM_ID));
contest.setCheckIp(rs.getBoolean(DatabaseConstants.CONTEST_CHECK_IP));
Limit limit = new Limit();
limit.setId(rs.getLong(DatabaseConstants.LIMITS_LIMITS_ID));
limit.setTimeLimit(rs.getInt(DatabaseConstants.LIMITS_TIME_LIMIT));
limit.setMemoryLimit(rs.getInt(DatabaseConstants.LIMITS_MEMORY_LIMIT));
limit.setSubmissionLimit(rs.getInt(DatabaseConstants.LIMITS_SUBMISSION_LIMIT));
limit.setOutputLimit(rs.getInt(DatabaseConstants.LIMITS_OUTPUT_LIMIT));
contest.setLimit(limit);
return contest;
}
Aggregations