Search in sources :

Example 51 with GetMapping

use of org.springframework.web.bind.annotation.GetMapping in project judge by zjnu-acm.

the class ContestProblemController method problems.

@GetMapping
public String problems(Model model, Locale locale, @PathVariable("contestId") long contestId, Authentication authentication) {
    Contest contest = contestService.getContestAndProblemsNotDisabled(contestId, authentication != null ? authentication.getName() : null, locale);
    model.addAttribute("contestId", contestId);
    model.addAttribute("contest", contest);
    if (contest.isStarted()) {
        model.addAttribute("problems", contest.getProblems());
    } else {
        contest.setProblems(null);
    }
    return "contests/problems";
}
Also used : Contest(cn.edu.zjnu.acm.judge.domain.Contest) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 52 with GetMapping

use of org.springframework.web.bind.annotation.GetMapping in project judge by zjnu-acm.

the class ContestStatisticsController method contestStatistics.

@GetMapping(value = "/conteststatistics", produces = TEXT_HTML_VALUE)
public String contestStatistics(HttpServletRequest request, Model model, @RequestParam("contest_id") long contestId) throws SQLException {
    Instant now = Instant.now();
    Contest contest = contestService.findOneByIdAndNotDisabled(contestId);
    String title = contest.getTitle();
    Instant endTime = contest.getEndTime();
    model.addAttribute("contestId", contestId);
    model.addAttribute("title", "Contest Statistics");
    StringBuilder sb = new StringBuilder("<p align=center><font size=5 color=blue>Contest Statistics--");
    sb.append(HtmlEscape.escapeHtml4Xml(title));
    if (!contest.isEnded()) {
        if (endTime != null) {
            sb.append("<br/>Time to go:").append(JudgeUtils.formatTime(now, endTime));
        } else {
            sb.append("<br/>Time to go Infinity");
        }
    }
    sb.append("</font></p>" + "<TABLE align=center cellSpacing=0 cellPadding=0 width=600 border=1 class=table-back style=\"border-collapse: collapse\" bordercolor=#FFF>" + "<tr bgcolor=#6589D1><th>&nbsp;</th><th>100</th><th>99~70</th><th>69~31</th><th>30~1</th><th>0</th><th>CE</th><th>Others</th><th>Total</th>");
    Map<Integer, Language> languages = languageService.getAvailableLanguages();
    int languageCount = languages.size();
    StringBuilder sql = new StringBuilder(600).append("select ");
    for (int i : languages.keySet()) {
        sql.append("sum(if(language=").append(i).append(",1,0)) g").append(i).append(",");
    }
    sql.append("s.problem_id,sum(if(score=100,1,0)) A,sum(if(score<100 and score >=70,1,0)) B,sum(if(score<70 and score >30,1,0)) D,sum(if(score>0 and score <=30,1,0)) C,sum(if(score=0,1,0)) E,sum(if(score=-7,1,0)) F,sum(if(score<-7 or score > 100,1,0)) G,count(*) Total from contest_problem cp left join solution s on cp.problem_id=s.problem_id and cp.contest_id=s.contest_id where s.contest_id=? group by cp.problem_id order by cp.num");
    String[] judgeStatus = { "A", "B", "C", "D", "E", "F", "G", "Total" };
    long[] byScore = new long[judgeStatus.length];
    long[] byLanguage = new long[languageCount];
    sb.append("<th>&nbsp;</th>");
    languages.values().stream().map(Language::getName).map(HtmlEscape::escapeHtml4Xml).forEach(languageName -> sb.append("<th>").append(languageName).append("</th>"));
    sb.append("</tr>");
    log.debug("{}", sql);
    Map<Long, long[]> problemsMap = contestService.getProblemsMap(contestId);
    try (Connection conn = dataSource.getConnection();
        PreparedStatement ps = conn.prepareStatement(sql.toString())) {
        ps.setLong(1, contestId);
        try (ResultSet rs = ps.executeQuery()) {
            while (rs.next()) {
                long problemId = rs.getLong("problem_id");
                long[] num = problemsMap.get(problemId);
                if (num != null) {
                    sb.append("<tr><th><a href=contests/").append(contestId).append("/problems/").append(num[1]).append(".html>").append(contestService.toProblemIndex(num[0])).append("</a></th>");
                }
                for (int i = 0; i < judgeStatus.length; ++i) {
                    long value = rs.getLong(judgeStatus[i]);
                    byScore[i] += value;
                    if (value == 0) {
                        sb.append("<td>&nbsp;</td>");
                    } else if (i == judgeStatus.length - 1) {
                        sb.append("<th><a href=status?contest_id=").append(contestId).append("&problem_id=").append(problemId).append(">").append(value).append("</a></th>");
                    } else {
                        sb.append("<td>").append(value).append("</td>");
                    }
                }
                sb.append("<td>&nbsp;</td>");
                for (int i = 0; i < languageCount; ++i) {
                    long value = rs.getLong(i + 1);
                    byLanguage[i] += value;
                    if (value == 0) {
                        sb.append("<td>&nbsp;</td>");
                    } else {
                        sb.append("<td>").append(value).append("</td>");
                    }
                }
                sb.append("</tr>");
            }
        }
    }
    sb.append("<tr><th>Total</th>");
    for (int i = 0; i < judgeStatus.length; ++i) {
        if (byScore[i] == 0) {
            sb.append("<td>&nbsp;</td>");
        } else if (i == judgeStatus.length - 1) {
            sb.append("<th>").append(byScore[i]).append("</th>");
        } else {
            sb.append("<td>").append(byScore[i]).append("</td>");
        }
    }
    sb.append("<td>&nbsp;</td>");
    for (int i = 0; i < languageCount; ++i) {
        if (byLanguage[i] == 0) {
            sb.append("<td>&nbsp;</td>");
        } else {
            sb.append("<td>").append(byLanguage[i]).append("</td>");
        }
    }
    sb.append("</tr></table>");
    model.addAttribute("content", sb.toString());
    return "legacy";
}
Also used : Instant(java.time.Instant) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Language(cn.edu.zjnu.acm.judge.domain.Language) ResultSet(java.sql.ResultSet) Contest(cn.edu.zjnu.acm.judge.domain.Contest) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 53 with GetMapping

