Search in sources :

Example 1 with EntityNotFoundException

use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project Artemis by ls1intum.

the class LectureUnitResource method updateLectureUnitsOrder.

/**
 * PUT /lectures/:lectureId/lecture-units-order
 *
 * @param lectureId           the id of the lecture for which to update the lecture unit order
 * @param orderedLectureUnits ordered lecture units
 * @return the ResponseEntity with status 200 (OK) and with body the ordered lecture units
 */
@PutMapping("/lectures/{lectureId}/lecture-units-order")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<List<LectureUnit>> updateLectureUnitsOrder(@PathVariable Long lectureId, @RequestBody List<LectureUnit> orderedLectureUnits) {
    log.debug("REST request to update the order of lecture units of lecture: {}", lectureId);
    Optional<Lecture> lectureOptional = lectureRepository.findByIdWithPostsAndLectureUnitsAndLearningGoals(lectureId);
    if (lectureOptional.isEmpty()) {
        throw new EntityNotFoundException("Lecture", lectureId);
    }
    Lecture lecture = lectureOptional.get();
    if (lecture.getCourse() == null) {
        return conflict();
    }
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, lecture.getCourse(), null);
    // Ensure that exactly as many lecture units have been received as are currently related to the lecture
    if (orderedLectureUnits.size() != lecture.getLectureUnits().size()) {
        return conflict();
    }
    // Ensure that all received lecture units are already related to the lecture
    for (LectureUnit lectureUnit : orderedLectureUnits) {
        if (!lecture.getLectureUnits().contains(lectureUnit)) {
            return conflict();
        }
        // Set the lecture manually as it won't be included in orderedLectureUnits
        lectureUnit.setLecture(lecture);
        // keep bidirectional mapping between attachment unit and attachment
        if (lectureUnit instanceof AttachmentUnit) {
            ((AttachmentUnit) lectureUnit).getAttachment().setAttachmentUnit((AttachmentUnit) lectureUnit);
        }
    }
    lecture.setLectureUnits(orderedLectureUnits);
    Lecture persistedLecture = lectureRepository.save(lecture);
    return ResponseEntity.ok(persistedLecture.getLectureUnits());
}
Also used : Lecture(de.tum.in.www1.artemis.domain.Lecture) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) AttachmentUnit(de.tum.in.www1.artemis.domain.lecture.AttachmentUnit) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with EntityNotFoundException

use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project Artemis by ls1intum.

the class PlagiarismResource method updatePlagiarismComparisonInstructorStatement.

/**
 * Updates an instructor statement on a plagiarismComparison (for one side).
 * This process will send a notification to the respective student.
 * I.e. the instructor sets a personal message to one of the accused students.
 *
 * @param courseId the id of the course
 * @param comparisonId the id of the PlagiarismComparison
 * @param studentLogin of one of accused students
 * @param statement of the instructor directed to one of the accused students
 * @return the instructor statement (convention)
 */
@PutMapping("courses/{courseId}/plagiarism-comparisons/{comparisonId}/instructor-statement/{studentLogin}")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<PlagiarismStatementDTO> updatePlagiarismComparisonInstructorStatement(@PathVariable("courseId") long courseId, @PathVariable("comparisonId") long comparisonId, @PathVariable("studentLogin") String studentLogin, @RequestBody PlagiarismStatementDTO statement) {
    var comparison = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsElseThrow(comparisonId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    User affectedUser = userRepository.getUserByLoginElseThrow(studentLogin);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    String instructorStatement = statement.statement;
    if (!authenticationCheckService.isAtLeastInstructorInCourse(course, user)) {
        throw new AccessForbiddenException("Only instructors responsible for this course can access this plagiarism case.");
    }
    if (!Objects.equals(comparison.getPlagiarismResult().getExercise().getCourseViaExerciseGroupOrCourseMember().getId(), courseId)) {
        throw new BadRequestAlertException("The courseId does not belong to the given comparisonId", "PlagiarismComparison", "idMismatch");
    }
    if (comparison.getSubmissionA().getStudentLogin().equals(studentLogin)) {
        plagiarismComparisonRepository.updatePlagiarismComparisonInstructorStatementA(comparison.getId(), instructorStatement);
        // needed for notifications
        comparison.setInstructorStatementA(instructorStatement);
    } else if (comparison.getSubmissionB().getStudentLogin().equals(studentLogin)) {
        plagiarismComparisonRepository.updatePlagiarismComparisonInstructorStatementB(comparison.getId(), instructorStatement);
        // needed for notifications
        comparison.setInstructorStatementB(instructorStatement);
    } else {
        throw new EntityNotFoundException("Student with id not found in plagiarism comparison");
    }
    singleUserNotificationService.notifyUserAboutNewPossiblePlagiarismCase(comparison, affectedUser);
    return ResponseEntity.ok(statement);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) User(de.tum.in.www1.artemis.domain.User) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) Course(de.tum.in.www1.artemis.domain.Course) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with EntityNotFoundException

use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project ArTEMiS by ls1intum.

the class PlagiarismResource method updatePlagiarismComparisonInstructorStatement.

