Search in sources :

Example 16 with Participant

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

the class ComplaintResource method getNumberOfAllowedComplaintsInCourse.

/**
 * Get courses/{courseId}/allowed-complaints get the number of complaints that a student or team is still allowed to submit in the given course.
 * It is determined by the max. complaint limit and the current number of open or rejected complaints of the student or team in the course.
 * Students use their personal complaints for individual exercises and team complaints for team-based exercises, i.e. each student has
 * maxComplaints for personal complaints and additionally maxTeamComplaints for complaints by their team in the course.
 *
 * @param courseId the id of the course for which we want to get the number of allowed complaints
 * @param teamMode whether to return the number of allowed complaints per team (instead of per student)
 * @return the ResponseEntity with status 200 (OK) and the number of still allowed complaints
 */
@GetMapping("courses/{courseId}/allowed-complaints")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Long> getNumberOfAllowedComplaintsInCourse(@PathVariable Long courseId, @RequestParam(defaultValue = "false") Boolean teamMode) {
    log.debug("REST request to get the number of unaccepted Complaints associated to the current user in course : {}", courseId);
    User user = userRepository.getUser();
    Participant participant = user;
    Course course = courseRepository.findByIdElseThrow(courseId);
    if (!course.getComplaintsEnabled()) {
        throw new BadRequestAlertException("Complaints are disabled for this course", COMPLAINT_ENTITY_NAME, "complaintsDisabled");
    }
    if (teamMode) {
        Optional<Team> team = teamRepository.findAllByCourseIdAndUserIdOrderByIdDesc(course.getId(), user.getId()).stream().findFirst();
        participant = team.orElseThrow(() -> new BadRequestAlertException("You do not belong to a team in this course.", COMPLAINT_ENTITY_NAME, "noAssignedTeamInCourse"));
    }
    long unacceptedComplaints = complaintService.countUnacceptedComplaintsByParticipantAndCourseId(participant, courseId);
    return ResponseEntity.ok(Math.max(complaintService.getMaxComplaintsPerParticipant(course, participant) - unacceptedComplaints, 0));
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) Participant(de.tum.in.www1.artemis.domain.participation.Participant) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 17 with Participant

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

the class ParticipantScoreIntegrationTest method getAverageScoreOfParticipantInCourse_asInstructorOfCourse_shouldReturnAverageParticipantScores.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void getAverageScoreOfParticipantInCourse_asInstructorOfCourse_shouldReturnAverageParticipantScores() throws Exception {
    List<ParticipantScoreAverageDTO> participantScoreAverageDTOS = request.getList("/api/courses/" + idOfCourse + "/participant-scores/average-participant", HttpStatus.OK, ParticipantScoreAverageDTO.class);
    assertThat(participantScoreAverageDTOS).hasSize(2);
    ParticipantScoreAverageDTO student1Result = participantScoreAverageDTOS.stream().filter(participantScoreAverageDTO -> participantScoreAverageDTO.userName != null).findFirst().get();
    ParticipantScoreAverageDTO team1Result = participantScoreAverageDTOS.stream().filter(participantScoreAverageDTO -> participantScoreAverageDTO.teamName != null).findFirst().get();
    assertAverageParticipantScoreDTOStructure(student1Result, "student1", null, 50.0, 50.0, 5.0, 5.0);
    assertAverageParticipantScoreDTOStructure(team1Result, null, "team1", 50.0, 50.0, 5.0, 5.0);
}
Also used : ParticipantScoreAverageDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 18 with Participant

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

