Search in sources :

Example 31 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 32 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 33 with Participant

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);
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) QuizSubmission(de.tum.in.www1.artemis.domain.quiz.QuizSubmission) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) QuizSubmission(de.tum.in.www1.artemis.domain.quiz.QuizSubmission) QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise)

Example 34 with Participant

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);
}
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 35 with Participant

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));
}
Also used : Participant(de.tum.in.www1.artemis.domain.participation.Participant) ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore)

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