Search in sources :

Example 36 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 37 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 38 with StudentExam

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

the class ExamActivityResource method updatePerformedExamActions.

/**
 * PUT /courses/{courseId}/exams/{examId}/student-exams/{studentExamId}/actions: Adds the performed actions by
 * the user
 *
 * @param courseId      the course to which the student exams belong to
 * @param examId        the exam to which the student exams belong to
 * @param studentExamId the student exam id where we want to add the actions
 * @param actions       list of actions performed by the user after the last synchronisation
 * @return 200 if successful
 */
@PutMapping("/courses/{courseId}/exams/{examId}/student-exams/{studentExamId}/actions")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Void> updatePerformedExamActions(@PathVariable Long courseId, @PathVariable Long examId, @PathVariable Long studentExamId, @RequestBody List<ExamAction> actions) {
    Exam exam = examRepository.findByIdElseThrow(examId);
    if (!exam.isMonitoring()) {
        throw new BadRequestException("Monitoring is not enabled for the exam with the id " + examId);
    }
    StudentExam studentExam = studentExamRepository.findByIdWithExercisesElseThrow(studentExamId);
    User currentUser = userRepository.getUserWithGroupsAndAuthorities();
    boolean isTestRun = studentExam.isTestRun();
    this.studentExamAccessService.checkStudentExamAccessElseThrow(courseId, examId, studentExamId, currentUser, isTestRun);
    // TODO: Validate actions
    actions.forEach(action -> examMonitoringScheduleService.addExamAction(examId, studentExamId, action));
    log.info("REST request by user: {} for exam with id {} to add {} actions for student-exam {}", currentUser.getLogin(), examId, actions.size(), studentExamId);
    return ResponseEntity.ok().build();
}
Also used : User(de.tum.in.www1.artemis.domain.User) BadRequestException(javax.ws.rs.BadRequestException) 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 39 with StudentExam

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

the class ExamResource method generateStudentExams.

/**
 * POST /courses/:courseId/exams/:examId/generate-student-exams : Generates the student exams 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-student-exams")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<StudentExam>> generateStudentExams(@PathVariable Long courseId, @PathVariable Long examId) {
    long start = System.nanoTime();
    log.info("REST request to generate student exams for exam {}", examId);
    final Exam exam = examRepository.findByIdWithRegisteredUsersExerciseGroupsAndExercisesElseThrow(examId);
    examAccessService.checkCourseAndExamAccessForInstructorElseThrow(courseId, exam);
    // Validate settings of the exam
    examService.validateForStudentExamGeneration(exam);
    examService.combineTemplateCommitsOfAllProgrammingExercisesInExam(exam);
    List<StudentExam> studentExams = studentExamRepository.generateStudentExams(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);
    }
    // Reschedule after creation (possible longer working time)
    examMonitoringScheduleService.scheduleExamActivitySave(examId);
    log.info("Generated {} student exams in {} for exam {}", studentExams.size(), formatDurationFrom(start), 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 40 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