Search in sources :

Example 46 with ExerciseGroup

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

the class ExamResource method getExamForTestRunAssessmentDashboard.

/**
 * GET /courses/:courseId/exams/:examId/exam-for-test-run-assessment-dashboard
 *
 * @param courseId the id of the course to retrieve
 * @param examId   the id of the exam that contains the exercises
 * @return data about an exam test run including all exercises, plus some data for the tutor as tutor status for assessment
 */
@GetMapping("/courses/{courseId}/exams/{examId}/exam-for-test-run-assessment-dashboard")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<Exam> getExamForTestRunAssessmentDashboard(@PathVariable long courseId, @PathVariable long examId) {
    log.debug("REST request /courses/{courseId}/exams/{examId}/exam-for-test-run-assessment-dashboard");
    Exam exam = examService.findByIdWithExerciseGroupsAndExercisesElseThrow(examId);
    Course course = exam.getCourse();
    checkExamCourseIdElseThrow(courseId, exam);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
    for (ExerciseGroup exerciseGroup : exam.getExerciseGroups()) {
        exerciseGroup.setExercises(courseRepository.getInterestingExercisesForAssessmentDashboards(exerciseGroup.getExercises()));
    }
    return ResponseEntity.ok(exam);
}
Also used : ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) 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 47 with ExerciseGroup

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

the class ExamResource method updateOrderOfExerciseGroups.

/**
 * PUT /courses/:courseId/exams/:examId/exercise-groups-order : Update the order of exercise groups. If the received
 * exercise groups do not belong to the exam the operation is aborted.
 *
 * @param courseId              the id of the course
 * @param examId                the id of the exam
 * @param orderedExerciseGroups the exercise groups of the exam in the desired order.
 * @return the list of exercise groups
 */
@PutMapping("/courses/{courseId}/exams/{examId}/exercise-groups-order")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<List<ExerciseGroup>> updateOrderOfExerciseGroups(@PathVariable Long courseId, @PathVariable Long examId, @RequestBody List<ExerciseGroup> orderedExerciseGroups) {
    log.debug("REST request to update the order of exercise groups of exam : {}", examId);
    examAccessService.checkCourseAndExamAccessForEditorElseThrow(courseId, examId);
    Exam exam = examRepository.findByIdWithExerciseGroupsElseThrow(examId);
    // Ensure that exactly as many exercise groups have been received as are currently related to the exam
    if (orderedExerciseGroups.size() != exam.getExerciseGroups().size()) {
        throw new AccessForbiddenException("exam", examId);
    }
    // Ensure that all received exercise groups are already related to the exam
    for (ExerciseGroup exerciseGroup : orderedExerciseGroups) {
        if (!exam.getExerciseGroups().contains(exerciseGroup)) {
            throw new AccessForbiddenException("exam", examId);
        }
        // Set the exam manually as it won't be included in orderedExerciseGroups
        exerciseGroup.setExam(exam);
    }
    exam.setExerciseGroups(orderedExerciseGroups);
    examRepository.save(exam);
    // Return the original request body as it might contain exercise details (e.g. quiz questions), which would be lost otherwise
    return ResponseEntity.ok(orderedExerciseGroups);
}
Also used : ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 48 with ExerciseGroup

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

the class ExerciseGroupResource method getExerciseGroup.

/**
 * GET /courses/{courseId}/exams/{examId}/exerciseGroups/{exerciseGroupId} : Find an exercise group by id.
 *
 * @param courseId          the course to which the exercise group belongs to
 * @param examId            the exam to which the exercise group belongs to
 * @param exerciseGroupId   the id of the exercise group to find
 * @return the ResponseEntity with status 200 (OK) and with the found exercise group as body
 */
@GetMapping("/courses/{courseId}/exams/{examId}/exerciseGroups/{exerciseGroupId}")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<ExerciseGroup> getExerciseGroup(@PathVariable Long courseId, @PathVariable Long examId, @PathVariable Long exerciseGroupId) {
    log.debug("REST request to get exercise group : {}", exerciseGroupId);
    ExerciseGroup exerciseGroup = exerciseGroupRepository.findByIdElseThrow(exerciseGroupId);
    examAccessService.checkCourseAndExamAndExerciseGroupAccessElseThrow(Role.EDITOR, courseId, examId, exerciseGroup);
    return ResponseEntity.ok(exerciseGroup);
}
Also used : ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 49 with ExerciseGroup

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

the class ExerciseGroupResource method updateExerciseGroup.

