use of cn.edu.zju.acm.onlinejudge.bean.Problem in project zoj by licheng.
the class BaseAction method checkProblemPermission.
protected ActionForward checkProblemPermission(ActionMapping mapping, ContextAdapter context, Boolean isProblemset, PermissionLevel level) throws Exception {
Problem problem = context.getProblem();
AbstractContest contest = null;
if (problem != null) {
contest = ContestManager.getInstance().getContest(problem.getContestId());
}
if (problem == null || contest == null || isProblemset != null && (contest instanceof Contest || contest instanceof Course) == isProblemset.booleanValue()) {
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.showproblem.noproblemid"));
this.saveErrors(context.getRequest(), messages);
if (isProblemset != null) {
context.setAttribute("back", isProblemset ? "showProblemsets.do" : "showContests.do");
}
return this.handleFailure(mapping, context, messages, "nopermission");
}
context.setAttribute("contest", contest);
context.setAttribute("problem", problem);
// check contest permission
UserSecurity userSecurity = context.getUserSecurity();
boolean hasPermisstion = false;
if (level == PermissionLevel.ADMIN) {
hasPermisstion = userSecurity.canAdminContest(contest.getId());
} else if (level == PermissionLevel.PARTICIPATE) {
hasPermisstion = userSecurity.canParticipateContest(contest.getId());
} else if (level == PermissionLevel.PARTICIPATECANVIEWSOURCE) {
hasPermisstion = userSecurity.canViewSource(contest.getId());
} else if (level == PermissionLevel.VIEW) {
hasPermisstion = userSecurity.canViewContest(contest.getId());
}
if (!hasPermisstion) {
ActionMessages messages = new ActionMessages();
messages.add("message", new ActionMessage("onlinejudge.showcontest.nopermission"));
this.saveErrors(context.getRequest(), messages);
if (isProblemset != null) {
context.setAttribute("back", isProblemset ? "showProblemsets.do" : "showContests.do");
}
return this.handleFailure(mapping, context, messages, "nopermission");
}
// check start time
if (userSecurity.canAdminContest(contest.getId())) {
return null;
} else {
return this.checkContestStart(mapping, context, contest);
}
}
use of cn.edu.zju.acm.onlinejudge.bean.Problem 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.bean.Problem in project zoj by licheng.
the class ShowRankListAction method exportToExcel.
private byte[] exportToExcel(AbstractContest contest, List<Problem> problems, RankList ranklist) throws Exception {
List<RankListEntry> entries = ranklist.getEntries();
long time = this.getTimeEscaped(contest);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue(contest.getTitle());
if (ranklist.getRole() != null) {
row = sheet.createRow(1);
cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(ranklist.getRole().getDescription());
}
row = sheet.createRow(2);
cell = row.createCell((short) 0);
cell.setCellValue("Length");
cell = row.createCell((short) 1);
cell.setCellValue(Utility.toTime(contest.getLength() / 1000));
row = sheet.createRow(3);
cell = row.createCell((short) 0);
cell.setCellValue("Time Escaped");
cell = row.createCell((short) 1);
cell.setCellValue(Utility.toTime(time / 1000));
row = sheet.createRow(5);
row.createCell((short) 0).setCellValue("Rank");
row.createCell((short) 1).setCellValue("Handle");
row.createCell((short) 2).setCellValue("Nickname");
row.createCell((short) 3).setCellValue("Solved");
short columnIndex = 4;
for (Problem problem2 : problems) {
Problem problem = problem2;
row.createCell(columnIndex).setCellValue(problem.getCode());
columnIndex++;
}
row.createCell(columnIndex).setCellValue("Penalty");
int rowIndex = 6;
for (RankListEntry rankListEntry : entries) {
RankListEntry entry = rankListEntry;
row = sheet.createRow(rowIndex);
row.createCell((short) 0).setCellValue(rowIndex - 5);
row.createCell((short) 1).setCellValue(entry.getUserProfile().getHandle());
String nick = entry.getUserProfile().getHandle();
if (entry.getUserProfile().getNickName() != null) {
nick = entry.getUserProfile().getNickName();
}
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(nick);
row.createCell((short) 3).setCellValue(entry.getSolved());
for (short i = 0; i < problems.size(); ++i) {
String score = entry.getAcceptTime(i) > 0 ? entry.getAcceptTime(i) + "(" + entry.getSubmitNumber(i) + ")" : "" + entry.getSubmitNumber(i);
row.createCell((short) (4 + i)).setCellValue(score);
}
row.createCell((short) (4 + problems.size())).setCellValue(entry.getPenalty());
rowIndex++;
}
// output to stream
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
wb.write(out);
return out.toByteArray();
} finally {
out.close();
}
}
use of cn.edu.zju.acm.onlinejudge.bean.Problem 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.Problem in project zoj by licheng.
the class ShowProblemStatusAction method execute.
/*
* Generated Methods
*/
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
// check contest
boolean isProblemset = context.getRequest().getRequestURI().endsWith("showProblemStatus.do");
ActionForward forward = this.checkProblemViewPermission(mapping, context, isProblemset);
if (forward != null) {
return forward;
}
Problem problem = context.getProblem();
String orderBy = context.getRequest().getParameter("orderBy");
if (!"date".equals(orderBy) && !"memory".equals(orderBy)) {
orderBy = "time";
}
if (problem != null) {
ProblemStatistics statistics = StatisticsManager.getInstance().getProblemStatistics(problem.getId(), orderBy, 20);
context.setAttribute("ProblemStatistics", statistics);
}
return this.handleSuccess(mapping, context, "success");
}
Aggregations