Search in sources :

Example 1 with PlagiarismCaseDTO

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

the class PlagiarismResource method getPlagiarismComparisonForStudent.

/**
 * Retrieves the plagiarismComparison specified by its Id. The submissions are anonymized for the student.
 * StudentIds are replaced with "Your Submission" and "Other Submission" based on the requesting user.
 *
 * @param courseId the id of the course
 * @param comparisonId the id of the PlagiarismComparison
 * @return the PlagiarismComparison
 * @throws AccessForbiddenException if the requesting user is not affected by the plagiarism case.
 */
@GetMapping("courses/{courseId}/plagiarism-comparisons/{comparisonId}")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<PlagiarismCaseDTO> getPlagiarismComparisonForStudent(@PathVariable("courseId") long courseId, @PathVariable("comparisonId") Long comparisonId) {
    var comparison = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsElseThrow(comparisonId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    if (!authenticationCheckService.isAtLeastStudentInCourse(course, user)) {
        throw new AccessForbiddenException("Only students registered 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");
    }
    // check if current user is part of the comparison or not
    if (!(comparison.getSubmissionA().getStudentLogin().equals(user.getLogin()) || comparison.getSubmissionB().getStudentLogin().equals(user.getLogin()))) {
        log.error("User {} tried accessing plagiarism case with comparison id {} they're not affected by.", user.getLogin(), comparisonId);
        throw new AccessForbiddenException("User tried accessing plagiarism case they're not affected by.");
    }
    PlagiarismComparison<?> anonymizedComparisonForStudentView = this.plagiarismService.anonymizeComparisonForStudentView(comparison, user.getLogin());
    return ResponseEntity.ok(new PlagiarismCaseDTO(anonymizedComparisonForStudentView.getPlagiarismResult().getExercise(), Set.of(anonymizedComparisonForStudentView)));
}
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) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PlagiarismCaseDTO(de.tum.in.www1.artemis.web.rest.dto.PlagiarismCaseDTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with PlagiarismCaseDTO

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

the class PlagiarismResource method getPlagiarismCasesForCourse.

/**
 * Retrieves all plagiarismCases related to a course that were previously confirmed.
 *
 * @param courseId the id of the course
 * @return all plagiarism cases
 */
@GetMapping("courses/{courseId}/plagiarism-cases")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<PlagiarismCaseDTO>> getPlagiarismCasesForCourse(@PathVariable long courseId) {
    log.debug("REST request to get all plagiarism cases in course with id: {}", courseId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    if (!authenticationCheckService.isAtLeastInstructorInCourse(course, userRepository.getUserWithGroupsAndAuthorities())) {
        throw new AccessForbiddenException("Only instructors of this course have access to its plagiarism cases.");
    }
    List<PlagiarismCaseDTO> foundPlagiarismCasesForCourse = this.plagiarismService.collectAllPlagiarismCasesForCourse(courseId);
    return ResponseEntity.ok(foundPlagiarismCasesForCourse);
}
Also used : Course(de.tum.in.www1.artemis.domain.Course) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PlagiarismCaseDTO(de.tum.in.www1.artemis.web.rest.dto.PlagiarismCaseDTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with PlagiarismCaseDTO

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

the class PlagiarismResource method getPlagiarismComparisonForStudent.

/**
 * Retrieves the plagiarismComparison specified by its Id. The submissions are anonymized for the student.
 * StudentIds are replaced with "Your Submission" and "Other Submission" based on the requesting user.
 *
 * @param courseId the id of the course
 * @param comparisonId the id of the PlagiarismComparison
 * @return the PlagiarismComparison
 * @throws AccessForbiddenException if the requesting user is not affected by the plagiarism case.
 */
@GetMapping("courses/{courseId}/plagiarism-comparisons/{comparisonId}")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<PlagiarismCaseDTO> getPlagiarismComparisonForStudent(@PathVariable("courseId") long courseId, @PathVariable("comparisonId") Long comparisonId) {
    var comparison = plagiarismComparisonRepository.findByIdWithSubmissionsStudentsElseThrow(comparisonId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    if (!authenticationCheckService.isAtLeastStudentInCourse(course, user)) {
        throw new AccessForbiddenException("Only students registered 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");
    }
    // check if current user is part of the comparison or not
    if (!(comparison.getSubmissionA().getStudentLogin().equals(user.getLogin()) || comparison.getSubmissionB().getStudentLogin().equals(user.getLogin()))) {
        log.error("User {} tried accessing plagiarism case with comparison id {} they're not affected by.", user.getLogin(), comparisonId);
        throw new AccessForbiddenException("User tried accessing plagiarism case they're not affected by.");
    }
    PlagiarismComparison<?> anonymizedComparisonForStudentView = this.plagiarismService.anonymizeComparisonForStudentView(comparison, user.getLogin());
    return ResponseEntity.ok(new PlagiarismCaseDTO(anonymizedComparisonForStudentView.getPlagiarismResult().getExercise(), Set.of(anonymizedComparisonForStudentView)));
}
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) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PlagiarismCaseDTO(de.tum.in.www1.artemis.web.rest.dto.PlagiarismCaseDTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with PlagiarismCaseDTO

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

the class PlagiarismService method collectAllPlagiarismCasesForCourse.

/**
 * Collects all plagiarism cases for a given course
 *
 * @param courseId of the course
 * @return the collected plagiarism cases
 */
public List<PlagiarismCaseDTO> collectAllPlagiarismCasesForCourse(Long courseId) {
    // TODO why do we do this so strangely (this is working legacy code)? Refactor in a follow up
    var collectedPlagiarismCases = new ArrayList<PlagiarismCaseDTO>();
    var exerciseIDs = exerciseRepository.findAllIdsByCourseId(courseId);
    exerciseIDs.forEach(id -> {
        var exerciseOptional = exerciseRepository.findById(id);
        if (exerciseOptional.isPresent()) {
            PlagiarismResult<?> result = plagiarismResultRepository.findFirstByExerciseIdOrderByLastModifiedDateDescOrNull(exerciseOptional.get().getId());
            if (result != null) {
                Set<PlagiarismComparison<?>> filteredComparisons = result.getComparisons().stream().filter(c -> c.getStatus() == PlagiarismStatus.CONFIRMED).collect(Collectors.toSet());
                if (filteredComparisons.size() > 0) {
                    collectedPlagiarismCases.add(new PlagiarismCaseDTO(exerciseOptional.get(), filteredComparisons));
                }
            }
        }
    });
    return collectedPlagiarismCases;
}
Also used : Set(java.util.Set) PlagiarismComparisonRepository(de.tum.in.www1.artemis.repository.PlagiarismComparisonRepository) Submission(de.tum.in.www1.artemis.domain.Submission) PlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismResult) Collectors(java.util.stream.Collectors) PlagiarismResultRepository(de.tum.in.www1.artemis.repository.PlagiarismResultRepository) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) ArrayList(java.util.ArrayList) ExerciseRepository(de.tum.in.www1.artemis.repository.ExerciseRepository) PlagiarismComparison(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison) PlagiarismStatus(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismStatus) List(java.util.List) PlagiarismCaseDTO(de.tum.in.www1.artemis.web.rest.dto.PlagiarismCaseDTO) Service(org.springframework.stereotype.Service) PlagiarismComparison(de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison) ArrayList(java.util.ArrayList) PlagiarismCaseDTO(de.tum.in.www1.artemis.web.rest.dto.PlagiarismCaseDTO)

Aggregations

PlagiarismCaseDTO (de.tum.in.www1.artemis.web.rest.dto.PlagiarismCaseDTO)4 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)4 Course (de.tum.in.www1.artemis.domain.Course)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 User (de.tum.in.www1.artemis.domain.User)2 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)2 Submission (de.tum.in.www1.artemis.domain.Submission)1 PlagiarismComparison (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison)1 PlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismResult)1 PlagiarismStatus (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismStatus)1 ExerciseRepository (de.tum.in.www1.artemis.repository.ExerciseRepository)1 PlagiarismComparisonRepository (de.tum.in.www1.artemis.repository.PlagiarismComparisonRepository)1 PlagiarismResultRepository (de.tum.in.www1.artemis.repository.PlagiarismResultRepository)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Service (org.springframework.stereotype.Service)1