Search in sources :

Example 1 with Problem

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);
    }
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) UserSecurity(cn.edu.zju.acm.onlinejudge.security.UserSecurity) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) Contest(cn.edu.zju.acm.onlinejudge.bean.Contest) Course(cn.edu.zju.acm.onlinejudge.bean.Course)

Example 2 with Problem

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());
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ProblemForm(cn.edu.zju.acm.onlinejudge.form.ProblemForm) ActionMessages(org.apache.struts.action.ActionMessages) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ActionForward(org.apache.struts.action.ActionForward) ProblemPersistence(cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)

Example 3 with Problem

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();
    }
}
Also used : RankListEntry(cn.edu.zju.acm.onlinejudge.util.RankListEntry) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 4 with Problem

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");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ProblemsetRankList(cn.edu.zju.acm.onlinejudge.util.ProblemsetRankList) RankList(cn.edu.zju.acm.onlinejudge.util.RankList) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ProblemsetRankList(cn.edu.zju.acm.onlinejudge.util.ProblemsetRankList) ActionForward(org.apache.struts.action.ActionForward)

Example 5 with Problem

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");
}
Also used : ProblemStatistics(cn.edu.zju.acm.onlinejudge.util.ProblemStatistics) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ActionForward(org.apache.struts.action.ActionForward)

Aggregations

Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)44 ActionForward (org.apache.struts.action.ActionForward)11 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)10 ArrayList (java.util.ArrayList)9 Limit (cn.edu.zju.acm.onlinejudge.bean.Limit)8 ActionMessage (org.apache.struts.action.ActionMessage)7 ProblemPersistence (cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)6 ActionMessages (org.apache.struts.action.ActionMessages)6 Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)5 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)5 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)4 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)3 RankListEntry (cn.edu.zju.acm.onlinejudge.util.RankListEntry)3 List (java.util.List)3 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)2 ProblemForm (cn.edu.zju.acm.onlinejudge.form.ProblemForm)2