Search in sources :

Example 36 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project Artemis by ls1intum.

the class ResultListenerIntegrationTest method setupTestScenarioWithOneResultSaved.

public ParticipantScore setupTestScenarioWithOneResultSaved(boolean isRatedResult, boolean isTeam) {
    List<ParticipantScore> savedParticipantScores = participantScoreRepository.findAllEagerly();
    assertThat(savedParticipantScores).isEmpty();
    Long idOfExercise;
    Participant participant;
    if (isTeam) {
        participant = teamRepository.findById(idOfTeam1).get();
        idOfExercise = idOfTeamTextExercise;
    } else {
        participant = userRepository.findOneByLogin("student1").get();
        idOfExercise = idOfIndividualTextExercise;
    }
    Result persistedResult = database.createParticipationSubmissionAndResult(idOfExercise, participant, 10.0, 10.0, 200, isRatedResult);
    savedParticipantScores = participantScoreRepository.findAllEagerly();
    assertThat(savedParticipantScores).isNotEmpty();
    assertThat(savedParticipantScores).hasSize(1);
    ParticipantScore savedParticipantScore = savedParticipantScores.get(0);
    Double pointsAchieved = round(persistedResult.getScore() * 0.01 * 10.0);
    if (isRatedResult) {
        assertParticipantScoreStructure(savedParticipantScore, idOfExercise, participant.getId(), persistedResult.getId(), persistedResult.getScore(), persistedResult.getId(), persistedResult.getScore(), pointsAchieved, pointsAchieved);
    } else {
        assertParticipantScoreStructure(savedParticipantScore, idOfExercise, participant.getId(), persistedResult.getId(), persistedResult.getScore(), null, null, pointsAchieved, null);
    }
    verify(this.scoreService, times(1)).updateOrCreateParticipantScore(any());
    return savedParticipantScore;
}
Also used : ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) Participant(de.tum.in.www1.artemis.domain.participation.Participant)

Example 37 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class ParticipantScoreResource method getParticipantScoresOfExam.

/**
 * GET /exams/:examId/participant-scores  gets the participant scores of the exam
 *
 * @param examId     the id of the exam for which to get the participant score
 * @param pageable   pageable object
 * @param getUnpaged if set all participant scores of the exam will be loaded (paging deactivated)
 * @return the ResponseEntity with status 200 (OK) and with the participant scores in the body
 */
@GetMapping("/exams/{examId}/participant-scores")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ParticipantScoreDTO>> getParticipantScoresOfExam(@PathVariable Long examId, Pageable pageable, @RequestParam(value = "getUnpaged", required = false, defaultValue = "false") boolean getUnpaged) {
    long start = System.currentTimeMillis();
    log.debug("REST request to get participant scores for exam : {}", examId);
    Set<Exercise> exercisesOfExam = getExercisesOfExam(examId);
    Pageable page;
    if (getUnpaged) {
        page = Pageable.unpaged();
    } else {
        page = pageable;
    }
    List<ParticipantScoreDTO> resultsOfAllExercises = participantScoreService.getParticipantScoreDTOs(page, exercisesOfExam);
    log.info("getParticipantScoresOfExam took {}ms", System.currentTimeMillis() - start);
    return ResponseEntity.ok().body(resultsOfAllExercises);
}
Also used : Exercise(de.tum.in.www1.artemis.domain.Exercise) Pageable(org.springframework.data.domain.Pageable) ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 38 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class ParticipantScoreResource method getAverageScoreOfCourse.

/**
 * GET /courses/:courseId/participant-scores/average  gets the average score of the course
 * <p>
 * Important: Exercises with {@link de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore#NOT_INCLUDED} will be not taken into account!
 *
 * @param courseId                the id of the course for which to get the average score
 * @param onlyConsiderRatedScores if set the method will get the rated average score, if unset the method will get the average score
 * @return the ResponseEntity with status 200 (OK) and with average score in the body
 */
