Search in sources :

Example 11 with BusinessException

use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.

the class ShowSourceController method showSource.

@Secured("ROLE_USER")
@GetMapping("/showsource")
@SuppressWarnings("AssignmentToMethodParameter")
public String showSource(HttpServletRequest request, @RequestParam("solution_id") long submissionId, @RequestParam(value = "style", required = false) Integer style, Authentication authentication) {
    Submission submission = submissionMapper.findOne(submissionId);
    if (submission == null) {
        throw new BusinessException(BusinessCode.SUBMISSION_NOT_FOUND, submissionId);
    }
    contestOnlyService.checkViewSource(request, submission);
    String userId = authentication != null ? authentication.getName() : null;
    if (!submissionService.canView(request, submission)) {
        throw new MessageException("You have no permission to view the source.", HttpStatus.FORBIDDEN);
    }
    String language = languageService.getLanguageName(submission.getLanguage());
    if (style == null) {
        style = userPerferenceMapper.getStyle(userId);
    } else {
        userPerferenceMapper.setStyle(userId, style);
    }
    String source = submissionMapper.findSourceById(submissionId);
    request.setAttribute("submission", submission);
    if (submission.getContest() != null) {
        request.setAttribute("contestId", submission.getContest());
    }
    request.setAttribute("language", language);
    request.setAttribute("result", ResultType.getShowsourceString(submission.getScore()));
    request.setAttribute("style", style);
    request.setAttribute("source", source);
    return "submissions/source";
}
Also used : BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Submission(cn.edu.zjnu.acm.judge.domain.Submission) MessageException(cn.edu.zjnu.acm.judge.exception.MessageException) GetMapping(org.springframework.web.bind.annotation.GetMapping) Secured(org.springframework.security.access.annotation.Secured)

Example 12 with BusinessException

use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.

the class ShowSubmissionDetailsController method showSolutionDetails.

@GetMapping("/showsolutiondetails")
public String showSolutionDetails(HttpServletRequest request, @RequestParam("solution_id") long submissionId, Authentication authentication) {
    Submission submission = submissionMapper.findOne(submissionId);
    if (submission == null) {
        throw new BusinessException(BusinessCode.SUBMISSION_NOT_FOUND, submissionId);
    }
    Long contestId = submission.getContest();
    if (contestId != null) {
        Contest contest = contestMapper.findOne(contestId);
        if (contest != null) {
            request.setAttribute("contestId", contest.getId());
        }
    }
    if (!submissionService.canView(request, submission)) {
        throw new MessageException("You have no permission to view solution '" + submissionId + "'", HttpStatus.FORBIDDEN);
    }
    String submissionDetail = submissionMapper.getSubmissionDetail(submissionId);
    if (submissionDetail == null) {
        submissionDetail = "";
    }
    String[] detailsArray = submissionDetail.split(",");
    SubmissionDetail[] details = new SubmissionDetail[detailsArray.length / 4];
    for (int i = 0; i < detailsArray.length / 4; ++i) {
        details[i] = SubmissionDetail.builder().result(ResultType.getCaseScoreDescription(Integer.parseInt(detailsArray[i << 2]))).score(detailsArray[i << 2 | 1]).time(detailsArray[i << 2 | 2]).memory(detailsArray[i << 2 | 3]).build();
    }
    request.setAttribute("details", details);
    request.setAttribute("user", submission.getUser());
    request.setAttribute("problem", submission.getProblem());
    request.setAttribute("result", ResultType.getResultDescription(submission.getScore()));
    request.setAttribute("score", submission.getScore());
    request.setAttribute("time", submission.getTime());
    request.setAttribute("memory", submission.getMemory());
    return "submissions/detail";
}
Also used : BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Submission(cn.edu.zjnu.acm.judge.domain.Submission) MessageException(cn.edu.zjnu.acm.judge.exception.MessageException) SubmissionDetail(cn.edu.zjnu.acm.judge.data.dto.SubmissionDetail) Contest(cn.edu.zjnu.acm.judge.domain.Contest) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 13 with BusinessException

use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.

the class AccountServiceImpl method prepare.

private void prepare(Collection<Account> accounts) {
    for (Account account : accounts) {
        if (!StringUtils.hasText(account.getId())) {
            throw new BusinessException(BusinessCode.IMPORT_USER_ID_EMPTY);
        }
        String password = account.getPassword();
        if (!StringUtils.hasLength(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 14 with BusinessException

use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.

the class ShowSourceController method showSource.

@Secured("ROLE_USER")
@GetMapping("showsource")
@SuppressWarnings("AssignmentToMethodParameter")
public String showSource(HttpServletRequest request, @RequestParam("solution_id") long submissionId, @RequestParam(value = "style", required = false) Integer style) {
    String userId = SecurityUtils.getUserId();
    Submission submission = submissionService.findById(submissionId);
    contestOnlyService.checkViewSource(request, submission);
    if (!submissionService.canView(request, submission)) {
        throw new BusinessException(BusinessCode.VIEW_SOURCE_PERMISSION_DENIED, submissionId);
    }
    String language = languageService.getLanguageName(submission.getLanguage());
    if (style == null) {
        style = userPreferenceMapper.getStyle(userId);
    } else {
        userPreferenceMapper.setStyle(userId, style);
    }
    String source = submissionDetailMapper.findSourceById(submissionId);
    request.setAttribute("submission", submission);
    if (submission.getContest() != null) {
        request.setAttribute("contestId", submission.getContest());
    }
    request.setAttribute("language", language);
    request.setAttribute("result", ResultType.getShowSourceString(submission.getScore()));
    request.setAttribute("style", style);
    request.setAttribute("source", source);
    return "submissions/source";
}
Also used : BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Submission(cn.edu.zjnu.acm.judge.domain.Submission) GetMapping(org.springframework.web.bind.annotation.GetMapping) Secured(org.springframework.security.access.annotation.Secured)

Example 15 with BusinessException

use of cn.edu.zjnu.acm.judge.exception.BusinessException in project judge by zjnu-acm.

the class ShowSubmissionDetailsController method showSolutionDetails.

@GetMapping("showsolutiondetails")
public String showSolutionDetails(HttpServletRequest request, @RequestParam("solution_id") long submissionId) {
    Submission submission = submissionService.findById(submissionId);
    Long contestId = submission.getContest();
    if (contestId != null) {
        Contest contest = contestMapper.findOne(contestId);
        if (contest != null) {
            request.setAttribute("contestId", contest.getId());
        }
    }
    if (!submissionService.canView(request, submission)) {
        throw new BusinessException(BusinessCode.VIEW_SOURCE_PERMISSION_DENIED, submissionId);
    }
    List<SubmissionDetailDTO> details = submissionService.getSubmissionDetail(submissionId);
    request.setAttribute("details", details);
    request.setAttribute("user", submission.getUser());
    request.setAttribute("problem", submission.getProblem());
    request.setAttribute("result", ResultType.getResultDescription(submission.getScore()));
    request.setAttribute("score", submission.getScore());
    request.setAttribute("time", submission.getTime());
    request.setAttribute("memory", submission.getMemory());
    return "submissions/detail";
}
Also used : BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Submission(cn.edu.zjnu.acm.judge.domain.Submission) SubmissionDetailDTO(cn.edu.zjnu.acm.judge.data.dto.SubmissionDetailDTO) Contest(cn.edu.zjnu.acm.judge.domain.Contest) GetMapping(org.springframework.web.bind.annotation.GetMapping)

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