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