@GetMapping("/courses/{courseId}/participant-scores/average")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<Double> getAverageScoreOfCourse(@PathVariable Long courseId, @RequestParam(defaultValue = "true", required = false) boolean onlyConsiderRatedScores) {
    long start = System.currentTimeMillis();
    if (onlyConsiderRatedScores) {
        log.debug("REST request to get average rated scores for course : {}", courseId);
    } else {
        log.debug("REST request to get average scores for course : {}", courseId);
    }
    Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
    Set<Exercise> includedExercisesOfCourse = course.getExercises().stream().filter(Exercise::isCourseExercise).filter(exercise -> !exercise.getIncludedInOverallScore().equals(IncludedInOverallScore.NOT_INCLUDED)).collect(toSet());
    Double averageScore = participantScoreService.getAverageScore(onlyConsiderRatedScores, includedExercisesOfCourse);
    log.info("getAverageScoreOfCourse took {}ms", System.currentTimeMillis() - start);
    return ResponseEntity.ok().body(averageScore);
}
Also used : ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) Logger(org.slf4j.Logger) CourseRepository(de.tum.in.www1.artemis.repository.CourseRepository) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) Course(de.tum.in.www1.artemis.domain.Course) Set(java.util.Set) Role(de.tum.in.www1.artemis.security.Role) ParticipantScoreAverageDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO) HashSet(java.util.HashSet) List(java.util.List) ScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ScoreDTO) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) Exercise(de.tum.in.www1.artemis.domain.Exercise) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ParticipantScoreService(de.tum.in.www1.artemis.service.ParticipantScoreService) AuthorizationCheckService(de.tum.in.www1.artemis.service.AuthorizationCheckService) Pageable(org.springframework.data.domain.Pageable) ResponseEntity(org.springframework.http.ResponseEntity) IncludedInOverallScore(de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore) Exam(de.tum.in.www1.artemis.domain.exam.Exam) Collectors.toSet(java.util.stream.Collectors.toSet) ExamRepository(de.tum.in.www1.artemis.repository.ExamRepository) Exercise(de.tum.in.www1.artemis.domain.Exercise) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 39 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class ProgrammingExerciseExportImportResource method exportSubmissionsByStudentLogins.

/**
 * POST /programming-exercises/:exerciseId/export-repos-by-participant-identifiers/:participantIdentifiers : sends all submissions from participantIdentifiers as zip
 *
 * @param exerciseId              the id of the exercise to get the repos from
 * @param participantIdentifiers  the identifiers of the participants (student logins or team short names) for whom to zip the submissions, separated by commas
 * @param repositoryExportOptions the options that should be used for the export
 * @return ResponseEntity with status
 * @throws IOException if something during the zip process went wrong
 */
@PostMapping(EXPORT_SUBMISSIONS_BY_PARTICIPANTS)
@PreAuthorize("hasRole('TA')")
@FeatureToggle(Feature.ProgrammingExercises)
public ResponseEntity<Resource> exportSubmissionsByStudentLogins(@PathVariable long exerciseId, @PathVariable String participantIdentifiers, @RequestBody RepositoryExportOptionsDTO repositoryExportOptions) throws IOException {
    var programmingExercise = programmingExerciseRepository.findByIdWithStudentParticipationsAndLegalSubmissionsElseThrow(exerciseId);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.TEACHING_ASSISTANT, programmingExercise, user);
    if (repositoryExportOptions.isExportAllParticipants()) {
        // only instructors are allowed to download all repos
        authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.INSTRUCTOR, programmingExercise, user);
    }
    if (repositoryExportOptions.getFilterLateSubmissionsDate() == null) {
        repositoryExportOptions.setFilterLateSubmissionsIndividualDueDate(true);
        repositoryExportOptions.setFilterLateSubmissionsDate(programmingExercise.getDueDate());
    }
    List<String> participantIdentifierList = new ArrayList<>();
    if (!repositoryExportOptions.isExportAllParticipants()) {
        participantIdentifiers = participantIdentifiers.replaceAll("\\s+", "");
        participantIdentifierList = Arrays.asList(participantIdentifiers.split(","));
    }
    // Select the participations that should be exported
    List<ProgrammingExerciseStudentParticipation> exportedStudentParticipations = new ArrayList<>();
    for (StudentParticipation studentParticipation : programmingExercise.getStudentParticipations()) {
        ProgrammingExerciseStudentParticipation programmingStudentParticipation = (ProgrammingExerciseStudentParticipation) studentParticipation;
        if (repositoryExportOptions.isExportAllParticipants() || (programmingStudentParticipation.getRepositoryUrl() != null && studentParticipation.getParticipant() != null && participantIdentifierList.contains(studentParticipation.getParticipantIdentifier()))) {
            exportedStudentParticipations.add(programmingStudentParticipation);
        }
    }
    return provideZipForParticipations(exportedStudentParticipations, programmingExercise, repositoryExportOptions);
}
Also used : User(de.tum.in.www1.artemis.domain.User) ArrayList(java.util.ArrayList) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) FeatureToggle(de.tum.in.www1.artemis.service.feature.FeatureToggle) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 40 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class ComplaintResponseResource method handleComplaintResponse.

