Search in sources :

Example 6 with GradingInstruction

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

the class ModelingExerciseImportService method copyModelingExerciseBasis.

/**
 * This helper method copies all attributes of the {@code importedExercise} into the new exercise.
 * Here we ignore all external entities as well as the start-, end-, and assessment due date.
 * Also fills {@code gradingInstructionCopyTracker}.
 *
 * @param importedExercise The exercise from which to copy the basis
 * @param gradingInstructionCopyTracker  The mapping from original GradingInstruction Ids to new GradingInstruction instances.
 * @return the cloned TextExercise basis
 */
@NotNull
private ModelingExercise copyModelingExerciseBasis(Exercise importedExercise, Map<Long, GradingInstruction> gradingInstructionCopyTracker) {
    log.debug("Copying the exercise basis from {}", importedExercise);
    ModelingExercise newExercise = new ModelingExercise();
    super.copyExerciseBasis(newExercise, importedExercise, gradingInstructionCopyTracker);
    newExercise.setDiagramType(((ModelingExercise) importedExercise).getDiagramType());
    newExercise.setExampleSolutionModel(((ModelingExercise) importedExercise).getExampleSolutionModel());
    newExercise.setExampleSolutionExplanation(((ModelingExercise) importedExercise).getExampleSolutionExplanation());
    return newExercise;
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) NotNull(javax.validation.constraints.NotNull)

Example 7 with GradingInstruction

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