/**
 * Updates an instructor statement on a plagiarismComparison (for one side).
 * This process will send a notification to the respective student.
 * I.e. the instructor sets a personal message to one of the accused students.
 *
 * @param courseId the id of the course
 * @param comparisonId the id of the PlagiarismComparison
 * @param studentLogin of one of accused students
 * @param statement of the instructor directed to one of the accused students
 * @return the instructor statement (convention)
 */
@PutMapping("courses/{courseId}/plagiarism-comparisons/{comparisonId}/instructor-statement/{studentLogin}")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<PlagiarismStatementDTO> updatePlagiarismComparisonInstructorStatement(@PathVariable("courseId") long courseId, @PathVariable("comparisonId") long comparisonId, @PathVariable("studentLogin") String studentLogin, @RequestBody PlagiarismStatementDTO statement) {
    var comparison = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsElseThrow(comparisonId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    User affectedUser = userRepository.getUserByLoginElseThrow(studentLogin);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    String instructorStatement = statement.statement;
    if (!authenticationCheckService.isAtLeastInstructorInCourse(course, user)) {
        throw new AccessForbiddenException("Only instructors responsible for this course can access this plagiarism case.");
    }
    if (!Objects.equals(comparison.getPlagiarismResult().getExercise().getCourseViaExerciseGroupOrCourseMember().getId(), courseId)) {
        throw new BadRequestAlertException("The courseId does not belong to the given comparisonId", "PlagiarismComparison", "idMismatch");
    }
    if (comparison.getSubmissionA().getStudentLogin().equals(studentLogin)) {
        plagiarismComparisonRepository.updatePlagiarismComparisonInstructorStatementA(comparison.getId(), instructorStatement);
        // needed for notifications
        comparison.setInstructorStatementA(instructorStatement);
    } else if (comparison.getSubmissionB().getStudentLogin().equals(studentLogin)) {
        plagiarismComparisonRepository.updatePlagiarismComparisonInstructorStatementB(comparison.getId(), instructorStatement);
        // needed for notifications
        comparison.setInstructorStatementB(instructorStatement);
    } else {
        throw new EntityNotFoundException("Student with id not found in plagiarism comparison");
    }
    singleUserNotificationService.notifyUserAboutNewPossiblePlagiarismCase(comparison, affectedUser);
    return ResponseEntity.ok(statement);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) User(de.tum.in.www1.artemis.domain.User) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) Course(de.tum.in.www1.artemis.domain.Course) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with EntityNotFoundException

use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project ArTEMiS by ls1intum.

the class FileUploadSubmissionService method lockAndGetFileUploadSubmissionWithoutResult.

/**
 * Get a file upload submission of the given exercise that still needs to be assessed and lock the submission to prevent other tutors from receiving and assessing it.
 *
 * @param fileUploadExercise the exercise the submission should belong to
 * @param correctionRound - the correction round we want our submission to have results for
 * @param ignoreTestRunParticipations flag to determine if test runs should be removed. This should be set to true for exam exercises
 * @return a locked file upload submission that needs an assessment
 */
public FileUploadSubmission lockAndGetFileUploadSubmissionWithoutResult(FileUploadExercise fileUploadExercise, boolean ignoreTestRunParticipations, int correctionRound) {
    FileUploadSubmission fileUploadSubmission = getRandomFileUploadSubmissionEligibleForNewAssessment(fileUploadExercise, ignoreTestRunParticipations, correctionRound).orElseThrow(() -> new EntityNotFoundException("File upload submission for exercise " + fileUploadExercise.getId() + " could not be found"));
    lockSubmission(fileUploadSubmission, correctionRound);
    return fileUploadSubmission;
}
Also used : FileUploadSubmission(de.tum.in.www1.artemis.domain.FileUploadSubmission) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)

Example 5 with EntityNotFoundException

use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project ArTEMiS by ls1intum.

the class AssessmentService method getExampleAssessment.

/**
 * Gets an example submission with the given submissionId and returns the result of the submission.
 *
 * @param submissionId the id of the example modeling submission
 * @return the result of the submission
 * @throws EntityNotFoundException when no submission can be found for the given id
 */
public Result getExampleAssessment(long submissionId) {
    Optional<Submission> optionalSubmission = submissionRepository.findExampleSubmissionByIdWithEagerResult(submissionId);
    Submission submission = optionalSubmission.orElseThrow(() -> new EntityNotFoundException("Example Submission with id \"" + submissionId + "\" does not exist"));
    return submission.getLatestResult();
}
Also used : EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)

Aggregations

EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)96 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)20 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)20 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)16 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)12 Exam (de.tum.in.www1.artemis.domain.exam.Exam)10 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)10 AuditEvent (org.springframework.boot.actuate.audit.AuditEvent)10 User (de.tum.in.www1.artemis.domain.User)9 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)8 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)8 java.util (java.util)8 Collectors (java.util.stream.Collectors)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 Service (org.springframework.stereotype.Service)8 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)6 Course (de.tum.in.www1.artemis.domain.Course)6 Result (de.tum.in.www1.artemis.domain.Result)6