<commit_before>package cn.edu.zjnu.acm.judge.problem;

import cn.edu.zjnu.acm.judge.config.JudgeConfiguration;
import cn.edu.zjnu.acm.judge.domain.Contest;
import cn.edu.zjnu.acm.judge.domain.Problem;
import cn.edu.zjnu.acm.judge.exception.MessageException;
import cn.edu.zjnu.acm.judge.mapper.ContestMapper;
import cn.edu.zjnu.acm.judge.mapper.ProblemMapper;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import static org.springframework.http.MediaType.TEXT_HTML_VALUE;

@Controller
public class ShowProblemController {

    @Autowired
    private ProblemMapper problemMapper;
    @Autowired
    private ContestMapper contestMapper;
    @Autowired
    private JudgeConfiguration judgeConfiguration;

    @GetMapping(value = "/showproblem", produces = TEXT_HTML_VALUE)
    public String showproblem(Model model,
            @RequestParam("problem_id") long problemId,
            Locale locale) {
        Problem problem = problemMapper.findOne(problemId, locale.getLanguage());
        if (problem == null) {
            throw new MessageException("Can not find problem (ID:" + problemId + ")", HttpStatus.NOT_FOUND);
        }
        Long contestId = problem.getContest();
        Path dataPath = judgeConfiguration.getDataDirectory(problemId);
        long contestNum = -1;
        boolean started = true;
        boolean ended = true;
        if (contestId != null) {
            Contest contest = contestMapper.findOne(contestId);
            if (contest != null) {
                started = contest.isStarted();
                ended = contest.isEnded();
            }
            if (ended) {
                problemMapper.setContest(problemId, null);
                contestId = null;
            }
            if (problem.isDisabled() && contestId == null) {
                started = false;
            }
        }
        if (contestId != null) {
            Long problemIdInContest = contestMapper.getProblemIdInContest(contestId, problemId);
            contestNum = problemIdInContest == null ? -1 : problemIdInContest;
        }
        if (!started) {
            throw new MessageException("Can not find problem (ID:" + problemId + ")", HttpStatus.NOT_FOUND);
        }
        model.addAttribute("problem", problem);
        model.addAttribute("isSpecial", Files.exists(dataPath.resolve(JudgeConfiguration.VALIDATE_FILE_NAME)));
        model.addAttribute("contestId", contestId);
        if (contestId == null) {
            model.addAttribute("title1", problemId + " -- " + problem.getTitle());
            model.addAttribute("title2", problem.getTitle());
        } else {
            List<Problem> problems = contestMapper.getProblems(contestId, null, locale.getLanguage());
            model.addAttribute("title1", (char) (contestNum + 'A') + ":" + problemId + " -- " + problem.getTitle());
            model.addAttribute("title2", (char) (contestNum + 'A') + ":" + problem.getTitle());
            model.addAttribute("problems", problems);
        }

        return "problems/view";
    }

}<commit_msg>Do not show problem which is disabled<commit_after>package cn.edu.zjnu.acm.judge.problem;

import cn.edu.zjnu.acm.judge.config.JudgeConfiguration;
import cn.edu.zjnu.acm.judge.domain.Contest;
import cn.edu.zjnu.acm.judge.domain.Problem;
import cn.edu.zjnu.acm.judge.exception.MessageException;
import cn.edu.zjnu.acm.judge.mapper.ContestMapper;
import cn.edu.zjnu.acm.judge.mapper.ProblemMapper;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import static org.springframework.http.MediaType.TEXT_HTML_VALUE;

@Controller
public class ShowProblemController {

    @Autowired
    private ProblemMapper problemMapper;
    @Autowired
    private ContestMapper contestMapper;
    @Autowired
    private JudgeConfiguration judgeConfiguration;

    private Problem getProblem(long problemId, Locale locale) {
        Problem problem = problemMapper.findOne(problemId, locale.getLanguage());
        while (problem != null) {
            Long contestId = problem.getContest();
            if (contestId != null) {
                Contest contest = contestMapper.findOne(contestId);
                if (contest != null && !contest.isDisabled()) {
                    boolean started = contest.isStarted();
                    if (!contest.isEnded()) {
                        if (started) {
                            return problem;
                        }
                        break;
                    } else {
                        problemMapper.setContest(problemId, null);
                        problem.setContest(null);
                    }
                }
            }
            if (!problem.isDisabled()) {
                return problem;
            }
            break;
        }
        throw new MessageException("Can not find problem (ID:" + problemId + ")", HttpStatus.NOT_FOUND);
    }

    @GetMapping(value = "/showproblem", produces = TEXT_HTML_VALUE)
    public String showproblem(Model model,
            @RequestParam("problem_id") long problemId,
            Locale locale) {
        Problem problem = getProblem(problemId, locale);
        Long contestId = problem.getContest();
        Path dataPath = judgeConfiguration.getDataDirectory(problemId);
        model.addAttribute("problem", problem);
        model.addAttribute("isSpecial", Files.exists(dataPath.resolve(JudgeConfiguration.VALIDATE_FILE_NAME)));
        model.addAttribute("contestId", contestId);
        String title1, title2;
        if (contestId == null) {
            title1 = problemId + " -- " + problem.getTitle();
            title2 = problem.getTitle();
        } else {
            Long problemIdInContest = contestMapper.getProblemIdInContest(contestId, problemId);
            long contestNum = problemIdInContest == null ? -1 : problemIdInContest;
            List<Problem> problems = contestMapper.getProblems(contestId, null, locale.getLanguage());
            model.addAttribute("problems", problems);
            title1 = (char) (contestNum + 'A') + ":" + problemId + " -- " + problem.getTitle();
            title2 = (char) (contestNum + 'A') + ":" + problem.getTitle();
        }
        model.addAttribute("title1", title1);
        model.addAttribute("title2", title2);

        return "problems/view";
    }

}
{'fraction_non_alphanumeric': 0.11264991433466591, 'fraction_numerical': 0.0024271844660194173, 'mean_word_length': 2.6295336787564767, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1794060', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1906, 'n_words': 368}