Search in sources :

Example 81 with StudentParticipation

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

the class CompassService method getAutomaticResultForSubmission.

/**
 * Get the result of the given modeling submission. If the given submission already contains a manual result, this result is returned. Otherwise, it tries to load and return
 * the result for the submission from the hash map containing all automatic results. If no result could be found in the hash map, a new result is created for the given
 * submission.
 *
 * @param modelingSubmission the submission for which the result should be obtained
 * @return the result of the given submission either obtained from the submission or the semi-automatic result map, or a newly created one if it does not exist already
 */
private Result getAutomaticResultForSubmission(ModelingSubmission modelingSubmission) {
    Result result = modelingSubmission.getLatestResult();
    if (result == null || AssessmentType.MANUAL != result.getAssessmentType()) {
        if (result == null) {
            StudentParticipation studentParticipation = (StudentParticipation) modelingSubmission.getParticipation();
            result = new Result().submission(modelingSubmission).participation(studentParticipation);
        }
        return result;
    }
    return null;
}
Also used : StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) Result(de.tum.in.www1.artemis.domain.Result)

Example 82 with StudentParticipation

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

the class QuizSubmissionService method saveSubmissionForExamMode.

/**
 * Updates a submission for the exam mode
 *
 * @param quizExercise      the quiz exercise for which the submission for the exam mode should be done
 * @param quizSubmission    the quiz submission includes the submitted answers by the student
 * @param user              the student who wants to submit the quiz during the exam
 * @return                  the updated quiz submission after it has been saved to the database
 */
public QuizSubmission saveSubmissionForExamMode(QuizExercise quizExercise, QuizSubmission quizSubmission, String user) {
    // update submission properties
    quizSubmission.setSubmitted(true);
    quizSubmission.setType(SubmissionType.MANUAL);
    quizSubmission.setSubmissionDate(ZonedDateTime.now());
    Optional<StudentParticipation> optionalParticipation = participationService.findOneByExerciseAndStudentLoginAnyState(quizExercise, user);
    if (optionalParticipation.isEmpty()) {
        log.warn("The participation for quiz exercise {}, quiz submission {} and user {} was not found", quizExercise.getId(), quizSubmission.getId(), user);
        // TODO: think of better way to handle failure
        throw new EntityNotFoundException("Participation for quiz exercise " + quizExercise.getId() + " and quiz submission " + quizSubmission.getId() + " for user " + user + " was not found!");
    }
    StudentParticipation studentParticipation = optionalParticipation.get();
    quizSubmission.setParticipation(studentParticipation);
    // remove result from submission (in the unlikely case it is passed here), so that students cannot inject a result
    quizSubmission.setResults(new ArrayList<>());
    quizSubmissionRepository.save(quizSubmission);
    // versioning of submission
    try {
        submissionVersionService.saveVersionForIndividual(quizSubmission, user);
    } catch (Exception ex) {
        log.error("Quiz submission version could not be saved", ex);
    }
    log.debug("submit exam quiz finished: {}", quizSubmission);
    return quizSubmission;
}
Also used : EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) QuizSubmissionException(de.tum.in.www1.artemis.exception.QuizSubmissionException) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)

Example 83 with StudentParticipation

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

the class ScoreService method createNewStudentScore.

private void createNewStudentScore(Result newResult, StudentParticipation studentParticipation, Exercise exercise) {
    StudentScore newStudentScore = new StudentScore();
    newStudentScore.setExercise(exercise);
    newStudentScore.setUser(studentParticipation.getStudent().get());
    setLastAttributes(newStudentScore, newResult, exercise);
    if (newResult.isRated() != null && newResult.isRated()) {
        setLastRatedAttributes(newStudentScore, newResult, exercise);
    }
    StudentScore studentScore = studentScoreRepository.saveAndFlush(newStudentScore);
    logger.info("Saved a new student score: " + studentScore);
}
Also used : StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore)

Example 84 with StudentParticipation

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

the class ScoreService method updateOrCreateParticipantScore.

/**
 * Either updates an existing participant score or creates a new participant score if a new result comes in
 * The annotation "@Transactional" is ok because it means that this method does not support run in an outer transactional context, instead the outer transaction is paused
 *
 * @param createdOrUpdatedResult newly created or updated result
 */
// ok (see JavaDoc)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void updateOrCreateParticipantScore(Result createdOrUpdatedResult) {
    if (createdOrUpdatedResult.getScore() == null || createdOrUpdatedResult.getCompletionDate() == null) {
        return;
    }
    // There is a deadlock problem with programming exercises here if we use the participation from the result (reason unknown at the moment)
    // therefore we get the participation from the database
    Optional<StudentParticipation> studentParticipationOptional = getStudentParticipationForResult(createdOrUpdatedResult);
    if (studentParticipationOptional.isEmpty()) {
        return;
    }
    StudentParticipation studentParticipation = studentParticipationOptional.get();
    // we ignore test runs of exams
    if (studentParticipation.isTestRun()) {
        return;
    }
    Exercise exercise = studentParticipation.getExercise();
    ParticipantScore existingParticipationScoreForExerciseAndParticipant = getExistingParticipationScore(studentParticipation, exercise);
    // there already exists a participant score -> we need to update it
    if (existingParticipationScoreForExerciseAndParticipant != null) {
        updateExistingParticipantScore(existingParticipationScoreForExerciseAndParticipant, createdOrUpdatedResult, exercise);
    } else {
        // there does not already exist a participant score -> we need to create it
        createNewParticipantScore(createdOrUpdatedResult, studentParticipation, exercise);
    }
}
Also used : ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 85 with StudentParticipation

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

the class ScoreService method getExistingParticipationScore.

/**
 * Gets the existing participation score for an exercise and a participant or null if none can be found
 *
 * @param studentParticipation participation containing the information about the participant
 * @param exercise             exercise for which to find the participation score of the participant
 * @return existing participation score or null if none can be found
 */
private ParticipantScore getExistingParticipationScore(StudentParticipation studentParticipation, Exercise exercise) {
    ParticipantScore existingParticipationScoreForExerciseAndParticipant = null;
    if (exercise.isTeamMode()) {
        Team team = studentParticipation.getTeam().get();
        Optional<TeamScore> teamScoreOptional = teamScoreRepository.findTeamScoreByExerciseAndTeam(exercise, team);
        if (teamScoreOptional.isPresent()) {
            existingParticipationScoreForExerciseAndParticipant = teamScoreOptional.get();
        }
    } else {
        User user = studentParticipation.getStudent().get();
        Optional<StudentScore> studentScoreOptional = studentScoreRepository.findStudentScoreByExerciseAndUser(exercise, user);
        if (studentScoreOptional.isPresent()) {
            existingParticipationScoreForExerciseAndParticipant = studentScoreOptional.get();
        }
    }
    return existingParticipationScoreForExerciseAndParticipant;
}
Also used : ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) 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)219 Test (org.junit.jupiter.api.Test)118 WithMockUser (org.springframework.security.test.context.support.WithMockUser)112 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)60 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)50 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)48 ZonedDateTime (java.time.ZonedDateTime)44 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)42 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)40 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)36 Exam (de.tum.in.www1.artemis.domain.exam.Exam)30 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)30 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)28 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)28 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)26 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)24 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)24 Participation (de.tum.in.www1.artemis.domain.participation.Participation)24 Collectors (java.util.stream.Collectors)24