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 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 LearningGoalIntegrationTest method createParticipationSubmissionAndResult.
private void createParticipationSubmissionAndResult(Long idOfExercise, Participant participant, Double pointsOfExercise, Double bonusPointsOfExercise, long scoreAwarded, boolean rated) {
Exercise exercise = exerciseRepository.findById(idOfExercise).get();
if (!exercise.getMaxPoints().equals(pointsOfExercise)) {
exercise.setMaxPoints(pointsOfExercise);
}
if (!exercise.getBonusPoints().equals(bonusPointsOfExercise)) {
exercise.setBonusPoints(bonusPointsOfExercise);
}
exercise = exerciseRepository.save(exercise);
StudentParticipation studentParticipation = participationService.startExercise(exercise, participant, false);
Submission submission;
if (exercise instanceof ProgrammingExercise) {
submission = new ProgrammingSubmission();
} else if (exercise instanceof ModelingExercise) {
submission = new ModelingSubmission();
} else if (exercise instanceof TextExercise) {
submission = new TextSubmission();
} else if (exercise instanceof FileUploadExercise) {
submission = new FileUploadSubmission();
} else if (exercise instanceof QuizExercise) {
submission = new QuizSubmission();
} else {
throw new RuntimeException("Unsupported exercise type: " + exercise);
}
submission.setType(SubmissionType.MANUAL);
submission.setParticipation(studentParticipation);
submission = submissionRepository.save(submission);
// result
Result result = ModelFactory.generateResult(rated, scoreAwarded);
result.setParticipation(studentParticipation);
result.setCompletionDate(ZonedDateTime.now());
result = resultRepository.save(result);
submission.addResult(result);
result.setSubmission(submission);
submissionRepository.save(submission);
}
use of de.tum.in.www1.artemis.domain.participation.Participant in project Artemis by ls1intum.
the class ParticipantScoreIntegrationTest method getAverageScoreOfParticipantInExam_asInstructorOfCourse_shouldReturnAverageParticipantScores.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void getAverageScoreOfParticipantInExam_asInstructorOfCourse_shouldReturnAverageParticipantScores() throws Exception {
List<ParticipantScoreAverageDTO> participantScoreAverageDTOS = request.getList("/api/exams/" + idOfExam + "/participant-scores/average-participant", HttpStatus.OK, ParticipantScoreAverageDTO.class);
assertThat(participantScoreAverageDTOS).hasSize(1);
ParticipantScoreAverageDTO student1Result = participantScoreAverageDTOS.stream().filter(participantScoreAverageDTO -> participantScoreAverageDTO.userName != null).findFirst().get();
assertAverageParticipantScoreDTOStructure(student1Result, "student1", null, 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 ResultListenerIntegrationTest method verifyStructureOfParticipantScoreInDatabase.
private void verifyStructureOfParticipantScoreInDatabase(boolean isTeamTest, Long expectedLastResultId, Double expectedLastScore, Long expectedLastRatedResultId, Double expectedLastRatedScore) {
Long idOfExercise;
Participant participant;
if (isTeamTest) {
participant = teamRepository.findById(idOfTeam1).get();
idOfExercise = idOfTeamTextExercise;
} else {
participant = userRepository.findOneByLogin("student1").get();
idOfExercise = idOfIndividualTextExercise;
}
SecurityUtils.setAuthorizationObject();
List<ParticipantScore> savedParticipantScore = participantScoreRepository.findAllEagerly();
assertThat(savedParticipantScore).isNotEmpty();
assertThat(savedParticipantScore).hasSize(1);
ParticipantScore updatedParticipantScore = savedParticipantScore.get(0);
Double lastPoints = null;
Double lastRatedPoints = null;
if (expectedLastScore != null) {
lastPoints = round(expectedLastScore * 0.01 * 10.0);
}
if (expectedLastRatedScore != null) {
lastRatedPoints = round(expectedLastRatedScore * 0.01 * 10.0);
}
assertParticipantScoreStructure(updatedParticipantScore, idOfExercise, participant.getId(), expectedLastResultId, expectedLastScore, expectedLastRatedResultId, expectedLastRatedScore, lastPoints, lastRatedPoints);
verify(this.scoreService, times(2)).updateOrCreateParticipantScore(any(Result.class));
}
Aggregations