use of de.tum.in.www1.artemis.domain.TextExercise in project Artemis by ls1intum.
the class DatabaseUtilService method addCourseExamWithReviewDatesExerciseGroupWithOneTextExercise.
public TextExercise addCourseExamWithReviewDatesExerciseGroupWithOneTextExercise() {
ExerciseGroup exerciseGroup = addExerciseGroupWithExamWithReviewDatesAndCourse(true);
TextExercise textExercise = ModelFactory.generateTextExerciseForExam(exerciseGroup);
final var exercisesNrBefore = exerciseRepo.count();
exerciseRepo.save(textExercise);
assertThat(exercisesNrBefore + 1).as("one exercise got stored").isEqualTo(exerciseRepo.count());
return textExercise;
}
use of de.tum.in.www1.artemis.domain.TextExercise in project Artemis by ls1intum.
the class DatabaseUtilService method addCourseWithModelingAndTextExercise.
public Course addCourseWithModelingAndTextExercise() {
Course course = ModelFactory.generateCourse(null, pastTimestamp, futureFutureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, DiagramType.ClassDiagram, course);
modelingExercise.setTitle("Modeling");
course.addExercises(modelingExercise);
TextExercise textExercise = ModelFactory.generateTextExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, course);
textExercise.setTitle("Text");
course.addExercises(textExercise);
course = courseRepo.save(course);
exerciseRepo.save(modelingExercise);
exerciseRepo.save(textExercise);
return course;
}
use of de.tum.in.www1.artemis.domain.TextExercise in project Artemis by ls1intum.
the class DatabaseUtilService method createSubmissionAndResult.
public Result createSubmissionAndResult(StudentParticipation studentParticipation, long scoreAwarded, boolean rated) {
Exercise exercise = studentParticipation.getExercise();
Submission submission;
if (exercise instanceof ProgrammingExercise) {
submission = new ProgrammingSubmission();
} else if (exercise instanceof ModelingExercise) {
submission = new ModelingSubmission();
} else if (exercise instanceof TextExercise) {
submission = new TextSubmission();
} else if (exercise instanceof FileUploadExercise) {
submission = new FileUploadSubmission();
} else if (exercise instanceof QuizExercise) {
submission = new QuizSubmission();
} else {
throw new RuntimeException("Unsupported exercise type: " + exercise);
}
submission.setType(SubmissionType.MANUAL);
submission.setParticipation(studentParticipation);
submission = submissionRepository.saveAndFlush(submission);
Result result = ModelFactory.generateResult(rated, scoreAwarded);
result.setParticipation(studentParticipation);
result.setSubmission(submission);
result.completionDate(ZonedDateTime.now());
submission.addResult(result);
submission = submissionRepository.saveAndFlush(submission);
return submission.getResults().get(0);
}
use of de.tum.in.www1.artemis.domain.TextExercise in project Artemis by ls1intum.
the class DatabaseUtilService method addCourseWithOneExerciseAndSubmissions.
/**
* Generates a course with one specific exercise, and an arbitrare amount of submissions.
*
* @param exerciseType - the type of exercise which should be generated: modeling, programming, file-pload or text
* @param numberOfSubmissions - the amount of submissions which should be generated for an exercise
* @param modelForModelingExercise - the model string for a modeling exercise
* @return a course with an exercise with submissions
*/
public Course addCourseWithOneExerciseAndSubmissions(String exerciseType, int numberOfSubmissions, Optional<String> modelForModelingExercise) {
Course course;
Exercise exercise;
switch(exerciseType) {
case "modeling":
course = addCourseWithOneModelingExercise();
exercise = exerciseRepo.findAllExercisesByCourseId(course.getId()).iterator().next();
for (int j = 1; j <= numberOfSubmissions; j++) {
StudentParticipation participation = createAndSaveParticipationForExercise(exercise, "student" + j);
assertThat(modelForModelingExercise).isNotEmpty();
ModelingSubmission submission = ModelFactory.generateModelingSubmission(modelForModelingExercise.get(), true);
modelSubmissionService.save(submission, (ModelingExercise) exercise, "student" + j);
studentParticipationRepo.save(participation);
}
return course;
case "programming":
course = addCourseWithOneProgrammingExercise();
exercise = exerciseRepo.findAllExercisesByCourseId(course.getId()).iterator().next();
for (int j = 1; j <= numberOfSubmissions; j++) {
ProgrammingSubmission submission = new ProgrammingSubmission();
addProgrammingSubmission((ProgrammingExercise) exercise, submission, "student" + j);
}
return course;
case "text":
course = addCourseWithOneFinishedTextExercise();
exercise = exerciseRepo.findAllExercisesByCourseId(course.getId()).iterator().next();
for (int j = 1; j <= numberOfSubmissions; j++) {
TextSubmission textSubmission = ModelFactory.generateTextSubmission("Text" + j + j, null, true);
saveTextSubmission((TextExercise) exercise, textSubmission, "student" + j);
}
return course;
case "file-upload":
course = addCourseWithFileUploadExercise();
exercise = exerciseRepo.findAllExercisesByCourseId(course.getId()).iterator().next();
for (int j = 1; j <= numberOfSubmissions; j++) {
FileUploadSubmission submission = ModelFactory.generateFileUploadSubmissionWithFile(true, "path/to/file.pdf");
saveFileUploadSubmission((FileUploadExercise) exercise, submission, "student" + j);
}
return course;
default:
return null;
}
}
use of de.tum.in.www1.artemis.domain.TextExercise in project Artemis by ls1intum.
the class DatabaseUtilService method saveTextSubmissionWithResultAndAssessor.
private TextSubmission saveTextSubmissionWithResultAndAssessor(TextExercise exercise, TextSubmission submission, String studentLogin, Long teamId, String assessorLogin) {
StudentParticipation participation = Optional.ofNullable(studentLogin).map(login -> createAndSaveParticipationForExercise(exercise, login)).orElseGet(() -> addTeamParticipationForExercise(exercise, teamId));
submissionRepository.save(submission);
participation.addSubmission(submission);
Result result = new Result();
result.setAssessor(getUserByLogin(assessorLogin));
result.setScore(100D);
if (exercise.getReleaseDate() != null) {
result.setCompletionDate(exercise.getReleaseDate());
} else {
// exam exercises do not have a release date
result.setCompletionDate(ZonedDateTime.now());
}
result = resultRepo.save(result);
result.setSubmission(submission);
submission.setParticipation(participation);
submission.addResult(result);
submission.getParticipation().addResult(result);
submission = textSubmissionRepo.save(submission);
resultRepo.save(result);
studentParticipationRepo.save(participation);
submission = textSubmissionRepo.save(submission);
return submission;
}
Aggregations