use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.
the class SubmissionServiceImpl method contestSubmit.
@Override
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, true);
}
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 = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Order.desc("solved"), Sort.Order.asc("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);
}
use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.
the class ProblemService method updateSelective.
public void updateSelective(long problemId, Problem p, 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.setModifiedTime(Instant.now());
problemMapper.updateSelective(problemId, p, locale);
}
Aggregations