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());
}
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();
}
}
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);
}
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);
}
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));
}
Aggregations