Search in sources :

Example 16 with StudentExam

use of de.tum.in.www1.artemis.domain.exam.StudentExam in project ArTEMiS by ls1intum.

the class ExamSubmissionService method isSubmissionInTime.

private boolean isSubmissionInTime(Exercise exercise, StudentExam studentExam, boolean withGracePeriod) {
    // The attributes of the exam (e.g. startDate) are missing. Therefore we need to load it.
    Exam exam = examRepository.findByIdElseThrow(exercise.getExerciseGroup().getExam().getId());
    ZonedDateTime calculatedEndDate = withGracePeriod ? exam.getEndDate().plusSeconds(exam.getGracePeriod()) : exam.getEndDate();
    if (studentExam.getWorkingTime() != null && studentExam.getWorkingTime() > 0) {
        calculatedEndDate = withGracePeriod ? studentExam.getIndividualEndDateWithGracePeriod() : studentExam.getIndividualEndDate();
    }
    return exam.getStartDate().isBefore(ZonedDateTime.now()) && calculatedEndDate.isAfter(ZonedDateTime.now());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam)

Example 17 with StudentExam

use of de.tum.in.www1.artemis.domain.exam.StudentExam in project ArTEMiS by ls1intum.

the class StudentExamAccessService method checkStudentExamAccessElseThrow.

/**
 * Checks if the current user is allowed to see the requested student exam.
 *
 * @param courseId      the if of the course
 * @param examId        the id of the exam
 * @param studentExamId the id of the student exam
 * @param currentUser   the current user
 * @param isTestRun     flag to determine if this is a test run or not
 */
public void checkStudentExamAccessElseThrow(Long courseId, Long examId, Long studentExamId, User currentUser, boolean isTestRun) {
    checkCourseAndExamAccessElseThrow(courseId, examId, currentUser, isTestRun);
    // Check that the student exam exists
    StudentExam studentExam = studentExamRepository.findByIdElseThrow(studentExamId);
    // Check that the examId equals the id of the exam of the student exam
    if (!studentExam.getExam().getId().equals(examId)) {
        throw new ConflictException("The student exam does not belong to the exam", "StudentExam", "studentExamExamConflict");
    }
    // Check that the student of the required student exam (from the database) is the current user
    if (!studentExam.getUser().equals(currentUser)) {
        throw new AccessForbiddenException();
    }
}
Also used : ConflictException(de.tum.in.www1.artemis.web.rest.errors.ConflictException) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)

Example 18 with StudentExam

use of de.tum.in.www1.artemis.domain.exam.StudentExam in project ArTEMiS by ls1intum.

the class ExamResource method getStudentExamForStart.

/**
 * GET /courses/{courseId}/exams/{examId}/start : Get an exam for the exam start.
 *
 * @param courseId the id of the course
 * @param examId   the id of the exam
 * @return the ResponseEntity with status 200 (OK) and with the found student exam (without exercises) as body
 */
@GetMapping("/courses/{courseId}/exams/{examId}/start")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<StudentExam> getStudentExamForStart(@PathVariable Long courseId, @PathVariable Long examId) {
    log.debug("REST request to get exam {} for conduction", examId);
    StudentExam exam = examAccessService.getExamInCourseElseThrow(courseId, examId);
    return ResponseEntity.ok(exam);
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 19 with StudentExam

use of de.tum.in.www1.artemis.domain.exam.StudentExam in project ArTEMiS by ls1intum.

the class ExamResource method generateMissingStudentExams.

/**
 * POST /courses/:courseId/exams/:examId/generate-missing-student-exams:
 * Generates exams for students, who don't have an individual exam yet.
 * They are created randomly based on the exam configuration and the exercise groups.
 *
 * @param courseId the id of the course
 * @param examId   the id of the exam
 * @return the list of student exams with their corresponding users
 */
@PostMapping(value = "/courses/{courseId}/exams/{examId}/generate-missing-student-exams")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<StudentExam>> generateMissingStudentExams(@PathVariable Long courseId, @PathVariable Long examId) {
    log.info("REST request to generate missing student exams for exam {}", examId);
    final Exam exam = examRepository.findByIdWithRegisteredUsersExerciseGroupsAndExercisesElseThrow(examId);
    examAccessService.checkCourseAndExamAccessForInstructorElseThrow(courseId, examId);
    // Validate settings of the exam
    examService.validateForStudentExamGeneration(exam);
    List<StudentExam> studentExams = studentExamRepository.generateMissingStudentExams(exam);
    // we need to break a cycle for the serialization
    for (StudentExam studentExam : studentExams) {
        studentExam.getExam().setRegisteredUsers(null);
        studentExam.getExam().setExerciseGroups(null);
        studentExam.getExam().setStudentExams(null);
    }
    log.info("Generated {} missing student exams for exam {}", studentExams.size(), examId);
    return ResponseEntity.ok().body(studentExams);
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 20 with StudentExam

use of de.tum.in.www1.artemis.domain.exam.StudentExam in project ArTEMiS by ls1intum.

the class StudentExamAccessServiceTest method testExamIdEqualsExamOfStudentExam.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testExamIdEqualsExamOfStudentExam() {
    StudentExam studentExamNotRelatedToExam1 = database.addStudentExam(exam2);
    assertThrows(ConflictException.class, () -> studentExamAccessService.checkStudentExamAccessElseThrow(course1.getId(), exam1.getId(), studentExamNotRelatedToExam1.getId(), false));
    assertThrows(ConflictException.class, () -> studentExamAccessService.checkStudentExamAccessElseThrow(course1.getId(), exam1.getId(), studentExamNotRelatedToExam1.getId(), users.get(0), false));
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Aggregations

StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)69 WithMockUser (org.springframework.security.test.context.support.WithMockUser)44 Test (org.junit.jupiter.api.Test)42 Exam (de.tum.in.www1.artemis.domain.exam.Exam)37 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)22 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)20 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)18 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)18 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)16 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)14 ZonedDateTime (java.time.ZonedDateTime)14 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)12 Participation (de.tum.in.www1.artemis.domain.participation.Participation)12 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)12 java.util (java.util)12 Collectors (java.util.stream.Collectors)12 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)12 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)10 AssessmentType (de.tum.in.www1.artemis.domain.enumeration.AssessmentType)10 de.tum.in.www1.artemis.web.rest.dto (de.tum.in.www1.artemis.web.rest.dto)10