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