Search in sources :

Example 6 with BusinessException

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);
}
Also used : BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Problem(cn.edu.zjnu.acm.judge.domain.Problem) Contest(cn.edu.zjnu.acm.judge.domain.Contest)

Example 7 with BusinessException

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";
}
Also used : BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Pageable(org.springframework.data.domain.Pageable) User(cn.edu.zjnu.acm.judge.domain.User) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 8 with BusinessException

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("");
        }
    }
}
Also used : Account(cn.edu.zjnu.acm.judge.data.excel.Account) BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException)

Example 9 with BusinessException

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);
}
Also used : RunRecord(cn.edu.zjnu.acm.judge.data.dto.RunRecord) BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Submission(cn.edu.zjnu.acm.judge.domain.Submission) Problem(cn.edu.zjnu.acm.judge.domain.Problem)

Example 10 with BusinessException

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);
}
Also used : BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Problem(cn.edu.zjnu.acm.judge.domain.Problem)

Aggregations

BusinessException (cn.edu.zjnu.acm.judge.exception.BusinessException)22 GetMapping (org.springframework.web.bind.annotation.GetMapping)8 Problem (cn.edu.zjnu.acm.judge.domain.Problem)7 Submission (cn.edu.zjnu.acm.judge.domain.Submission)6 Contest (cn.edu.zjnu.acm.judge.domain.Contest)5 User (cn.edu.zjnu.acm.judge.domain.User)5 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 Secured (org.springframework.security.access.annotation.Secured)3 Account (cn.edu.zjnu.acm.judge.data.excel.Account)2 Message (cn.edu.zjnu.acm.judge.domain.Message)2 MessageException (cn.edu.zjnu.acm.judge.exception.MessageException)2 IOException (java.io.IOException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 JudgeException (cn.edu.zjnu.acm.judge.core.JudgeException)1 SimpleValidator (cn.edu.zjnu.acm.judge.core.SimpleValidator)1 Validator (cn.edu.zjnu.acm.judge.core.Validator)1 RunRecord (cn.edu.zjnu.acm.judge.data.dto.RunRecord)1 SubmissionDetail (cn.edu.zjnu.acm.judge.data.dto.SubmissionDetail)1 SubmissionDetailDTO (cn.edu.zjnu.acm.judge.data.dto.SubmissionDetailDTO)1 Mail (cn.edu.zjnu.acm.judge.domain.Mail)1