use of de.tum.in.www1.artemis.domain.modeling.ModelingSubmission in project ArTEMiS by ls1intum.
the class ModelingSubmissionService method lockAndGetModelingSubmission.
/**
* Get the modeling submission with the given ID from the database and lock the submission to prevent other tutors from receiving and assessing it.
* Additionally, check if the submission lock limit has been reached.
*
* In case Compass is supported (and activated), this method also assigns a result with feedback suggestions to the submission
*
* @param submissionId the id of the modeling submission
* @param modelingExercise the corresponding exercise
* @param correctionRound the correction round for which we want the lock
* @return the locked modeling submission
*/
public ModelingSubmission lockAndGetModelingSubmission(Long submissionId, ModelingExercise modelingExercise, int correctionRound) {
ModelingSubmission modelingSubmission = modelingSubmissionRepository.findByIdWithEagerResultAndFeedbackAndAssessorAndParticipationResultsElseThrow(submissionId);
if (modelingSubmission.getLatestResult() == null || modelingSubmission.getLatestResult().getAssessor() == null) {
checkSubmissionLockLimit(modelingExercise.getCourseViaExerciseGroupOrCourseMember().getId());
if (compassService.isSupported(modelingExercise) && correctionRound == 0L) {
modelingSubmission = assignResultWithFeedbackSuggestionsToSubmission(modelingSubmission, modelingExercise);
}
}
lockSubmission(modelingSubmission, correctionRound);
return modelingSubmission;
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingSubmission in project ArTEMiS by ls1intum.
the class ModelingSubmissionService method assignResultWithFeedbackSuggestionsToSubmission.
/**
* Assigns an automatic result generated by Compass to the given modeling submission and saves the updated submission to the database. If the given submission already contains
* a manual result, it will not get updated with the automatic result.
*
* @param modelingSubmission the modeling submission that should be updated with an automatic result generated by Compass
* @param modelingExercise the modeling exercise to which the submission belongs
* @return the updated modeling submission
*/
private ModelingSubmission assignResultWithFeedbackSuggestionsToSubmission(ModelingSubmission modelingSubmission, ModelingExercise modelingExercise) {
var existingResult = modelingSubmission.getLatestResult();
if (existingResult != null && existingResult.getAssessmentType() != null && existingResult.getAssessmentType() == AssessmentType.MANUAL) {
return modelingSubmission;
}
Result automaticResult = compassService.getSuggestionResult(modelingSubmission, modelingExercise);
if (automaticResult != null) {
automaticResult.setSubmission(null);
automaticResult.setParticipation(modelingSubmission.getParticipation());
automaticResult = resultRepository.save(automaticResult);
automaticResult.setSubmission(modelingSubmission);
modelingSubmission.addResult(automaticResult);
modelingSubmission = modelingSubmissionRepository.save(modelingSubmission);
}
return modelingSubmission;
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingSubmission in project ArTEMiS by ls1intum.
the class ModelingSubmissionService method findRandomSubmissionWithoutExistingAssessment.
/**
* retrieves a modeling submission without assessment for the specified correction round and potentially locks the submission
*
* In case Compass is supported (and activated), this method also assigns a result with feedback suggestions to the submission
*
* @param lockSubmission whether the submission should be locked
* @param correctionRound the correction round (0 = first correction, 1 = second correction
* @param modelingExercise the modeling exercise for which a
* @param isExamMode whether the exercise belongs to an exam
* @return a random modeling submission (potentially based on compass)
*/
public ModelingSubmission findRandomSubmissionWithoutExistingAssessment(boolean lockSubmission, int correctionRound, ModelingExercise modelingExercise, boolean isExamMode) {
var submissionWithoutResult = super.getRandomSubmissionEligibleForNewAssessment(modelingExercise, isExamMode, correctionRound).orElseThrow(() -> new EntityNotFoundException("Modeling submission for exercise " + modelingExercise.getId() + " could not be found"));
ModelingSubmission modelingSubmission = (ModelingSubmission) submissionWithoutResult;
if (lockSubmission) {
if (compassService.isSupported(modelingExercise) && correctionRound == 0L) {
modelingSubmission = assignResultWithFeedbackSuggestionsToSubmission(modelingSubmission, modelingExercise);
setNumberOfAffectedSubmissionsPerElement(modelingSubmission);
}
lockSubmission(modelingSubmission, correctionRound);
}
return modelingSubmission;
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingSubmission in project ArTEMiS by ls1intum.
the class ModelingSubmissionService method save.
/**
* Saves the given submission and the corresponding model and creates the result if necessary. This method used for creating and updating modeling submissions.
*
* @param modelingSubmission the submission that should be saved
* @param modelingExercise the exercise the submission belongs to
* @param username the name of the corresponding user
* @return the saved modelingSubmission entity
*/
public ModelingSubmission save(ModelingSubmission modelingSubmission, ModelingExercise modelingExercise, String username) {
Optional<StudentParticipation> optionalParticipation = participationService.findOneByExerciseAndStudentLoginWithEagerSubmissionsAnyState(modelingExercise, username);
if (optionalParticipation.isEmpty()) {
throw new EntityNotFoundException("No participation found for " + username + " in exercise with id " + modelingExercise.getId());
}
StudentParticipation participation = optionalParticipation.get();
final Optional<ZonedDateTime> dueDate = exerciseDateService.getDueDate(participation);
if (dueDate.isPresent() && exerciseDateService.isAfterDueDate(participation) && participation.getInitializationDate().isBefore(dueDate.get())) {
throw new ResponseStatusException(HttpStatus.FORBIDDEN);
}
// remove result from submission (in the unlikely case it is passed here), so that students cannot inject a result
modelingSubmission.setResults(new ArrayList<>());
// NOTE: from now on we always set submitted to true to prevent problems here! Except for late submissions of course exercises to prevent issues in auto-save
if (modelingExercise.isExamExercise() || exerciseDateService.isBeforeDueDate(participation)) {
modelingSubmission.setSubmitted(true);
}
modelingSubmission.setSubmissionDate(ZonedDateTime.now());
modelingSubmission.setType(SubmissionType.MANUAL);
modelingSubmission.setParticipation(participation);
modelingSubmission = modelingSubmissionRepository.save(modelingSubmission);
// versioning of submission
try {
if (modelingExercise.isTeamMode()) {
submissionVersionService.saveVersionForTeam(modelingSubmission, username);
} else if (modelingExercise.isExamExercise()) {
submissionVersionService.saveVersionForIndividual(modelingSubmission, username);
}
} catch (Exception ex) {
log.error("Modeling submission version could not be saved", ex);
}
participation.addSubmission(modelingSubmission);
participation.setInitializationState(InitializationState.FINISHED);
StudentParticipation savedParticipation = studentParticipationRepository.save(participation);
if (modelingSubmission.getId() == null) {
Optional<Submission> optionalSubmission = savedParticipation.findLatestSubmission();
if (optionalSubmission.isPresent()) {
modelingSubmission = (ModelingSubmission) optionalSubmission.get();
}
}
log.debug("return model: {}", modelingSubmission.getModel());
return modelingSubmission;
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingSubmission in project ArTEMiS by ls1intum.
the class ExampleSubmissionService method importStudentSubmissionAsExampleSubmission.
/**
* Creates new example submission by copying the student submission with its assessments
* calls copySubmission of required service depending on type of exercise
*
* @param submissionId The original student submission id to be copied
* @param exercise The exercise to which the example submission belongs
* @return the exampleSubmission entity
*/
public ExampleSubmission importStudentSubmissionAsExampleSubmission(Long submissionId, Exercise exercise) {
ExampleSubmission newExampleSubmission = new ExampleSubmission();
newExampleSubmission.setExercise(exercise);
if (exercise instanceof ModelingExercise) {
ModelingSubmission modelingSubmission = (ModelingSubmission) submissionRepository.findOneWithEagerResultAndFeedback(submissionId);
checkGivenExerciseIdSameForSubmissionParticipation(exercise.getId(), modelingSubmission.getParticipation().getExercise().getId());
// example submission does not need participation
modelingSubmission.setParticipation(null);
newExampleSubmission.setSubmission(modelingExerciseImportService.copySubmission(modelingSubmission, new HashMap<>()));
}
if (exercise instanceof TextExercise) {
TextSubmission textSubmission = textSubmissionRepository.findByIdWithEagerResultsAndFeedbackAndTextBlocksElseThrow(submissionId);
checkGivenExerciseIdSameForSubmissionParticipation(exercise.getId(), textSubmission.getParticipation().getExercise().getId());
// example submission does not need participation
textSubmission.setParticipation(null);
newExampleSubmission.setSubmission(textExerciseImportService.copySubmission(textSubmission));
}
return exampleSubmissionRepository.save(newExampleSubmission);
}
Aggregations