/**
 * PUT /courses/{courseId}/exams/{examId}/exerciseGroups : Update an existing exercise group.
 *
 * @param courseId              the course to which the exercise group belongs to
 * @param examId                the exam to which the exercise group belongs to
 * @param updatedExerciseGroup  the exercise group to update
 * @return the ResponseEntity with status 200 (OK) and with the body of the updated exercise group
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PutMapping("/courses/{courseId}/exams/{examId}/exerciseGroups")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<ExerciseGroup> updateExerciseGroup(@PathVariable Long courseId, @PathVariable Long examId, @RequestBody ExerciseGroup updatedExerciseGroup) throws URISyntaxException {
    log.debug("REST request to update an exercise group : {}", updatedExerciseGroup);
    if (updatedExerciseGroup.getId() == null) {
        return createExerciseGroup(courseId, examId, updatedExerciseGroup);
    }
    if (updatedExerciseGroup.getExam() == null) {
        throw new ConflictException("The exercise group has to belong to an exam.", ENTITY_NAME, "missingExam");
    }
    examAccessService.checkCourseAndExamAndExerciseGroupAccessElseThrow(Role.EDITOR, courseId, examId, updatedExerciseGroup);
    ExerciseGroup result = exerciseGroupRepository.save(updatedExerciseGroup);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, result.getTitle())).body(result);
}
Also used : ConflictException(de.tum.in.www1.artemis.web.rest.errors.ConflictException) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 50 with ExerciseGroup

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

the class ExerciseGroupResource method deleteExerciseGroup.

/**
 * DELETE /courses/{courseId}/exams/{examId}/exerciseGroups/{exerciseGroupId} : Delete the exercise group with the given id.
 *
 * @param courseId          the course to which the exercise group belongs to
 * @param examId            the exam to which the exercise group belongs to
 * @param exerciseGroupId   the id of the exercise group to delete
 * @param deleteStudentReposBuildPlans boolean which states whether the corresponding student build plans should be deleted
 * @param deleteBaseReposBuildPlans boolean which states whether the corresponding base build plans should be deleted
 * @return the ResponseEntity with status 200 (OK)
 */
@DeleteMapping("/courses/{courseId}/exams/{examId}/exerciseGroups/{exerciseGroupId}")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<Void> deleteExerciseGroup(@PathVariable Long courseId, @PathVariable Long examId, @PathVariable Long exerciseGroupId, @RequestParam(defaultValue = "false") boolean deleteStudentReposBuildPlans, @RequestParam(defaultValue = "false") boolean deleteBaseReposBuildPlans) {
    log.info("REST request to delete exercise group : {}", exerciseGroupId);
    ExerciseGroup exerciseGroup = exerciseGroupRepository.findByIdWithExercisesElseThrow(exerciseGroupId);
    examAccessService.checkCourseAndExamAndExerciseGroupAccessElseThrow(Role.INSTRUCTOR, courseId, examId, exerciseGroup);
    User user = userRepository.getUser();
    AuditEvent auditEvent = new AuditEvent(user.getLogin(), Constants.DELETE_EXERCISE_GROUP, "exerciseGroup=" + exerciseGroup.getTitle());
    auditEventRepository.add(auditEvent);
    log.info("User {} has requested to delete the exercise group {}", user.getLogin(), exerciseGroup.getTitle());
    for (Exercise exercise : exerciseGroup.getExercises()) {
        exerciseDeletionService.delete(exercise.getId(), deleteStudentReposBuildPlans, deleteBaseReposBuildPlans);
    }
    // Remove the exercise group by removing it from the list of exercise groups of the corresponding exam.
    // This is necessary as @OrderColumn (exercise_group_order) needs continuous values. Otherwise the client will
    // receive null values for the gaps in exam.getExerciseGroups().
    Exam exam = examRepository.findByIdWithExerciseGroupsElseThrow(examId);
    List<ExerciseGroup> filteredExerciseGroups = exam.getExerciseGroups();
    filteredExerciseGroups.removeIf(exGroup -> exGroup.getId().equals(exerciseGroupId));
    exam.setExerciseGroups(filteredExerciseGroups);
    examRepository.save(exam);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, exerciseGroup.getTitle())).build();
}
Also used : User(de.tum.in.www1.artemis.domain.User) Exercise(de.tum.in.www1.artemis.domain.Exercise) AuditEvent(org.springframework.boot.actuate.audit.AuditEvent) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) Exam(de.tum.in.www1.artemis.domain.exam.Exam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)126 WithMockUser (org.springframework.security.test.context.support.WithMockUser)76 Test (org.junit.jupiter.api.Test)70 Exam (de.tum.in.www1.artemis.domain.exam.Exam)64 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)46 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)46 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)22 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)22 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)20 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)20 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)18 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)14 TextExercise (de.tum.in.www1.artemis.domain.TextExercise)12 ZonedDateTime (java.time.ZonedDateTime)12 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)10 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)10 Collectors (java.util.stream.Collectors)10 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)8 Participation (de.tum.in.www1.artemis.domain.participation.Participation)8