Search in sources :

Example 1 with PlagiarismComparisonStatusDTO

use of de.tum.in.www1.artemis.web.rest.dto.PlagiarismComparisonStatusDTO in project Artemis by ls1intum.

the class PlagiarismIntegrationTest method updatePlagiarismComparisonFinalStatusForUnknownStudent.

/**
 * Checks the method updatePlagiarismComparisonFinalStatus for unknown student
 */
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updatePlagiarismComparisonFinalStatusForUnknownStudent() throws Exception {
    Course course = database.addCourseWithOneFinishedTextExercise();
    TextExercise textExercise = textExerciseRepository.findByCourseIdWithCategories(course.getId()).get(0);
    TextPlagiarismResult textPlagiarismResult = database.createTextPlagiarismResultForExercise(textExercise);
    PlagiarismComparison<TextSubmissionElement> plagiarismComparison = new PlagiarismComparison<>();
    PlagiarismSubmission<TextSubmissionElement> submissionA = new PlagiarismSubmission<>();
    submissionA.setStudentLogin("student1");
    PlagiarismSubmission<TextSubmissionElement> submissionB = new PlagiarismSubmission<>();
    submissionB.setStudentLogin("student2");
    plagiarismComparison.setInstructorStatementB(INSTRUCTOR_STATEMENT_B);
    plagiarismComparison.setPlagiarismResult(textPlagiarismResult);
    plagiarismComparison.setStatusB(PlagiarismStatus.NONE);
    plagiarismComparison.setSubmissionA(submissionA);
    plagiarismComparison.setSubmissionB(submissionB);
    plagiarismComparisonRepository.save(plagiarismComparison);
    request.put("/api/courses/" + course.getId() + "/plagiarism-comparisons/" + plagiarismComparison.getId() + "/final-status/student42", new PlagiarismComparisonStatusDTO(), HttpStatus.NOT_FOUND);
}
Also used : PlagiarismComparison(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison) TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) PlagiarismSubmission(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission) TextExercise(de.tum.in.www1.artemis.domain.TextExercise) Course(de.tum.in.www1.artemis.domain.Course) TextSubmissionElement(de.tum.in.www1.artemis.domain.plagiarism.text.TextSubmissionElement) PlagiarismComparisonStatusDTO(de.tum.in.www1.artemis.web.rest.dto.PlagiarismComparisonStatusDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 2 with PlagiarismComparisonStatusDTO

use of de.tum.in.www1.artemis.web.rest.dto.PlagiarismComparisonStatusDTO 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);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) User(de.tum.in.www1.artemis.domain.User) Course(de.tum.in.www1.artemis.domain.Course) PlagiarismStatus(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismStatus) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with PlagiarismComparisonStatusDTO

use of de.tum.in.www1.artemis.web.rest.dto.PlagiarismComparisonStatusDTO 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);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with PlagiarismComparisonStatusDTO

use of de.tum.in.www1.artemis.web.rest.dto.PlagiarismComparisonStatusDTO in project ArTEMiS by ls1intum.

the class PlagiarismIntegrationTest method updatePlagiarismComparisonFinalStatusForUnknownStudent.

