Search in sources :

Example 11 with Contest

use of cn.edu.zjnu.acm.judge.domain.Contest 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 12 with Contest

use of cn.edu.zjnu.acm.judge.domain.Contest in project judge by zjnu-acm.

the class ContestMapperTest method testFindOne.

/**
 * Test of findOne method, of class ContestMapper.
 */
@Test
public void testFindOne() {
    log.info("findOne");
    long contestId = 0L;
    Contest expResult = null;
    Contest result = instance.findOne(contestId);
    assertEquals(expResult, result);
}
Also used : Contest(cn.edu.zjnu.acm.judge.domain.Contest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with Contest

use of cn.edu.zjnu.acm.judge.domain.Contest in project judge by zjnu-acm.

the class MockDataService method contest.

@Nonnull
public Contest contest(boolean create) {
    Instant now = Instant.now();
    Contest contest = Contest.builder().startTime(now.minus(1, ChronoUnit.HOURS)).endTime(now.plus(1, ChronoUnit.HOURS)).title("test title").description("test description").build();
    if (create) {
        contestService.save(contest);
    }
    return contest;
}
Also used : Instant(java.time.Instant) Contest(cn.edu.zjnu.acm.judge.domain.Contest) Nonnull(javax.annotation.Nonnull)

Aggregations

Contest (cn.edu.zjnu.acm.judge.domain.Contest)13 Problem (cn.edu.zjnu.acm.judge.domain.Problem)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 BusinessException (cn.edu.zjnu.acm.judge.exception.BusinessException)3 Nonnull (javax.annotation.Nonnull)3 Instant (java.time.Instant)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 SubmissionDetail (cn.edu.zjnu.acm.judge.data.dto.SubmissionDetail)1 Language (cn.edu.zjnu.acm.judge.domain.Language)1 Submission (cn.edu.zjnu.acm.judge.domain.Submission)1 MessageException (cn.edu.zjnu.acm.judge.exception.MessageException)1 Path (java.nio.file.Path)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1