use of de.tum.in.www1.artemis.domain.TextSubmission in project Artemis by ls1intum.
the class DatabaseUtilService method addCourseWithExercisesAndSubmissions.
/**
* With this method we can generate a course. We can specify the number of exercises. To not only test one type, this method generates modeling, file-upload and text
* exercises in a cyclic manner.
*
* @param numberOfExercises number of generated exercises. E.g. if you set it to 4, 2 modeling exercises, one text and one file-upload exercise will be generated.
* (thats why there is the %3 check)
* @param numberOfSubmissionPerExercise for each exercise this number of submissions will be generated. E.g. if you have 2 exercises, and set this to 4, in total 8
* submissions will be created.
* @param numberOfAssessments generates the assessments for a submission of an exercise. Example from abobe, 2 exrecises, 4 submissions each. If you set
* numberOfAssessments to 2, for each exercise 2 assessmetns will be created. In total there will be 4 assessments then. (by two
* different tutors, as each exercise is assessed by an individual tutor. There are 4 tutors that create assessments)
* @param numberOfComplaints generates the complaints for assessments, in the same way as results are created.
* @param typeComplaint true: complaintType==COMPLAINT | false: complaintType==MORE_FEEDBACK
* @param numberComplaintResponses generates responses for the complaint/feedback request (as above)
* @param validModel model for the modeling submission
* @return - the generated course
*/
public Course addCourseWithExercisesAndSubmissions(int numberOfExercises, int numberOfSubmissionPerExercise, int numberOfAssessments, int numberOfComplaints, boolean typeComplaint, int numberComplaintResponses, String validModel) {
Course course = ModelFactory.generateCourse(null, pastTimestamp, futureFutureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
var tutors = userRepo.getTutors(course);
for (int i = 0; i < numberOfExercises; i++) {
var currentUser = tutors.get(i % 4);
if ((i % 3) == 0) {
ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(pastTimestamp, pastTimestamp.plusHours(1), futureTimestamp, DiagramType.ClassDiagram, course);
modelingExercise.setTitle("Modeling" + i);
course.addExercises(modelingExercise);
course = courseRepo.save(course);
exerciseRepo.save(modelingExercise);
for (int j = 1; j <= numberOfSubmissionPerExercise; j++) {
StudentParticipation participation = createAndSaveParticipationForExercise(modelingExercise, "student" + j);
ModelingSubmission submission = ModelFactory.generateModelingSubmission(validModel, true);
modelSubmissionService.save(submission, modelingExercise, "student" + j);
studentParticipationRepo.save(participation);
if (numberOfAssessments >= j) {
Result result = generateResult(submission, currentUser);
submission.addResult(result);
participation.addResult(result);
studentParticipationRepo.save(participation);
modelingSubmissionRepo.save(submission);
generateComplaintAndResponses(j, numberOfComplaints, numberComplaintResponses, typeComplaint, result, currentUser);
}
}
} else if ((i % 3) == 1) {
TextExercise textExercise = ModelFactory.generateTextExercise(pastTimestamp, pastTimestamp.plusHours(1), futureTimestamp, course);
textExercise.setTitle("Text" + i);
course.addExercises(textExercise);
course = courseRepo.save(course);
exerciseRepo.save(textExercise);
for (int j = 1; j <= numberOfSubmissionPerExercise; j++) {
TextSubmission submission = ModelFactory.generateTextSubmission("submissionText", Language.ENGLISH, true);
submission = saveTextSubmission(textExercise, submission, "student" + j);
if (numberOfAssessments >= j) {
Result result = generateResult(submission, currentUser);
submission.addResult(result);
saveResultInParticipation(submission, result);
textSubmissionRepo.save(submission);
generateComplaintAndResponses(j, numberOfComplaints, numberComplaintResponses, typeComplaint, result, currentUser);
}
}
} else if ((i % 3) == 2) {
FileUploadExercise fileUploadExercise = ModelFactory.generateFileUploadExercise(pastTimestamp, pastTimestamp.plusHours(1), futureTimestamp, "png,pdf", course);
fileUploadExercise.setTitle("FileUpload" + i);
course.addExercises(fileUploadExercise);
course = courseRepo.save(course);
exerciseRepo.save(fileUploadExercise);
for (int j = 1; j <= numberOfSubmissionPerExercise; j++) {
FileUploadSubmission submission = ModelFactory.generateFileUploadSubmissionWithFile(true, "path/to/file.pdf");
saveFileUploadSubmission(fileUploadExercise, submission, "student" + j);
if (numberOfAssessments >= j) {
Result result = generateResult(submission, currentUser);
saveResultInParticipation(submission, result);
fileUploadSubmissionRepo.save(submission);
generateComplaintAndResponses(j, numberOfComplaints, numberComplaintResponses, typeComplaint, result, currentUser);
}
}
}
}
course = courseRepo.save(course);
return course;
}
use of de.tum.in.www1.artemis.domain.TextSubmission 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.TextSubmission 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.TextSubmission 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;
}
use of de.tum.in.www1.artemis.domain.TextSubmission in project Artemis by ls1intum.
the class DatabaseUtilService method createCourseWithTestModelingAndFileUploadExercisesAndSubmissions.
public Course createCourseWithTestModelingAndFileUploadExercisesAndSubmissions() throws Exception {
Course course = addCourseWithModelingAndTextAndFileUploadExercise();
course.setEndDate(ZonedDateTime.now().minusMinutes(5));
course = courseRepo.save(course);
var fileUploadExercise = findFileUploadExerciseWithTitle(course.getExercises(), "FileUpload");
createFileUploadSubmissionWithFile(fileUploadExercise, "uploaded-file.png");
var textExercise = findTextExerciseWithTitle(course.getExercises(), "Text");
var textSubmission = ModelFactory.generateTextSubmission("example text", Language.ENGLISH, true);
saveTextSubmission(textExercise, textSubmission, "student1");
var modelingExercise = findModelingExerciseWithTitle(course.getExercises(), "Modeling");
createAndSaveParticipationForExercise(modelingExercise, "student1");
String emptyActivityModel = FileUtils.loadFileFromResources("test-data/model-submission/empty-activity-diagram.json");
ModelingSubmission submission = ModelFactory.generateModelingSubmission(emptyActivityModel, true);
addSubmission(modelingExercise, submission, "student1");
return course;
}
Aggregations