use of org.springframework.web.bind.annotation.GetMapping in project judge by zjnu-acm.

the class ProblemStatusController method status.

@GetMapping("/problemstatus")
@SuppressWarnings("AssignmentToMethodParameter")
public String status(HttpServletRequest request, @RequestParam("problem_id") long id, @PageableDefault(size = 20, sort = { "time", "memory", "code_length" }) Pageable pageable, Authentication authentication) {
    log.debug("{}", pageable);
    if (pageable.getPageSize() > 500) {
        pageable = new PageRequest(pageable.getPageNumber(), 500, pageable.getSort());
    }
    Problem problem = problemService.findOneNoI18n(id);
    List<ScoreCount> list = submissionMapper.groupByScore(null, id);
    ArrayList<String> scores = new ArrayList<>(list.size());
    ArrayList<Long> counts = new ArrayList<>(list.size());
    ArrayList<String> urls = new ArrayList<>(list.size());
    for (ScoreCount scoreCount : list) {
        int score = scoreCount.getScore();
        scores.add(ResultType.getShowsourceString(score));
        counts.add(scoreCount.getCount());
        urls.add(request.getContextPath() + "/status?problem_id=" + id + "&score=" + score);
    }
    Page<Submission> page = submissionService.bestSubmission(null, id, pageable, problem.getSubmitUser());
    boolean isAdmin = UserDetailsServiceImpl.isAdminLoginned(request);
    boolean isSourceBrowser = UserDetailsServiceImpl.isSourceBrowser(request);
    boolean canView = isAdmin || isSourceBrowser;
    request.setAttribute("page", page);
    request.setAttribute("sa", Arrays.asList(counts, scores, urls));
    request.setAttribute("problem", problem);
    request.setAttribute("url", URLBuilder.fromRequest(request).replaceQueryParam("page").toString());
    request.setAttribute("canView", canView);
    request.setAttribute("authentication", authentication);
    return "problems/status";
}
Also used : Submission(cn.edu.zjnu.acm.judge.domain.Submission) ArrayList(java.util.ArrayList) ScoreCount(cn.edu.zjnu.acm.judge.data.dto.ScoreCount) PageRequest(org.springframework.data.domain.PageRequest) Problem(cn.edu.zjnu.acm.judge.domain.Problem) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 54 with GetMapping

use of org.springframework.web.bind.annotation.GetMapping in project judge by zjnu-acm.

the class CKFinderController method ckfinder.

@Nullable
@ToDownload
@GetMapping("/support/ckfinder")
public Path ckfinder(@RequestParam("path") String path) {
    log.info(path);
    try {
        int indexOf = path.indexOf('?');
        Path parent = judgeConfiguration.getUploadDirectory();
        Path imagePath = parent.getFileSystem().getPath(parent.toString(), indexOf > 0 ? path.substring(0, indexOf) : path).normalize();
        if (!imagePath.startsWith(parent)) {
            log.debug("absolute path parent='{}' path='{}'", parent, imagePath);
            return null;
        }
        return imagePath;
    } catch (IllegalArgumentException ex) {
        return null;
    }
}
Also used : Path(java.nio.file.Path) GetMapping(org.springframework.web.bind.annotation.GetMapping) ToDownload(com.github.zhanhb.download.spring.ToDownload) Nullable(javax.annotation.Nullable)

Example 55 with GetMapping

use of org.springframework.web.bind.annotation.GetMapping in project judge by zjnu-acm.

the class MailController method delete.

@GetMapping("/deletemail")
public String delete(@RequestParam("mail_id") long mailId, Authentication authentication) {
    Mail mail = mailMapper.findOne(mailId);
    if (mail == null) {
        throw new MessageException("No such mail", HttpStatus.NOT_FOUND);
    }
    if (!UserDetailsServiceImpl.isUser(authentication, mail.getTo())) {
        throw new MessageException("Sorry, invalid access", HttpStatus.FORBIDDEN);
    }
    mailMapper.delete(mailId);
    return "redirect:/mail";
}
Also used : Mail(cn.edu.zjnu.acm.judge.domain.Mail) MessageException(cn.edu.zjnu.acm.judge.exception.MessageException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

GetMapping (org.springframework.web.bind.annotation.GetMapping)756 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)114 ResponseEntity (org.springframework.http.ResponseEntity)80 ArrayList (java.util.ArrayList)52 List (java.util.List)49 ModelAndView (org.springframework.web.servlet.ModelAndView)48 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)45 HttpHeaders (org.springframework.http.HttpHeaders)41 Map (java.util.Map)40 HashMap (java.util.HashMap)38 lombok.val (lombok.val)38 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)36 Grid (org.hisp.dhis.common.Grid)35 IOException (java.io.IOException)34 RequestParam (org.springframework.web.bind.annotation.RequestParam)34 ApiOperation (io.swagger.annotations.ApiOperation)31 RootNode (org.hisp.dhis.node.types.RootNode)31 PathVariable (org.springframework.web.bind.annotation.PathVariable)31 HttpServletRequest (javax.servlet.http.HttpServletRequest)30 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)28