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