Search in sources :

Example 11 with GradingInstruction

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

the class ModelingExerciseImportService method importModelingExercise.

/**
 * Imports a modeling exercise creating a new entity, copying all basic values and saving it in the database.
 * All basic include everything except Student-, Tutor participations, and student questions. <br>
 * This method calls {@link #copyModelingExerciseBasis(Exercise, Map<Long, GradingInstruction>)} to set up the basis of the exercise
 * {@link #copyExampleSubmission(Exercise, Exercise)} for a hard copy of the example submissions.
 *
 * @param templateExercise The template exercise which should get imported
 * @param importedExercise The new exercise already containing values which should not get copied, i.e. overwritten
 * @return The newly created exercise
 */
@NotNull
public ModelingExercise importModelingExercise(ModelingExercise templateExercise, ModelingExercise importedExercise) {
    log.debug("Creating a new Exercise based on exercise {}", templateExercise.getId());
    Map<Long, GradingInstruction> gradingInstructionCopyTracker = new HashMap<>();
    ModelingExercise newExercise = copyModelingExerciseBasis(importedExercise, gradingInstructionCopyTracker);
    newExercise.setKnowledge(templateExercise.getKnowledge());
    modelingExerciseRepository.save(newExercise);
    newExercise.setExampleSubmissions(copyExampleSubmission(templateExercise, newExercise, gradingInstructionCopyTracker));
    return newExercise;
}
Also used : HashMap(java.util.HashMap) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) NotNull(javax.validation.constraints.NotNull)

Example 12 with GradingInstruction

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

the class ModelingExerciseImportService method importModelingExercise.

/**
 * Imports a modeling exercise creating a new entity, copying all basic values and saving it in the database.
 * All basic include everything except Student-, Tutor participations, and student questions. <br>
 * This method calls {@link #copyModelingExerciseBasis(Exercise, Map<Long, GradingInstruction>)} to set up the basis of the exercise
 * {@link #copyExampleSubmission(Exercise, Exercise)} for a hard copy of the example submissions.
 *
 * @param templateExercise The template exercise which should get imported
 * @param importedExercise The new exercise already containing values which should not get copied, i.e. overwritten
 * @return The newly created exercise
 */
@NotNull
public ModelingExercise importModelingExercise(ModelingExercise templateExercise, ModelingExercise importedExercise) {
    log.debug("Creating a new Exercise based on exercise {}", templateExercise.getId());
    Map<Long, GradingInstruction> gradingInstructionCopyTracker = new HashMap<>();
    ModelingExercise newExercise = copyModelingExerciseBasis(importedExercise, gradingInstructionCopyTracker);
    newExercise.setKnowledge(templateExercise.getKnowledge());
    modelingExerciseRepository.save(newExercise);
    newExercise.setExampleSubmissions(copyExampleSubmission(templateExercise, newExercise, gradingInstructionCopyTracker));
    return newExercise;
}
Also used : HashMap(java.util.HashMap) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) NotNull(javax.validation.constraints.NotNull)

Example 13 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 14 with GradingInstruction

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

the class ModelingExerciseIntegrationTest method testUpdateModelingExerciseInstructions_asInstructor.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testUpdateModelingExerciseInstructions_asInstructor() throws Exception {
    ModelingExercise modelingExercise = modelingExerciseUtilService.createModelingExercise(classExercise.getCourseViaExerciseGroupOrCourseMember().getId());
    gradingCriteria = database.addGradingInstructionsToExercise(modelingExercise);
    var currentInstructionsSize = modelingExercise.getGradingCriteria().get(1).getStructuredGradingInstructions().size();
    var newInstruction = new GradingInstruction();
    newInstruction.setInstructionDescription("New Instruction");
    modelingExercise.getGradingCriteria().get(1).addStructuredGradingInstructions(newInstruction);
    ModelingExercise createdModelingExercise = request.postWithResponseBody("/api/modeling-exercises", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
    assertThat(createdModelingExercise.getGradingCriteria().get(1).getStructuredGradingInstructions()).hasSize(currentInstructionsSize + 1);
    modelingExercise.getGradingCriteria().get(1).getStructuredGradingInstructions().get(0).setInstructionDescription("UPDATE");
    createdModelingExercise = request.postWithResponseBody("/api/modeling-exercises", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
    assertThat(createdModelingExercise.getGradingCriteria().get(1).getStructuredGradingInstructions().get(0).getInstructionDescription()).isEqualTo("UPDATE");
    modelingExercise.getGradingCriteria().get(1).setStructuredGradingInstructions(null);
    createdModelingExercise = request.postWithResponseBody("/api/modeling-exercises", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
    assertThat(createdModelingExercise.getGradingCriteria()).isNotEmpty();
    assertThat(createdModelingExercise.getGradingCriteria().get(1).getStructuredGradingInstructions()).isNullOrEmpty();
}
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)

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