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