/**
 * Checks the method updatePlagiarismComparisonFinalStatus for unknown student
 */
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updatePlagiarismComparisonFinalStatusForUnknownStudent() throws Exception {
    Course course = database.addCourseWithOneFinishedTextExercise();
    TextExercise textExercise = textExerciseRepository.findByCourseIdWithCategories(course.getId()).get(0);
    TextPlagiarismResult textPlagiarismResult = database.createTextPlagiarismResultForExercise(textExercise);
    PlagiarismComparison<TextSubmissionElement> plagiarismComparison = new PlagiarismComparison<>();
    PlagiarismSubmission<TextSubmissionElement> submissionA = new PlagiarismSubmission<>();
    submissionA.setStudentLogin("student1");
    PlagiarismSubmission<TextSubmissionElement> submissionB = new PlagiarismSubmission<>();
    submissionB.setStudentLogin("student2");
    plagiarismComparison.setInstructorStatementB(INSTRUCTOR_STATEMENT_B);
    plagiarismComparison.setPlagiarismResult(textPlagiarismResult);
    plagiarismComparison.setStatusB(PlagiarismStatus.NONE);
    plagiarismComparison.setSubmissionA(submissionA);
    plagiarismComparison.setSubmissionB(submissionB);
    plagiarismComparisonRepository.save(plagiarismComparison);
    request.put("/api/courses/" + course.getId() + "/plagiarism-comparisons/" + plagiarismComparison.getId() + "/final-status/student42", new PlagiarismComparisonStatusDTO(), HttpStatus.NOT_FOUND);
}
Also used : PlagiarismComparison(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison) TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) PlagiarismSubmission(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission) TextExercise(de.tum.in.www1.artemis.domain.TextExercise) Course(de.tum.in.www1.artemis.domain.Course) TextSubmissionElement(de.tum.in.www1.artemis.domain.plagiarism.text.TextSubmissionElement) PlagiarismComparisonStatusDTO(de.tum.in.www1.artemis.web.rest.dto.PlagiarismComparisonStatusDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 5 with PlagiarismComparisonStatusDTO

use of de.tum.in.www1.artemis.web.rest.dto.PlagiarismComparisonStatusDTO in project ArTEMiS by ls1intum.

the class PlagiarismIntegrationTest method updatePlagiarismComparisonFinalStatusForStudentB.

/**
 * Checks the method updatePlagiarismComparisonFinalStatus for second (B) user
 */
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updatePlagiarismComparisonFinalStatusForStudentB() throws Exception {
    Course course = database.addCourseWithOneFinishedTextExercise();
    TextExercise textExercise = textExerciseRepository.findByCourseIdWithCategories(course.getId()).get(0);
    TextPlagiarismResult textPlagiarismResult = database.createTextPlagiarismResultForExercise(textExercise);
    PlagiarismComparison<TextSubmissionElement> plagiarismComparison = new PlagiarismComparison<>();
    PlagiarismSubmission<TextSubmissionElement> submissionA = new PlagiarismSubmission<>();
    submissionA.setStudentLogin("student1");
    PlagiarismSubmission<TextSubmissionElement> submissionB = new PlagiarismSubmission<>();
    submissionB.setStudentLogin("student2");
    plagiarismComparison.setInstructorStatementB(INSTRUCTOR_STATEMENT_B);
    plagiarismComparison.setPlagiarismResult(textPlagiarismResult);
    plagiarismComparison.setStatusB(PlagiarismStatus.NONE);
    plagiarismComparison.setSubmissionA(submissionA);
    plagiarismComparison.setSubmissionB(submissionB);
    plagiarismComparisonRepository.save(plagiarismComparison);
    var plagiarismComparisonStatus = new PlagiarismComparisonStatusDTO();
    plagiarismComparisonStatus.setStatus(PlagiarismStatus.CONFIRMED);
    request.put("/api/courses/" + course.getId() + "/plagiarism-comparisons/" + plagiarismComparison.getId() + "/final-status/student2", plagiarismComparisonStatus, HttpStatus.OK);
    var updatedPlagiarismComparison = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsElseThrow(plagiarismComparison.getId());
    assertThat(updatedPlagiarismComparison.getStatusB()).as("should update status for studentB").isEqualTo(PlagiarismStatus.CONFIRMED);
}
Also used : PlagiarismComparison(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison) TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) PlagiarismSubmission(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission) TextExercise(de.tum.in.www1.artemis.domain.TextExercise) Course(de.tum.in.www1.artemis.domain.Course) TextSubmissionElement(de.tum.in.www1.artemis.domain.plagiarism.text.TextSubmissionElement) PlagiarismComparisonStatusDTO(de.tum.in.www1.artemis.web.rest.dto.PlagiarismComparisonStatusDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Aggregations

Course (de.tum.in.www1.artemis.domain.Course)12 TextExercise (de.tum.in.www1.artemis.domain.TextExercise)6 PlagiarismComparison (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison)6 PlagiarismSubmission (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission)6 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)6 TextSubmissionElement (de.tum.in.www1.artemis.domain.plagiarism.text.TextSubmissionElement)6 PlagiarismComparisonStatusDTO (de.tum.in.www1.artemis.web.rest.dto.PlagiarismComparisonStatusDTO)6 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)6 Test (org.junit.jupiter.api.Test)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 WithMockUser (org.springframework.security.test.context.support.WithMockUser)6 User (de.tum.in.www1.artemis.domain.User)4 PlagiarismStatus (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismStatus)2 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)2