use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.
the class ContestProblemController method showProblem.
@GetMapping("{pid}")
public String showProblem(@PathVariable("contestId") long contestId, @PathVariable("pid") long problemNum, Model model, @Nullable Locale locale) {
Contest contest = contestService.getContestAndProblemsNotDisabled(contestId, null, locale);
if (!contest.isStarted()) {
throw new BusinessException(BusinessCode.CONTEST_NOT_STARTED, contest.getId(), contest.getStartTime());
}
Problem problem = contestService.getProblem(contestId, problemNum, locale);
model.addAttribute("problem", problem);
model.addAttribute("problems", contest.getProblems());
model.addAttribute("isSpecial", systemService.isSpecialJudge(problem.getOrigin()));
List<Long> problemsId = contest.getProblems().stream().map(Problem::getOrigin).collect(ImmutableList.toImmutableList());
String index = contestService.toProblemIndex(problemsId.indexOf(problem.getOrigin()));
String title1 = index + ":" + problem.getOrigin() + " -- " + problem.getTitle();
String title2 = index + ":" + problem.getTitle();
model.addAttribute("title1", title1);
model.addAttribute("title2", title2);
return "contests/problem";
}
use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.
the class ContestProblemController method status.
@GetMapping("{pid}/status")
public String status(@PathVariable("contestId") long contestId, @PathVariable("pid") int problemNum, @RequestParam(value = "language", required = false) Integer language, @PageableDefault(size = 20, sort = { "time", "memory", "code_length" }) Pageable pageable, Model model, HttpServletRequest request) {
// check if problem exists and not disabled
contestService.findOneByIdAndNotDisabled(contestId);
Problem problem = contestService.getProblem(contestId, problemNum, null);
BestSubmissionForm form = BestSubmissionForm.builder().contestId(contestId).problemId(problem.getOrigin()).language(language).build();
Page<Submission> page = submissionService.bestSubmission(form, pageable, problem.getSubmitUser());
model.addAttribute("page", page);
List<ScoreCount> list = submissionMapper.groupByScore(contestId, problem.getOrigin());
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?contest_id=" + contestId + "&problem_id=" + problem.getOrigin() + "&score=" + score);
}
boolean isAdmin = UserDetailsServiceImpl.isAdministrator(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", URIBuilder.fromRequest(request).replaceQueryParam("page").toString());
request.setAttribute("contestId", contestId);
request.setAttribute("canView", canView);
request.setAttribute("currentUserId", SecurityUtils.getUserId());
return "contests/problems-status";
}
use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.
the class ProblemControllerTest method testDataDir.
/**
* Test of dataDir method, of class ProblemController.
*
* {@link ProblemController#dataDir(long)}
*/
@Test
public void testDataDir() throws Exception {
log.info("dataDir");
Problem problem = mockDataService.problem();
MvcResult result = mvc.perform(get("/api/problems/{id}/dataDir", problem.getId()).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn();
objectMapper.readTree(result.getResponse().getContentAsString()).hasNonNull("dataDir");
}
use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.
the class ProblemServiceImpl method attachment.
@Override
public List<String> attachment(long problemId, String requestLocale) {
MarkupParser parser = new MarkupParser(ParseConfiguration.htmlConfiguration());
Problem problem = findOne(problemId, requestLocale);
String description = problem.getDescription();
String input = problem.getInput();
String output = problem.getOutput();
String hint = problem.getHint();
String source = problem.getSource();
@SuppressWarnings("CollectionWithoutInitialCapacity") List<String> list = new ArrayList<>();
for (String string : new String[] { description, input, output, hint, source }) {
try {
if (string == null) {
continue;
}
parser.parse(string, new AbstractMarkupHandler() {
@Override
public void handleAttribute(char[] buffer, int nameOffset, int nameLen, int nameLine, int nameCol, int operatorOffset, int operatorLen, int operatorLine, int operatorCol, int valueContentOffset, int valueContentLen, int valueOuterOffset, int valueOuterLen, int valueLine, int valueCol) {
String name = new String(buffer, nameOffset, nameLen);
if (name.equalsIgnoreCase("href") || name.equalsIgnoreCase("src")) {
String value = new String(buffer, valueContentOffset, valueContentLen);
list.add(value);
}
}
});
} catch (ParseException ex) {
log.error("", ex);
}
}
return list;
}
use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.
the class ProblemServiceImpl method updateSelective.
@Override
@Transactional
public void updateSelective(long problemId, Problem p, @Nullable String requestLocale) {
Problem problem = problemMapper.findOne(problemId, requestLocale);
if (problem == null) {
throw new BusinessException(BusinessCode.PROBLEM_NOT_FOUND, problemId);
}
String locale = convert(requestLocale);
if (locale != null) {
problemMapper.touchI18n(problemId, locale);
}
p.setCreatedTime(null);
p.setModifiedTime(Instant.now());
problemMapper.updateSelective(problemId, p, locale);
}
Aggregations