the class ParticipantScoreIntegrationTest method getParticipantScoresOfExam_asInstructorOfCourse_shouldReturnParticipantScores.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void getParticipantScoresOfExam_asInstructorOfCourse_shouldReturnParticipantScores() throws Exception {
    List<ParticipantScoreDTO> participantScoresOfExam = request.getList("/api/exams/" + idOfExam + "/participant-scores", HttpStatus.OK, ParticipantScoreDTO.class);
    assertThat(participantScoresOfExam).hasSize(1);
    ParticipantScoreDTO student1Result = participantScoresOfExam.stream().filter(participantScoreDTO -> participantScoreDTO.userId != null).findFirst().get();
    assertParticipantScoreDTOStructure(student1Result, idOfStudent1, null, getIdOfIndividualTextExerciseOfExam, 50D, 50D, 5.0, 5.0);
}
Also used : ParticipantScoreDTO(de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 19 with Participant

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

the class ProgrammingExerciseTestService method resumeProgrammingExerciseByTriggeringFailedBuild_correctInitializationState.

// TEST
public void resumeProgrammingExerciseByTriggeringFailedBuild_correctInitializationState(ExerciseMode exerciseMode, boolean buildPlanExists) throws Exception {
    var participation = createStudentParticipationWithSubmission(exerciseMode);
    var participant = participation.getParticipant();
    mockDelegate.mockTriggerFailedBuild(participation);
    // We need to mock the call again because we are triggering the build twice in order to verify that the submission isn't re-created
    mockDelegate.mockTriggerFailedBuild(participation);
    mockDelegate.mockDefaultBranch(participation.getProgrammingExercise());
    // These will be updated triggering a failed build
    participation.setInitializationState(InitializationState.INACTIVE);
    participation.setBuildPlanId(!buildPlanExists ? null : participation.getBuildPlanId());
    programmingExerciseStudentParticipationRepository.saveAndFlush(participation);
    if (!buildPlanExists) {
        mockDelegate.mockConnectorRequestsForResumeParticipation(exercise, participant.getParticipantIdentifier(), participant.getParticipants(), true);
        participation = request.putWithResponseBody("/api/exercises/" + exercise.getId() + "/resume-programming-participation", null, ProgrammingExerciseStudentParticipation.class, HttpStatus.OK);
    }
    // Construct trigger-build url and execute request
    String url = "/api/programming-submissions/" + participation.getId() + "/trigger-failed-build";
    request.postWithoutLocation(url, null, HttpStatus.OK, new HttpHeaders());
    // Fetch updated participation and assert
    ProgrammingExerciseStudentParticipation updatedParticipation = (ProgrammingExerciseStudentParticipation) participationRepository.findByIdElseThrow(participation.getId());
    assertThat(updatedParticipation.getInitializationState()).as("Participation should be initialized").isEqualTo(InitializationState.INITIALIZED);
    assertThat(updatedParticipation.getBuildPlanId()).as("Build Plan Id should be set").isEqualTo(exercise.getProjectKey().toUpperCase() + "-" + participant.getParticipantIdentifier().toUpperCase());
    // Trigger the build again and make sure no new submission is created
    request.postWithoutLocation(url, null, HttpStatus.OK, new HttpHeaders());
    var submissions = submissionRepository.findAll();
    assertThat(submissions).hasSize(1);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)

Example 20 with Participant

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

the class ScoreService method getNewLastResultForParticipantScore.

/**
 * Get the result that can replace the currently set last result for a participant score
 *
 * @param participantScore participant score
 * @return optional of new result
 */
private Optional<Result> getNewLastResultForParticipantScore(ParticipantScore participantScore) {
    List<Result> resultOrdered;
    if (participantScore.getClass().equals(StudentScore.class)) {
        StudentScore studentScore = (StudentScore) participantScore;
        resultOrdered = resultRepository.getResultsOrderedByParticipationIdLegalSubmissionIdResultIdDescForStudent(participantScore.getExercise().getId(), studentScore.getUser().getId()).stream().filter(r -> !participantScore.getLastResult().equals(r)).collect(Collectors.toList());
    } else {
        TeamScore teamScore = (TeamScore) participantScore;
        resultOrdered = resultRepository.getResultsOrderedByParticipationIdLegalSubmissionIdResultIdDescForTeam(participantScore.getExercise().getId(), teamScore.getTeam().getId()).stream().filter(r -> !participantScore.getLastResult().equals(r)).collect(Collectors.toList());
    }
    // the new last result (result with the highest id of submission with the highest id) will be at the beginning of the list
    return resultOrdered.isEmpty() ? Optional.empty() : Optional.of(resultOrdered.get(0));
}
Also used : StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore)

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