private ResponseEntity<ComplaintResponse> handleComplaintResponse(long complaintId, Principal principal, Optional<ComplaintResponse> optionalComplaintResponse) {
    if (optionalComplaintResponse.isEmpty()) {
        throw new EntityNotFoundException("ComplaintResponse with " + complaintId + " was not found!");
    }
    var user = userRepository.getUserWithGroupsAndAuthorities();
    var complaintResponse = optionalComplaintResponse.get();
    // All tutors and higher can see this, and also the students who first open the complaint
    Participant originalAuthor = complaintResponse.getComplaint().getParticipant();
    StudentParticipation studentParticipation = (StudentParticipation) complaintResponse.getComplaint().getResult().getParticipation();
    Exercise exercise = studentParticipation.getExercise();
    var atLeastTA = authorizationCheckService.isAtLeastTeachingAssistantForExercise(exercise, user);
    if (!atLeastTA && !isOriginalAuthor(principal, originalAuthor)) {
        throw new AccessForbiddenException("Insufficient permission for this complaint response");
    }
    if (!authorizationCheckService.isAtLeastInstructorForExercise(exercise, user)) {
        complaintResponse.getComplaint().setParticipant(null);
    }
    if (!atLeastTA) {
        complaintResponse.setReviewer(null);
    }
    if (isOriginalAuthor(principal, originalAuthor)) {
        // hide complaint completely if the user is the student who created the complaint
        complaintResponse.setComplaint(null);
    } else {
        // hide unnecessary information
        complaintResponse.getComplaint().getResult().setParticipation(null);
        complaintResponse.getComplaint().getResult().setSubmission(null);
    }
    return ResponseUtil.wrapOrNotFound(optionalComplaintResponse);
}
Also used : Participant(de.tum.in.www1.artemis.domain.participation.Participant) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)

Aggregations

StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)21 Participant (de.tum.in.www1.artemis.domain.participation.Participant)15 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)14 ParticipantScore (de.tum.in.www1.artemis.domain.scores.ParticipantScore)14 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 ParticipantScoreDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO)12 StudentScore (de.tum.in.www1.artemis.domain.scores.StudentScore)10 TeamScore (de.tum.in.www1.artemis.domain.scores.TeamScore)10 Test (org.junit.jupiter.api.Test)10 WithMockUser (org.springframework.security.test.context.support.WithMockUser)10 Exercise (de.tum.in.www1.artemis.domain.Exercise)8 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)8 ParticipantScoreAverageDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO)8 java.util (java.util)8 Collectors (java.util.stream.Collectors)8 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)7 QuizSubmission (de.tum.in.www1.artemis.domain.quiz.QuizSubmission)7 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)6 Course (de.tum.in.www1.artemis.domain.Course)6 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)6