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