@RequestMapping(value = "/plagicoj/plagicojinspectionresultlist.xhtml") public String plagicojInspecctionResultList(SecurityContextHolderAwareRequestWrapper requestWrapper, Model model, Principal principal, @RequestParam(required = false, value = "vid") String vid) { int countDictums = plagiCOJDAO.countDictums(submitId1, submitId2, submitIdRangeStart, submitIdRangeEnd, problemId,onlyAC,matchLanguage,ownSubmission,sameUser); loadParameters(requestWrapper); if (buildNavigating(countDictums, 50, "", getNumber(), model) != 0) { top = getNumber() - 1; top*=50; } resultList = plagiCOJDAO.getDictums(submitId1, submitId2, submitIdRangeStart, submitIdRangeEnd, problemId, onlyAC,matchLanguage,ownSubmission,sameUser,top,50); if (!resultList.isEmpty()){ maximumPageDictum = getNumber() == 1?1.0:resultList.get(0).getDictum(); minimumPageDictum = resultList.size() < 50?0.0:resultList.get(resultList.size() - 1).getDictum(); } model.addAttribute( "resultsList", resultList); return "/plagicoj/plagicojinspectionresultlist"; }
private void loadParameters(SecurityContextHolderAwareRequestWrapper requestWrapper) { orderby = requestWrapper.getParameter("orderby"); setInv(0); try { setInv((int) new Integer(requestWrapper.getParameter("inv"))); } catch (Exception e) { } int pos = 1; try { pos = new Integer(requestWrapper.getParameter("vid")); if (pos <= 0) { pos = 1; } } catch (Exception ex) { } if (requestWrapper.getParameter("mrnav") != null) { setMrNumber(pos); } else if (requestWrapper.getParameter("mcnav") != null) { setMcNumber(pos); } else { setNumber(pos); } }
@RequestMapping(value = "/manageproblemI18N.xhtml", method = RequestMethod.POST) public String manageProblemI18N(Model model, SecurityContextHolderAwareRequestWrapper requestWrapper, Principal principal, HttpServletRequest request, Problem problem, BindingResult result) { Integer uid = problemDAO.integer("select.uid.by.username", getUsername(principal)); if (!(requestWrapper.isUserInRole(Roles.ROLE_ADMIN) || requestWrapper.isUserInRole(Roles.ROLE_SUPER_PSETTER) || (problemDAO.bool("is.psetter.problem", uid, problem.getPid()) && requestWrapper .isUserInRole(Roles.ROLE_PSETTER)))) { return "/admin/adminproblems"; } if (result.hasErrors()) { model.addAttribute(problem); return "/admin/manageproblemI18N"; } problemDAO.updateProblemI18N(problem); problemDAO.log("editing problem I18N " + problem.getPid(), getUsername(principal)); return "redirect:/24h/problem.xhtml?pid=" + problem.getPid(); }
@RequestMapping(value = "/24h/bestsolutions.xhtml", method = RequestMethod.GET) public String BestSolutions(Locale locale, Principal principal, SecurityContextHolderAwareRequestWrapper requestWrapper, PagingOptions options, Model model, @RequestParam Integer pid) { Problem problem = problemDAO.getStatistics(locale.getLanguage(), pid); if (requestWrapper.isUserInRole(Roles.ROLE_USER)) { int uid = submissionDAO.integer("select.uid.by.username", getUsername(principal)); problem.setSolved(problemDAO.bool("issolved.byuser", uid, problem.getPid())); if (problem.isSolved()) { problem.setLocked(problemDAO.isLocked(uid, problem.getPid())); } } model.addAttribute("problem", problem); return "/24h/bestsolutions"; }
@RequestMapping(value = "/tables/bestsolutions.xhtml", method = RequestMethod.GET) public String testBestSolutions(Locale locale, Principal principal, SecurityContextHolderAwareRequestWrapper requestWrapper, PagingOptions options, Model model, @RequestParam Integer pid) { Problem problem = problemDAO.getStatistics(locale.getLanguage(), pid); if (requestWrapper.isUserInRole(Roles.ROLE_USER)) { int uid = submissionDAO.integer("select.uid.by.username", getUsername(principal)); problem.setSolved(problemDAO.bool("issolved.byuser", uid, problem.getPid())); if (problem.isSolved()) { problem.setLocked(problemDAO.isLocked(uid, problem.getPid())); } } int found = submissionDAO.countBestSolutions(pid); if (found != 0) { IPaginatedList<SubmissionJudge> submissions = submissionDAO .bestSolutions(pid, found, options, requestWrapper, problem); model.addAttribute("submissions", submissions); } return "/tables/bestsolutions"; }
@RequestMapping(value = "/24h/submission.xhtml", method = RequestMethod.GET) public String SourceView(Principal principal, SecurityContextHolderAwareRequestWrapper requestWrapper, Model model, @RequestParam("id") Integer id) { try { if (!canAccessSubmission(principal, requestWrapper, id)) { return "/error/cancel"; } else { SubmissionJudge submission = submissionDAO.getSourceCode(id); int uid = submissionDAO.integer("select.uid.by.username", getUsername(principal)); if (!requestWrapper.isUserInRole(Roles.ROLE_ADMIN) && !(submission.getUsername() .equals(getUsername(principal))) && !(problemDAO.bool("issolved.byuser", uid, submission.getPid()) && problemDAO.isLocked( uid, submission.getPid()))) { throw new EmptyResultDataAccessException(0); } model.addAttribute("submission", submission); } } catch (EmptyResultDataAccessException ex) { return "/error/accessdenied"; } return "/24h/submission"; }
@RequestMapping(value = "/contest/cawards.xhtml", method = RequestMethod.GET) public String contestAwards(Model model, SecurityContextHolderAwareRequestWrapper requestWrapper, Locale locale, @RequestParam("cid") Integer cid) { Contest contest = contestDAO.loadContest(cid); List<Problem> problems = problemDAO.getContestProblems(locale.getLanguage(), cid); IACMScoreboard iacmscoreboard = contestDAO.getRankingAcm(cid, null, false, problems); List<User> users = iacmscoreboard.assignMedals(contest); model.addAttribute("cid", cid); model.addAttribute("users", users); if (!contest.isPast()) { return "/error/accessdenied"; } model.addAttribute("contest", contest); awards(model, cid); return "/contest/cawards"; }
@RequestMapping(value = "/tables/cproblems.xhtml", method = RequestMethod.GET) public String tablesContestProblems(Locale locale,Model model, SecurityContextHolderAwareRequestWrapper requestWrapper,Principal principal, PagingOptions options, @RequestParam("cid") Integer cid) { String username = getUsername(principal); Contest contest = contestDAO.loadContest(cid); contestDAO.unfreezeIfNecessary(contest); model.addAttribute("contest", contest); if (contest.isRunning() || contest.isPast()) { contest.setShow_status(false); if (contest.isShow_problem_out() || (username != null && hasAnyPrivileges(requestWrapper,Roles.ROLE_ADMIN,Roles.ROLE_SUPER_PSETTER,Roles.ROLE_PSETTER)) || (!contest.isShow_problem_out() && username != null && contestDAO.isInContest(cid, contestDAO.integer("select.uid.by.username", username)))) { contest.setShow_status(true); int found = problemDAO.countProblemContest(cid); if (found > 0) { model.addAttribute("problems", problemDAO.getContestProblems(found,locale.getLanguage(),username, contest, options)); } } } return "/tables/cproblems"; }
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { if (request instanceof SecurityContextHolderAwareRequestWrapper) { boolean isMustChangePassword = SecurityContextHolder.getContext().getAuthentication().getAuthorities().stream().anyMatch( authority -> StandardEntitlement.MUST_CHANGE_PASSWORD.equals(authority.getAuthority())); SecurityContextHolderAwareRequestWrapper wrapper = SecurityContextHolderAwareRequestWrapper.class.cast(request); if (isMustChangePassword && "GET".equalsIgnoreCase(wrapper.getMethod()) && !ArrayUtils.contains(ALLOWED, wrapper.getPathInfo())) { throw new AccessDeniedException("Please change your password first"); } } chain.doFilter(request, response); }
@RequestMapping(value = "/plagicoj/sourcecodedetectorresult.xhtml", method = RequestMethod.GET) public String sourceCodeDetectorResult(SecurityContextHolderAwareRequestWrapper requestWrapper, Model model, Principal principal, @RequestParam(required = true, value = "ssid") Integer sourceSubmissionx, @RequestParam(required = true, value = "dsid") Integer destinationSubmissiony) { SubmissionJudge sourceSubmission = plagiCOJDAO.getSubmissions(sourceSubmissionx.toString(), null, null, null, null, false, null, null, principal != null, requestWrapper.isUserInRole("ROLE_ADMIN"), getUsername(principal), false).get(0); SubmissionJudge destinationSubmission = plagiCOJDAO.getSubmissions(destinationSubmissiony.toString(), null, null, null, null, false, null, null, principal != null, requestWrapper.isUserInRole("ROLE_ADMIN"), getUsername(principal), false).get(0); SourceCode source = new SourceCode(sourceSubmission.getCode(),cu.uci.plagicoj.utils.Language.valueOf(formatLanguageCode(sourceSubmission.getLang()))); SourceCode destination = new SourceCode(destinationSubmission.getCode(),cu.uci.plagicoj.utils.Language.valueOf(formatLanguageCode(destinationSubmission.getLang()))); Detector stringTilingDetector = new StringTilingDetector(source,destination); cu.uci.plagicoj.PlagiCOJ plagiCOJ = cu.uci.plagicoj.PlagiCOJ.create(stringTilingDetector); cu.uci.plagicoj.PlagiCOJResult plagiCOJResult = plagiCOJ.detectPlagiarism(); SourceCodeDetectorResult detectorResult = (SourceCodeDetectorResult) plagiCOJResult.getDetectorResults().get(0); model.addAttribute("matches", detectorResult.getMatches()); model.addAttribute("sourceTokens", detectorResult.getSourceTokens()); model.addAttribute("destinationTokens", detectorResult.getDestinationTokens()); model.addAttribute("judgesRevisions", plagiCOJDAO.getPlagiCOJDetectorResultJudgeRevisions(sourceSubmissionx, destinationSubmissiony, PlagiCOJDetectorType.PlagiCOJStringTilingDetector)); model.addAttribute("sourceSubmission", sourceSubmission); model.addAttribute("destinationSubmission", destinationSubmission); model.addAttribute("plagiCOJDetectorResult", detectorResult); return "/plagicoj/sourcecodedetectorresult"; }
@RequestMapping(value = "/manageproblemI18N.xhtml", method = RequestMethod.GET) public String manageProblemI18N(Model model, Locale locale, Principal principal, SecurityContextHolderAwareRequestWrapper requestWrapper, @RequestParam("pid") Integer pid) { Integer uid = problemDAO.integer("select.uid.by.username", getUsername(principal)); if (!requestWrapper.isUserInRole(Roles.ROLE_ADMIN) && !requestWrapper.isUserInRole(Roles.ROLE_SUPER_PSETTER) && !(problemDAO.bool("is.psetter.problem", uid, pid) && requestWrapper.isUserInRole(Roles.ROLE_PSETTER))) { return "/admin/adminproblems"; } Problem problem = problemDAO.object("select.problem.i18n.1", Problem.class, pid); model.addAttribute("pid", pid); model.addAttribute(problem); return "/admin/manageproblemI18N"; }
public String doContestImages(Model model, Principal principal, SecurityContextHolderAwareRequestWrapper requestWrapper, @RequestParam(value = "cid") Integer cid) { Contest contest = new Contest(); contest.setCid(cid); model.addAttribute("contest", contest); model.addAttribute("images", utils.getContestImages(cid)); model.addAttribute("eproblem", withProblems(cid)); return "/admin/contestimg"; }
@RequestMapping(value = "/contestimg.xhtml", method = RequestMethod.POST) public String contestImages(Model model, SecurityContextHolderAwareRequestWrapper requestWrapper, Principal principal, Contest contest, HttpServletRequest request, BindingResult result, RedirectAttributes redirectAttributes) { handleFiles(contest.getCid(), request); redirectAttributes.addFlashAttribute("message", Notification.getSuccesfullUpdate()); return doContestImages(model, principal, requestWrapper, contest.getCid()); }
@RequestMapping(value = "/unlock.xhtml", method = RequestMethod.GET) public String unfreezeContest(Model model, SecurityContextHolderAwareRequestWrapper requestWrapper, @RequestParam("cid") Integer cid) throws IOException { Contest contest = contestDAO.loadContest(cid); if (requestWrapper.isUserInRole(Roles.ROLE_ADMIN) && contest.isPast()) { // se cambian las banderas block y unfreeze auto del contest a // valores complementarios contestDAO.dml("update.freeze.blocked.contest", false, true, cid); contestDAO.repointContest(contest, false); } return "redirect:/contest/cscoreboard.xhtml?cid=" + cid; }
@RequestMapping(value = "/lock.xhtml", method = RequestMethod.GET) public String freezeContest(Model model, SecurityContextHolderAwareRequestWrapper requestWrapper, @RequestParam("cid") Integer cid) throws IOException { Contest contest = contestDAO.loadContest(cid); if (requestWrapper.isUserInRole(Roles.ROLE_ADMIN) && contest.isPast()) { // se cambian las banderas block y unfreeze auto del contest a // valores complementarios contestDAO.freezeContest(contest); } return "redirect:/contest/cscoreboard.xhtml?cid=" + cid; }
@RequestMapping(value = "/tables/status.xhtml", method = RequestMethod.GET) public String JudgementsTable( Principal principal, Model model, SecurityContextHolderAwareRequestWrapper requestWrapper, PagingOptions options, @RequestParam(required = false, value = "username") String filter_user, @RequestParam(required = false, value = "pid") Integer pid, @RequestParam(required = false, value = "status") String status, @RequestParam(required = false, value = "planguage") String language) { String lang = submissionDAO.string( "select language from language where key=?", language); int found = submissionDAO.countSubmissions(filter_user, lang, pid, Config.getProperty("judge.status." + status)); if (found != 0) { IPaginatedList<SubmissionJudge> submissions = submissionDAO .getSubmissions(filter_user, found, lang, pid, Config.getProperty("judge.status." + status), options, principal != null, requestWrapper.isUserInRole(Roles.ROLE_ADMIN), principal == null ? null : getUsername(principal)); model.addAttribute("submissions", submissions); } return "/tables/status"; }
private boolean canAccessSubmission(Principal principal, SecurityContextHolderAwareRequestWrapper requestWrapper, int submit_id) { if (requestWrapper.isUserInRole(Roles.ROLE_ADMIN)) { return true; } if (principal == null) { return false; } return submissionDAO.bool("can.access.submission"); }
@RequestMapping(value = "/24h/downloadsource.xhtml", method = RequestMethod.GET) public String SourceDownload(Principal principal, SecurityContextHolderAwareRequestWrapper requestWrapper, HttpServletResponse response, Model model, @RequestParam("sid") Integer id) throws Exception { try { if (!canAccessSubmission(principal, requestWrapper, id)) { return "/error/cancel"; } else { SubmissionJudge submission = submissionDAO.getSourceCode(id); int uid = submissionDAO.integer("select.uid.by.username", getUsername(principal)); if (!requestWrapper.isUserInRole(Roles.ROLE_ADMIN) && !(submission.getUsername() .equals(getUsername(principal))) && !(problemDAO.bool("issolved.byuser", uid, submission.getPid()) && problemDAO.isLocked( uid, submission.getPid()))) { throw new EmptyResultDataAccessException(0); } response.setContentType(Config.getProperty("language.mime." + submission.getLang())); response.setHeader("Content-disposition", "inline; filename=" + submission.getFilename()); response.getOutputStream().write( submission.getCode().getBytes()); response.getOutputStream().flush(); return null; } } catch (EmptyResultDataAccessException ex) { return "/error/accessdenied"; } }
@RequestMapping(value = "/tables/cballoontracker.xhtml", method = RequestMethod.GET) public String tableCballoontracker(Model model, SecurityContextHolderAwareRequestWrapper requestWrapper, Principal principal, PagingOptions options, @RequestParam(required = false, value = "group") String group, @RequestParam("cid") Integer cid) { model.addAttribute("submits", contestDAO.pendingBalloons(cid, options, group)); boolean isBalloonTracker = contestDAO.bool("balloontracker.in.contest", getUid(principal), cid); model.addAttribute("showBalloonMark", isBalloonTracker); return "/tables/cballoontracker"; }
@Deprecated @RequestMapping(value = "/tables/globalcontestscoreboard.xhtml", method = RequestMethod.GET) public String tablesGlobalContestScoreboartd(Locale locale, SecurityContextHolderAwareRequestWrapper requestWrapper, Model model, Principal principal, PagingOptions options, @RequestParam("cid") Integer cid) { Contest contest = contestDAO.loadContest(cid); if (contest.getStyle() == 4) { contest.setStyle(3); } if ((contest.isRunning() || contest.isPast()) && !contest.isRepointing()) { if (contest.isShow_scoreboard() || (principal != null && requestWrapper.isUserInRole(Roles.ROLE_ADMIN))) { contest.setShow_status(false); if (contest.isShow_scoreboard_out() || (principal != null && requestWrapper.isUserInRole(Roles.ROLE_ADMIN)) || (!contest.isShow_scoreboard_out() && principal != null && contestDAO.isInContest(cid, contestDAO.integer("users.uid", getUsername(principal))))) { contest.setShow_status(true); switch (contest.getStyle()) { case 1: { break; } case 3: IPaginatedList<User> users = contestDAO.getFreeContestRanking(cid, options); model.addAttribute("users", users); break; } } } } model.addAttribute("contest", contest); return "/tables/globalcontestscoreboard"; }
@RequestMapping(value = "/contest/cproblems.xhtml", method = RequestMethod.GET) public String ContestProblems(Locale locale,Model model, SecurityContextHolderAwareRequestWrapper requestWrapper,Principal principal, PagingOptions options, @RequestParam("cid") Integer cid) { Contest contest = contestDAO.loadContest(cid); contestDAO.unfreezeIfNecessary(contest); if (contest.isComing()) { return "redirect:/contest/contestview.xhtml?cid=" + cid; } model.addAttribute("contest", contest); return "/contest/cproblems"; }
@Transactional(readOnly = true) public IPaginatedList<SubmissionJudge> bestSolutions(Integer pid, int found, PagingOptions options, SecurityContextHolderAwareRequestWrapper Orequest, Problem Oproblem, boolean see) { IBestSolutions bsolutions = new IBestSolutions(pid, options.getPage(), Orequest, Oproblem); List<SubmissionJudge> submissions = jdbcTemplate.query( getSql("best.solutions"), bsolutions, pid, options.getOffset(20)); return getPaginatedList(options, submissions, 20, found); }
@Transactional(readOnly = true) public IPaginatedList<SubmissionJudge> bestSolutions(Integer pid, int found, PagingOptions options, SecurityContextHolderAwareRequestWrapper Orequest, Problem Oproblem) { IBestSolutions bsolutions = new IBestSolutions(pid, options.getPage() - 1, Orequest, Oproblem); return getPaginatedList(options, jdbcTemplate.query( getSql("best.solutions.1"), bsolutions, pid, (options.getPage() - 1) * 20), 20, found); }
@ApiOperation(value = "Obtener las mejores soluciones de un problema", notes = "Dado el identificador de un problema, devuelve las mejores soluciones de este.", response = JudgmentsRest.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 404, message = "bad pid") }) @RequestMapping(value = "/best/{pid}", method = RequestMethod.GET, headers = "Accept=application/json") @ResponseBody public ResponseEntity<?> getBestJudgmentsByProblem( @ApiParam(value = "Identificador del problema") @PathVariable int pid, @ApiIgnore SecurityContextHolderAwareRequestWrapper requestWrapper) { if (!problemDAO.exists(pid) ) return new ResponseEntity<>(ErrorUtils.BAD_PID, HttpStatus.NOT_FOUND); List<SubmissionJudge> listSubmitions = new LinkedList(); int found = submissionDAO.countBestSolutions(pid); if (found != 0){ PagingOptions options = new PagingOptions(1); Problem problem = problemDAO.getStatistics("en", pid); IPaginatedList<SubmissionJudge> submissions = submissionDAO.bestSolutions(pid, found, options,requestWrapper, problem); listSubmitions = submissions.getList(); } List<JudgmentsRest> listJudgmentsRest = new LinkedList(); for(SubmissionJudge s:listSubmitions){ int testcase = 0; if(s.isOntest()) testcase = s.getFirstWaCase()+1; JudgmentsRest jud = new JudgmentsRest(s.getSid(),""+s.getDate().toString(),s.getUsername(), s.getPid(), s.getStatus(),testcase, s.getTimeUsed(), s.getMemoryMB(), s.getFontMB(), s.getLang()); listJudgmentsRest.add(jud); } return new ResponseEntity<>(listJudgmentsRest, HttpStatus.OK); }
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper((HttpServletRequest) req, rolePrefix); // preserve any authentication from the original req into the wrapped request Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if ( auth != null ) { SecurityContextHolder.getContext().setAuthentication(auth); } chain.doFilter(wrapper, res); }
@RequestMapping(value = "/24h/votes.xhtml", method = RequestMethod.GET) public String Votes(Locale locale, Principal principal, SecurityContextHolderAwareRequestWrapper requestWrapper, Model model, @RequestParam Integer pid) { Problem problem = problemDAO.getStatistics(locale.getLanguage(), pid); if (getUsername(principal) == null) { return "/error/wproblem"; } int uid = problemDAO.integer("select.uid.by.username", getUsername(principal)); if (!problemDAO.bool("issolved.byuser", uid, problem.getPid())) { return "/error/wproblem"; } if (!problemDAO.bool("problem.voted.byuser", uid, problem.getPid())) { model.addAttribute("voted", false); } else { model.addAttribute("voted", true); VotesStats datos = problemDAO.object("problem.load.votes", VotesStats.class, problem.getPid()); double[] V = new double[6]; V[1] = datos.getVote1_sum() / Math.max(1, datos.getVote1_cant()); V[2] = datos.getVote2_sum() / Math.max(1, datos.getVote2_cant()); V[3] = datos.getVote3_sum() / Math.max(1, datos.getVote3_cant()); V[4] = datos.getVote4_sum() / Math.max(1, datos.getVote4_cant()); V[5] = datos.getVote5_sum() / Math.max(1, datos.getVote5_cant()); model.addAttribute("vote1", V[1]); model.addAttribute("vote2", V[2]); model.addAttribute("vote3", V[3]); model.addAttribute("vote4", V[4]); model.addAttribute("vote5", V[5]); model.addAttribute("str_vote1", String.format("%.2f", V[1])); model.addAttribute("str_vote2", String.format("%.2f", V[2])); model.addAttribute("str_vote3", String.format("%.2f", V[3])); model.addAttribute("str_vote4", String.format("%.2f", V[4])); model.addAttribute("str_vote5", String.format("%.2f", V[5])); } model.addAttribute("problem", problem); return "/24h/votes"; }
@RequestMapping(produces = "application/json",value = "/plagicoj/saverevision.json", method = RequestMethod.POST,headers = {"Accept=application/json"}) public @ResponseBody String saveRevision(SecurityContextHolderAwareRequestWrapper requestWrapper, Model model,@RequestParam(required = false, value = "ssid") Integer sourceSubmission, @RequestParam(required = false, value = "didd") Integer destinationSubmission, @RequestParam(required = false, defaultValue = "0", value = "eval") Integer evaluation, @RequestParam(required = false, value = "comment") String comment, Principal principal) throws Exception { return "{\"state\":\"success\"}"; }
@RequestMapping(value = "/manageproblem.xhtml", method = RequestMethod.POST) public String manageProblem(Model model, SecurityContextHolderAwareRequestWrapper requestWrapper, Principal principal, HttpServletRequest request, Problem problem, BindingResult result, RedirectAttributes redirectAttributes) { // adicionar. el resto es modificar. if (problem.getPid() == null || problem.getPid() == 0) { String data = addProblem(model, principal, request, problem, result); //chequeo que haya insertado correctamente y valla a redireccionar para el listar para mostrar los flash if (data.equals("redirect:/admin/adminproblems.xhtml")) { redirectAttributes.addFlashAttribute("message", Notification.getSuccesfullCreate()); } return data; } Integer uid = contestDAO.integer("select.uid.by.username", getUsername(principal)); if (!(requestWrapper.isUserInRole(Roles.ROLE_ADMIN) || requestWrapper.isUserInRole(Roles.ROLE_SUPER_PSETTER) || (problemDAO.bool("is.psetter.problem", uid, problem.getPid()) && requestWrapper .isUserInRole(Roles.ROLE_PSETTER)))) { return "/admin/adminproblems"; } validator.validate(problem, result); if (result.hasErrors()) { problemDAO.fillProblemLanguages(problem); problem.initLanguages(); model.addAttribute("languages", utilDAO.getEnabledProgramingLanguages()); model.addAttribute("contests", contestDAO.getComingAndRunningContests()); model.addAttribute("sources", problemDAO.getProblemSources()); model.addAttribute("psetters", utilDAO.objects("select.psetters.pid", User.class, problem.getPid())); model.addAttribute(problem); /*model.addAttribute("showpsetters", (requestWrapper.isUserInRole(Roles.ROLE_ADMIN) && requestWrapper.isUserInRole(Roles.ROLE_ADMIN)) || principal.getName().equals(problem.getUsername())); model.addAttribute("create", false);*/ return "/admin/manageproblem"; } if (!problem.isMultidata()) { problem.setCasetimelimit(problem.getTime()); } problemDAO.updateProblem(problem); problemDAO.clearProgrammingLanguages(problem.getPid()); if (problem.getLanguageids() != null) { for (int i = 0; i < problem.getLanguageids().length; i++) { problemDAO.insertProblemLanguage(problem.getPid(), problem.getLanguageids()[i]); } } // solo los admins pueden asignar nuevos problemsetters if (requestWrapper.isUserInRole(Roles.ROLE_ADMIN) || requestWrapper.isUserInRole(Roles.ROLE_SUPER_PSETTER) || (requestWrapper.isUserInRole(Roles.ROLE_PSETTER) && principal.getName().equals(problemDAO.creatorUsernameByPid(problem.getPid())))) { problemDAO.clearPsetters(problem.getPid()); if (problem.getPsettersids() != null) { for (int i = 0; i < problem.getPsettersids().length; i++) { problemDAO.dml("insert.psetter.pid", problem.getPsettersids()[i], problem.getPid()); } } } if (problem.getContest() != 0) { int pOrder = contestDAO.integer("contest.problem.order", problem.getContest()); contestDAO.insertProblemContest(problem.getPid(), problem.getContest(), 1, pOrder + 1); } if (problem.getLimits() != null) { problemDAO.clearLimits(problem.getPid()); for (Limits limits : problem.getLimits()) { limits.setProblemId(problem.getPid()); problemDAO.insertLimit(limits); } } handleFiles(problem, request); problemDAO.log("editing problem " + problem.getPid(), getUsername(principal)); //return "redirect:/24h/problem.xhtml?pid=" + problem.getPid(); redirectAttributes.addFlashAttribute("message", Notification.getSuccesfullUpdate()); return "redirect:/admin/adminproblems.xhtml"; }
@RequestMapping(value = "/contestimg.xhtml", method = RequestMethod.GET) public String contestImages(Model model, Principal principal, SecurityContextHolderAwareRequestWrapper requestWrapper, @RequestParam(value = "cid") Integer cid) { return doContestImages(model, principal, requestWrapper, cid); }
@RequestMapping(value = "/24h/submit.xhtml", method = RequestMethod.GET) public String SubmitController( Principal principal, SecurityContextHolderAwareRequestWrapper requestWrapper, Model model, @RequestParam(required = false, value = "pid") Integer pid, @RequestParam(required = false, defaultValue = "0", value = "sid") Integer sid) { SubmissionJudge submit = new SubmissionJudge(); Language language = userDAO .getProgrammingLanguageByUsername(getUsername(principal)); submit.setPid(pid == null ? 0 : pid); if (sid != 0) { SubmissionJudge submission = submissionDAO.getSourceCode(sid); int uid = userDAO.integer("select.uid.by.username", getUsername(principal)); if (!requestWrapper.isUserInRole(Roles.ROLE_ADMIN) && !(submission.getUsername() .equals(getUsername(principal))) && !(problemDAO.bool("issolved.byuser", uid, submission.getPid()) && problemDAO.isLocked(uid, submission.getPid()))) { } else { submit.setCode(submission.getCode()); submit.setPid(submission.getPid()); submit.setLid(submission.getLid()); submit.setKey(submission.getKey()); } } else { submit.setLid(language.getLid()); submit.setKey(language.getKey()); } List<Language> languages = new LinkedList<Language>(); try { if (problemDAO.exists(submit.getPid())) { languages.addAll(utilDAO.getEnabledLanguagesByProblem(submit .getPid())); } else { languages.addAll(utilDAO.getEnabledLanguagesByProblem(null)); } } catch (EmptyResultDataAccessException e) { } submit.setLanguages(languages); model.addAttribute("languages", languages); if (getUsername(principal) != null) { model.addAttribute("enableadveditor", userDAO.bool("is.adved.enable", getUsername(principal))); } model.addAttribute("submit", submit); return "/24h/submit"; }
public IBestSolutions(Integer pid, int number, SecurityContextHolderAwareRequestWrapper requestWrapper, Problem problem) { this.pid = pid; this.number = number; this.requestWrapper = requestWrapper; this.problem = problem; }
@Deprecated @RequestMapping(value = "/contest/globalcontestscoreboard.xhtml", method = RequestMethod.GET) public String GlobalContestScoreboartd(Locale locale, SecurityContextHolderAwareRequestWrapper requestWrapper, Model model, Principal principal, PagingOptions options, @RequestParam("cid") Integer cid, @RequestParam(required = false, value = "ungroup") String ungroup) { Contest contest = contestDAO.loadContest(cid); if (contest.isComing()) { return "redirect:/contest/contestview.xhtml?cid=" + cid; } if (contest.getStyle() == 4) { contest.setStyle(3); } if ((contest.isRunning() || contest.isPast()) && !contest.isRepointing()) { if (contest.isShow_scoreboard() || (principal != null && requestWrapper.isUserInRole(Roles.ROLE_ADMIN))) { contest.setShow_status(false); if (contest.isShow_scoreboard_out() || (principal != null && requestWrapper.isUserInRole(Roles.ROLE_ADMIN)) || (!contest.isShow_scoreboard_out() && principal != null && contestDAO.isInContest(cid, contestDAO.integer("users.uid", getUsername(principal))))) { contest.setShow_status(true); switch (contest.getStyle()) { case 1: { List<Problem> problems = problemDAO.getContestProblems(locale.getLanguage(), cid); int[] ids = new int[] { 1213, 1200, 1199, 1192, 1196, 1214, 1212, 1204, 1193, 1178, 1206, 1202, 1211, 1195, 1208, 1187, 1209, 1198, 1210, 1205, 1191, 1207, 1194 }; List<Integer> cids = new LinkedList<Integer>(); for (int i = 0; i < ids.length; i++) { int j = ids[i]; cids.add(j); } int[] minimums = contestDAO.getGlobalRankingAcmMinimun(cids); int min = minimums[0]; for (int i = 1; i < minimums.length; i++) { if (minimums[i] < min) { min = minimums[i]; } } IACMScoreboard iacmscoreboard = contestDAO.getGlobalRankingAcm(cids, ungroup != null, problems); for (int i = 0; i < problems.size(); i++) { problems.get(i).stats(); } if (ungroup != null) { setMedals(iacmscoreboard.getUsers(), contest, 0); model.addAttribute("users", iacmscoreboard.getUsers()); } else { model.addAttribute("group", true); for (int i = 0; i < iacmscoreboard.getGroups().size(); i++) { setMedals(iacmscoreboard.getGroups().get(i).getUsers(), contest, 0); } model.addAttribute("groups", iacmscoreboard.getGroups()); } model.addAttribute("problems", problems); break; } case 3: IPaginatedList<User> users = contestDAO.getFreeContestRanking(cid, options); model.addAttribute("users", users); break; } } } } model.addAttribute("contest", contest); return "/contest/globalcontestscoreboard"; }
public IPaginatedList<SubmissionJudge> bestSolutions(Integer pid, int found, PagingOptions options, SecurityContextHolderAwareRequestWrapper request, Problem problem);
/** * Returns the name of the currently logged-in user. * * @param request The HTTP request. * @return The name of the logged-in user, or <code>null</code>. */ public String getCurrentUsername(HttpServletRequest request) { return new SecurityContextHolderAwareRequestWrapper(request, null).getRemoteUser(); }