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