use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.
the class ProblemControllerTest method test.
/**
* @see ProblemController#save(Problem)
* @see ProblemController#findOne(long, String)
* @see ProblemController#update(long, Problem, String)
* @see ProblemController#delete(long)
*/
@Test
public void test() throws Exception {
Problem problem = mockDataService.problem(false);
Long id = objectMapper.readValue(mvc.perform(post("/api/problems.json").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsBytes(problem))).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)).andReturn().getResponse().getContentAsString(), Problem.class).getId();
assertNotNull(id);
assertFalse(findOne(id).getDisabled());
mvc.perform(patch("/api/problems/{id}.json", id).content("{\"disabled\":true}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNoContent());
assertTrue(findOne(id).getDisabled());
mvc.perform(patch("/api/problems/{id}.json", id).content("{\"disabled\":false}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNoContent());
assertFalse(findOne(id).getDisabled());
mvc.perform(delete("/api/problems/{id}.json", id)).andExpect(status().isNoContent());
try {
Problem p = problemService.findOne(id);
fail("should throw a BusinessException");
} catch (BusinessException ex) {
assertEquals(BusinessCode.PROBLEM_NOT_FOUND, ex.getCode());
}
mvc.perform(get("/api/problems/{id}.json", id)).andExpect(status().isNotFound());
mvc.perform(delete("/api/problems/{id}.json", id)).andExpect(status().isNotFound());
mvc.perform(patch("/api/problems/{id}.json", id).content("{}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNotFound());
}
use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.
the class SubmissionService method contestSubmit.
public CompletableFuture<?> contestSubmit(int languageId, String source, String userId, String ip, long contestId, long problemNum) {
check(languageId, source, userId);
Contest contest = contestService.findOneByIdAndNotDisabled(contestId);
// contest not started yet, can't submit the problem.
if (!contest.isStarted()) {
throw new BusinessException(BusinessCode.CONTEST_PROBLEM_NOT_FOUND, contestId, problemNum);
}
Problem problem = contestService.getProblem(contestId, problemNum, null);
return submit0(Submission.builder().contest(contest.isEnded() ? null : contestId).problem(problem.getOrigin()).ip(ip), source, userId, languageId);
}
use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.
the class SearchUserController method searchuser.
@GetMapping("/searchuser")
public String searchuser(Model model, @RequestParam(value = "user_id", defaultValue = "") String keyword, @RequestParam(value = "position", required = false) String position, @PageableDefault(1000) Pageable pageable) {
if (keyword.replace("%", "").length() < 2) {
throw new BusinessException(BusinessCode.USER_SEARCH_KEYWORD_SHORT);
}
String like = keyword;
if (position == null) {
like = "%" + like + "%";
} else if (position.equalsIgnoreCase("begin")) {
like += "%";
} else {
like = "%" + like;
}
Pageable t = pageable;
if (t.getSort() == null) {
t = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), new Sort(new Sort.Order("solved").with(Sort.Direction.DESC), new Sort.Order("submit")));
}
Page<User> users = accountService.findAll(AccountForm.builder().disabled(Boolean.FALSE).query(like).build(), t);
model.addAttribute("query", keyword);
model.addAttribute("users", users);
return "users/search";
}
use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.
the class AccountService method prepare.
private void prepare(Collection<Account> accounts) {
for (Account account : accounts) {
if (!StringUtils.hasText(account.getId())) {
throw new BusinessException(BusinessCode.EMPTY_USER_ID);
}
String password = account.getPassword();
if (StringUtils.isEmpty(password)) {
throw new BusinessException(BusinessCode.EMPTY_PASSWORD);
}
if (password.length() <= PasswordConfiguration.MAX_PASSWORD_LENGTH) {
ValueCheck.checkPassword(password);
account.setPassword(passwordEncoder.encode(password));
}
if (!StringUtils.hasText(account.getEmail())) {
account.setEmail(null);
}
if (!StringUtils.hasText(account.getNick())) {
account.setNick(account.getId());
}
if (account.getSchool() == null) {
account.setSchool("");
}
}
}
use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.
the class JudgeService method toCompletableFuture.
CompletableFuture<?> toCompletableFuture(Executor executor, long submissionId) {
return CompletableFuture.runAsync(() -> {
Submission submission = submissionMapper.findOne(submissionId);
if (submission == null) {
throw new BusinessException(BusinessCode.SUBMISSION_NOT_FOUND);
}
Problem problem = problemService.findOneNoI18n(submission.getProblem());
RunRecord runRecord = RunRecord.builder().submissionId(submission.getId()).language(languageService.getAvailableLanguage(submission.getLanguage())).problemId(submission.getProblem()).userId(submission.getUser()).source(submissionMapper.findSourceById(submissionId)).memoryLimit(problem.getMemoryLimit()).timeLimit(problem.getTimeLimit()).build();
judgeInternal(runRecord);
}, executor);
}
Aggregations