use of de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison in project Artemis by ls1intum.
the class PlagiarismResource method updatePlagiarismComparisonFinalStatus.
/**
* Updates the final status of a plagiarism comparison concerning one of both students.
* This process will send a notification to the respective student.
* I.e. an instructor sends his final verdict/decision
*
* @param courseId the id of the course
* @param comparisonId of the comparison
* @param studentLogin of the student
* @param statusDTO is the final status of this plagiarism comparison concerning one of both students
* @return the final (updated) status of this plagiarism comparison concerning one of both students
*/
@PutMapping("courses/{courseId}/plagiarism-comparisons/{comparisonId}/final-status/{studentLogin}")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<PlagiarismComparisonStatusDTO> updatePlagiarismComparisonFinalStatus(@PathVariable("courseId") long courseId, @PathVariable("comparisonId") long comparisonId, @PathVariable("studentLogin") String studentLogin, @RequestBody PlagiarismComparisonStatusDTO statusDTO) {
var comparison = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsElseThrow(comparisonId);
Course course = courseRepository.findByIdElseThrow(courseId);
User affectedUser = userRepository.getUserWithGroupsAndAuthorities(studentLogin);
User user = userRepository.getUserWithGroupsAndAuthorities();
PlagiarismStatus finalStatus = statusDTO.getStatus();
if (!authenticationCheckService.isAtLeastInstructorInCourse(course, user)) {
throw new AccessForbiddenException("Only instructors responsible for this course can access this plagiarism comparison.");
}
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.updatePlagiarismComparisonFinalStatusA(comparisonId, finalStatus);
// needed for notifications
comparison.setStatusA(finalStatus);
} else if (comparison.getSubmissionB().getStudentLogin().equals(studentLogin)) {
plagiarismComparisonRepository.updatePlagiarismComparisonFinalStatusB(comparisonId, finalStatus);
// needed for notifications
comparison.setStatusB(finalStatus);
} else {
return ResponseEntity.notFound().build();
}
singleUserNotificationService.notifyUserAboutFinalPlagiarismState(comparison, affectedUser);
return ResponseEntity.ok(statusDTO);
}
use of de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison in project Artemis by ls1intum.
the class PlagiarismResource method updatePlagiarismComparisonStatus.
/**
* Update the status of the plagiarism comparison with the given ID.
* I.e. An editor or instructor sees a possible plagiarism case for the first time and decides if it should be further examined, or if it is not a plagiarism.
*
* @param comparisonId of the plagiarism comparison to update the status of
* @param courseId the id of the course
* @param statusDTO new status for the given comparison
* @return the ResponseEntity with status 200 (Ok) or with status 400 (Bad Request) if the parameters are invalid
*/
@PutMapping("courses/{courseId}/plagiarism-comparisons/{comparisonId}/status")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Void> updatePlagiarismComparisonStatus(@PathVariable("courseId") long courseId, @PathVariable("comparisonId") long comparisonId, @RequestBody PlagiarismComparisonStatusDTO statusDTO) {
log.info("REST request to update the status {} of the plagiarism comparison with id: {}", statusDTO.getStatus(), comparisonId);
Course course = courseRepository.findByIdElseThrow(courseId);
authenticationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, course, null);
// TODO: this check can take up to a few seconds in the worst case, we should do it directly in the database
var comparison = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsElseThrow(comparisonId);
if (!Objects.equals(comparison.getPlagiarismResult().getExercise().getCourseViaExerciseGroupOrCourseMember().getId(), courseId)) {
throw new BadRequestAlertException("The courseId does not belong to the given comparisonId", "PlagiarismComparison", "idMismatch");
}
plagiarismComparisonRepository.updatePlagiarismComparisonStatus(comparisonId, statusDTO.getStatus());
log.info("Finished updating the status {} of the plagiarism comparison with id: {}", statusDTO.getStatus(), comparisonId);
return ResponseEntity.ok().body(null);
}
use of de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison 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.domain.plagiarism.PlagiarismComparison in project ArTEMiS by ls1intum.
the class PlagiarismService method anonymizeComparisonForStudentView.
/**
* Anonymizes the comparison for the student view.
* A student should not have sensitive information (e.g. the userLogin of the other student)
*
* @param comparison that has to be anonymized.
* @param userLogin of the student asking to see his plagiarism comparison.
* @return the anoymized plagiarism comparison for the given student
*/
public PlagiarismComparison anonymizeComparisonForStudentView(PlagiarismComparison comparison, String userLogin) {
if (comparison.getSubmissionA().getStudentLogin().equals(userLogin)) {
comparison.getSubmissionA().setStudentLogin(YOUR_SUBMISSION);
comparison.getSubmissionB().setStudentLogin(OTHER_SUBMISSION);
comparison.setInstructorStatementB(null);
} else if (comparison.getSubmissionB().getStudentLogin().equals(userLogin)) {
comparison.getSubmissionA().setStudentLogin(OTHER_SUBMISSION);
comparison.getSubmissionB().setStudentLogin(YOUR_SUBMISSION);
comparison.setInstructorStatementA(null);
} else {
throw new AccessForbiddenException("This plagiarism comparison is not related to the requesting user.");
}
return comparison;
}
use of de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison in project ArTEMiS by ls1intum.
the class PlagiarismIntegrationTest method saveStudentStatementForStudentB.
/**
* Checks the method updatePlagiarismComparisonStudentStatement for student B
*/
@Test
@WithMockUser(username = "student2", roles = "USER")
public void saveStudentStatementForStudentB() throws Exception {
Course course = database.addCourseWithOneFinishedTextExercise();
TextExercise textExercise = textExerciseRepository.findByCourseIdWithCategories(course.getId()).get(0);
TextPlagiarismResult textPlagiarismResult = database.createTextPlagiarismResultForExercise(textExercise);
PlagiarismComparison<TextSubmissionElement> plagiarismComparison = new PlagiarismComparison<>();
plagiarismComparison.setPlagiarismResult(textPlagiarismResult);
plagiarismComparison.setInstructorStatementB(INSTRUCTOR_STATEMENT_B);
PlagiarismSubmission<TextSubmissionElement> submissionB = new PlagiarismSubmission<>();
submissionB.setStudentLogin("student2");
plagiarismComparison.setSubmissionB(submissionB);
plagiarismComparisonRepository.save(plagiarismComparison);
var statement = new PlagiarismResource.PlagiarismStatementDTO();
statement.statement = "test statement";
request.put("/api/courses/" + course.getId() + "/plagiarism-comparisons/" + plagiarismComparison.getId() + "/student-statement", statement, HttpStatus.OK);
var comparison = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsElseThrow(plagiarismComparison.getId());
assertThat(comparison.getStudentStatementB()).as("should update student statement").isEqualTo("test statement");
}
Aggregations