Search in sources :

Example 16 with ModelingSubmission

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

Example 17 with 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;
}
Also used : Result(de.tum.in.www1.artemis.domain.Result)

Example 18 with 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;
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)

Example 19 with 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;
}
Also used : Submission(de.tum.in.www1.artemis.domain.Submission) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ZonedDateTime(java.time.ZonedDateTime) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) ResponseStatusException(org.springframework.web.server.ResponseStatusException) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ResponseStatusException(org.springframework.web.server.ResponseStatusException) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)

Example 20 with 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);
}
Also used : HashMap(java.util.HashMap) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise)

Aggregations

ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)160 Test (org.junit.jupiter.api.Test)108 WithMockUser (org.springframework.security.test.context.support.WithMockUser)106 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)36 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)16 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)16 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)12 JsonParser.parseString (com.google.gson.JsonParser.parseString)8 ModelCluster (de.tum.in.www1.artemis.domain.modeling.ModelCluster)8 ModelingSubmission (de.tum.in.www1.artemis.domain.ModelingSubmission)6 Result (de.tum.in.www1.artemis.domain.Result)6 ModelElement (de.tum.in.www1.artemis.domain.modeling.ModelElement)6 ModelClusterFactory (de.tum.in.www1.artemis.service.compass.controller.ModelClusterFactory)6 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)4 ExerciseHint (de.tum.in.www1.artemis.domain.hestia.ExerciseHint)4 Participation (de.tum.in.www1.artemis.domain.participation.Participation)4 PlagiarismComparison (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison)4 PlagiarismSubmission (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission)4