the class ModelingExerciseIntegrationTest method testImportModelingExercise_setGradingInstructionForCopiedFeedback.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testImportModelingExercise_setGradingInstructionForCopiedFeedback() throws Exception {
    var now = ZonedDateTime.now();
    Course course1 = database.addEmptyCourse();
    Course course2 = database.addEmptyCourse();
    ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(now.minusDays(1), now.minusHours(2), now.minusHours(1), DiagramType.ClassDiagram, course1);
    modelingExercise = modelingExerciseRepository.save(modelingExercise);
    List<GradingCriterion> gradingCriteria = database.addGradingInstructionsToExercise(modelingExercise);
    gradingCriterionRepository.saveAll(gradingCriteria);
    GradingInstruction gradingInstruction = gradingCriteria.get(0).getStructuredGradingInstructions().get(0);
    assertThat(gradingInstruction.getFeedback()).as("Test feedback should have student readable feedback").isNotEmpty();
    // Create example submission
    var exampleSubmission = database.generateExampleSubmission("model", modelingExercise, true);
    exampleSubmission = database.addExampleSubmission(exampleSubmission);
    database.addResultToSubmission(exampleSubmission.getSubmission(), AssessmentType.MANUAL);
    var submission = submissionRepository.findWithEagerResultAndFeedbackById(exampleSubmission.getSubmission().getId()).get();
    Feedback feedback = ModelFactory.generateFeedback().get(0);
    feedback.setGradingInstruction(gradingInstruction);
    database.addFeedbackToResult(feedback, Objects.requireNonNull(submission.getLatestResult()));
    modelingExercise.setCourse(course2);
    var importedModelingExercise = request.postWithResponseBody("/api/modeling-exercises/import/" + modelingExercise.getId(), modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
    assertThat(modelingExerciseRepository.findById(importedModelingExercise.getId())).isPresent();
    var importedExampleSubmission = importedModelingExercise.getExampleSubmissions().stream().findFirst().get();
    GradingInstruction importedFeedbackGradingInstruction = importedExampleSubmission.getSubmission().getLatestResult().getFeedbacks().get(0).getGradingInstruction();
    assertThat(importedFeedbackGradingInstruction).isNotNull();
    // Copy and original should have the same data but not the same ids.
    assertThat(importedFeedbackGradingInstruction.getId()).isNotEqualTo(gradingInstruction.getId());
    // To avoid infinite recursion when serializing to JSON.
    assertThat(importedFeedbackGradingInstruction.getGradingCriterion()).isNull();
    assertThat(importedFeedbackGradingInstruction.getFeedback()).isEqualTo(gradingInstruction.getFeedback());
    assertThat(importedFeedbackGradingInstruction.getGradingScale()).isEqualTo(gradingInstruction.getGradingScale());
    assertThat(importedFeedbackGradingInstruction.getInstructionDescription()).isEqualTo(gradingInstruction.getInstructionDescription());
    assertThat(importedFeedbackGradingInstruction.getCredits()).isEqualTo(gradingInstruction.getCredits());
    assertThat(importedFeedbackGradingInstruction.getUsageCount()).isEqualTo(gradingInstruction.getUsageCount());
    var importedModelingExerciseFromDb = modelingExerciseRepository.findByIdWithExampleSubmissionsAndResults(importedModelingExercise.getId()).get();
    var importedFeedbackGradingInstructionFromDb = importedModelingExerciseFromDb.getExampleSubmissions().stream().findFirst().get().getSubmission().getLatestResult().getFeedbacks().get(0).getGradingInstruction();
    assertThat(importedFeedbackGradingInstructionFromDb.getGradingCriterion().getId()).isNotEqualTo(gradingInstruction.getGradingCriterion().getId());
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with GradingInstruction

use of de.tum.in.www1.artemis.domain.GradingInstruction in project ArTEMiS by ls1intum.

the class ModelingExerciseImportService method copyModelingExerciseBasis.

/**
 * This helper method copies all attributes of the {@code importedExercise} into the new exercise.
 * Here we ignore all external entities as well as the start-, end-, and assessment due date.
 * Also fills {@code gradingInstructionCopyTracker}.
 *
 * @param importedExercise The exercise from which to copy the basis
 * @param gradingInstructionCopyTracker  The mapping from original GradingInstruction Ids to new GradingInstruction instances.
 * @return the cloned TextExercise basis
 */
@NotNull
private ModelingExercise copyModelingExerciseBasis(Exercise importedExercise, Map<Long, GradingInstruction> gradingInstructionCopyTracker) {
    log.debug("Copying the exercise basis from {}", importedExercise);
    ModelingExercise newExercise = new ModelingExercise();
    super.copyExerciseBasis(newExercise, importedExercise, gradingInstructionCopyTracker);
    newExercise.setDiagramType(((ModelingExercise) importedExercise).getDiagramType());
    newExercise.setExampleSolutionModel(((ModelingExercise) importedExercise).getExampleSolutionModel());
    newExercise.setExampleSolutionExplanation(((ModelingExercise) importedExercise).getExampleSolutionExplanation());
    return newExercise;
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) NotNull(javax.validation.constraints.NotNull)

Example 9 with GradingInstruction

use of de.tum.in.www1.artemis.domain.GradingInstruction in project ArTEMiS by ls1intum.

the class ModelingExerciseImportService method copyExampleSubmission.

/**
 * This functions does a hard copy of the example submissions contained in {@code templateExercise}.
 * To copy the corresponding Submission entity this function calls {@link #copySubmission(Submission, Map)}
 *
 * @param templateExercise {TextExercise} The original exercise from which to fetch the example submissions
 * @param newExercise The new exercise in which we will insert the example submissions
 * @param gradingInstructionCopyTracker  The mapping from original GradingInstruction Ids to new GradingInstruction instances.
 * @return The cloned set of example submissions
 */
Set<ExampleSubmission> copyExampleSubmission(Exercise templateExercise, Exercise newExercise, Map<Long, GradingInstruction> gradingInstructionCopyTracker) {
    log.debug("Copying the ExampleSubmissions to new Exercise: {}", newExercise);
    Set<ExampleSubmission> newExampleSubmissions = new HashSet<>();
    for (ExampleSubmission originalExampleSubmission : templateExercise.getExampleSubmissions()) {
        ModelingSubmission originalSubmission = (ModelingSubmission) originalExampleSubmission.getSubmission();
        ModelingSubmission newSubmission = (ModelingSubmission) copySubmission(originalSubmission, gradingInstructionCopyTracker);
        ExampleSubmission newExampleSubmission = new ExampleSubmission();
        newExampleSubmission.setExercise(newExercise);
        newExampleSubmission.setSubmission(newSubmission);
        newExampleSubmission.setAssessmentExplanation(originalExampleSubmission.getAssessmentExplanation());
        exampleSubmissionRepository.save(newExampleSubmission);
        newExampleSubmissions.add(newExampleSubmission);
    }
    return newExampleSubmissions;
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) HashSet(java.util.HashSet)

Example 10 with GradingInstruction

use of de.tum.in.www1.artemis.domain.GradingInstruction in project ArTEMiS by ls1intum.

the class ModelingExerciseImportService method copySubmission.

/**
 * This helper function does a hard copy of the {@code originalSubmission} and stores the values in {@code newSubmission}.
 * To copy the submission results this function calls {@link ExerciseImportService#copyExampleResult(Result, Submission, Map)} respectively.
 *
 * @param originalSubmission  The original submission to be copied.
 * @param gradingInstructionCopyTracker  The mapping from original GradingInstruction Ids to new GradingInstruction instances.
 * @return The cloned submission
 */
Submission copySubmission(Submission originalSubmission, Map<Long, GradingInstruction> gradingInstructionCopyTracker) {
    ModelingSubmission newSubmission = new ModelingSubmission();
    if (originalSubmission != null) {
        log.debug("Copying the Submission to new ExampleSubmission: {}", newSubmission);
        newSubmission.setExampleSubmission(true);
        newSubmission.setSubmissionDate(originalSubmission.getSubmissionDate());
        newSubmission.setType(originalSubmission.getType());
        newSubmission.setParticipation(originalSubmission.getParticipation());
        newSubmission.setExplanationText(((ModelingSubmission) originalSubmission).getExplanationText());
        newSubmission.setModel(((ModelingSubmission) originalSubmission).getModel());
        newSubmission = submissionRepository.saveAndFlush(newSubmission);
        if (originalSubmission.getLatestResult() != null) {
            newSubmission.addResult(copyExampleResult(originalSubmission.getLatestResult(), newSubmission, gradingInstructionCopyTracker));
        }
        newSubmission = submissionRepository.saveAndFlush(newSubmission);
    }
    return newSubmission;
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)

Aggregations

ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)8 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)4 NotNull (javax.validation.constraints.NotNull)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 Feedback (de.tum.in.www1.artemis.domain.Feedback)2 GradingInstruction (de.tum.in.www1.artemis.domain.GradingInstruction)2 Result (de.tum.in.www1.artemis.domain.Result)2 FeedbackType (de.tum.in.www1.artemis.domain.enumeration.FeedbackType)2 ModelElement (de.tum.in.www1.artemis.domain.modeling.ModelElement)2 CompassConfiguration (de.tum.in.www1.artemis.service.compass.utils.CompassConfiguration)2 BigDecimal (java.math.BigDecimal)2 RoundingMode (java.math.RoundingMode)2 java.util (java.util)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2