use of de.tum.in.www1.artemis.domain.FileUploadSubmission 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.FileUploadSubmission 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.FileUploadSubmission 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.FileUploadSubmission in project Artemis by ls1intum.
the class DatabaseUtilService method createCourseWithAllExerciseTypesAndParticipationsAndSubmissionsAndResults.
public Course createCourseWithAllExerciseTypesAndParticipationsAndSubmissionsAndResults(boolean hasAssessmentDueDatePassed) {
Course course = ModelFactory.generateCourse(null, pastTimestamp, futureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, DiagramType.ClassDiagram, course);
TextExercise textExercise = ModelFactory.generateTextExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, course);
FileUploadExercise fileUploadExercise = ModelFactory.generateFileUploadExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, "png", course);
ProgrammingExercise programmingExercise = ModelFactory.generateProgrammingExercise(pastTimestamp, futureTimestamp, course);
QuizExercise quizExercise = ModelFactory.generateQuizExercise(pastTimestamp, futureTimestamp, course);
// Set assessment due dates
if (hasAssessmentDueDatePassed) {
modelingExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
textExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
fileUploadExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
programmingExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
quizExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
} else {
modelingExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
textExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
fileUploadExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
programmingExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
quizExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
}
// Add exercises to course
course.addExercises(modelingExercise);
course.addExercises(textExercise);
course.addExercises(fileUploadExercise);
course.addExercises(programmingExercise);
course.addExercises(quizExercise);
// Save course and exercises to database
Course courseSaved = courseRepo.save(course);
modelingExercise = exerciseRepo.save(modelingExercise);
textExercise = exerciseRepo.save(textExercise);
fileUploadExercise = exerciseRepo.save(fileUploadExercise);
programmingExercise = exerciseRepo.save(programmingExercise);
quizExercise = exerciseRepo.save(quizExercise);
// Get user and setup participations
User user = (userRepo.findOneByLogin("student1")).get();
StudentParticipation participationModeling = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, modelingExercise, user);
StudentParticipation participationText = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, textExercise, user);
StudentParticipation participationFileUpload = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, fileUploadExercise, user);
StudentParticipation participationQuiz = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, quizExercise, user);
StudentParticipation participationProgramming = ModelFactory.generateStudentParticipation(InitializationState.INITIALIZED, programmingExercise, user);
// Save participations
participationModeling = studentParticipationRepo.save(participationModeling);
participationText = studentParticipationRepo.save(participationText);
participationFileUpload = studentParticipationRepo.save(participationFileUpload);
participationQuiz = studentParticipationRepo.save(participationQuiz);
participationProgramming = studentParticipationRepo.save(participationProgramming);
// Setup results
Result resultModeling = ModelFactory.generateResult(true, 10D);
resultModeling.setAssessmentType(AssessmentType.MANUAL);
resultModeling.setCompletionDate(ZonedDateTime.now());
Result resultText = ModelFactory.generateResult(true, 12D);
resultText.setAssessmentType(AssessmentType.MANUAL);
resultText.setCompletionDate(ZonedDateTime.now());
Result resultFileUpload = ModelFactory.generateResult(true, 0D);
resultFileUpload.setAssessmentType(AssessmentType.MANUAL);
resultFileUpload.setCompletionDate(ZonedDateTime.now());
Result resultQuiz = ModelFactory.generateResult(true, 0D);
resultQuiz.setAssessmentType(AssessmentType.AUTOMATIC);
resultQuiz.setCompletionDate(ZonedDateTime.now());
Result resultProgramming = ModelFactory.generateResult(true, 20D);
resultProgramming.setAssessmentType(AssessmentType.AUTOMATIC);
resultProgramming.setCompletionDate(ZonedDateTime.now());
// Connect participations to results and vice versa
resultModeling.setParticipation(participationModeling);
resultText.setParticipation(participationText);
resultFileUpload.setParticipation(participationFileUpload);
resultQuiz.setParticipation(participationQuiz);
resultProgramming.setParticipation(participationProgramming);
participationModeling.addResult(resultModeling);
participationText.addResult(resultText);
participationFileUpload.addResult(resultFileUpload);
participationQuiz.addResult(resultQuiz);
participationProgramming.addResult(resultProgramming);
// Save results and participations
resultModeling = resultRepo.save(resultModeling);
resultText = resultRepo.save(resultText);
resultFileUpload = resultRepo.save(resultFileUpload);
resultQuiz = resultRepo.save(resultQuiz);
resultProgramming = resultRepo.save(resultProgramming);
participationModeling = studentParticipationRepo.save(participationModeling);
participationText = studentParticipationRepo.save(participationText);
participationFileUpload = studentParticipationRepo.save(participationFileUpload);
participationQuiz = studentParticipationRepo.save(participationQuiz);
participationProgramming = studentParticipationRepo.save(participationProgramming);
// Connect exercises with participations
modelingExercise.addParticipation(participationModeling);
textExercise.addParticipation(participationText);
fileUploadExercise.addParticipation(participationFileUpload);
quizExercise.addParticipation(participationQuiz);
programmingExercise.addParticipation(participationProgramming);
// Setup submissions and connect with participations
ModelingSubmission modelingSubmission = ModelFactory.generateModelingSubmission("model1", true);
TextSubmission textSubmission = ModelFactory.generateTextSubmission("text of text submission", Language.ENGLISH, true);
FileUploadSubmission fileUploadSubmission = ModelFactory.generateFileUploadSubmission(true);
QuizSubmission quizSubmission = ModelFactory.generateQuizSubmission(true);
ProgrammingSubmission programmingSubmission = ModelFactory.generateProgrammingSubmission(true);
// Save submissions
modelingSubmission = submissionRepository.save(modelingSubmission);
textSubmission = submissionRepository.save(textSubmission);
fileUploadSubmission = submissionRepository.save(fileUploadSubmission);
quizSubmission = submissionRepository.save(quizSubmission);
programmingSubmission = submissionRepository.save(programmingSubmission);
modelingSubmission.setParticipation(participationModeling);
modelingSubmission.addResult(resultModeling);
textSubmission.setParticipation(participationText);
textSubmission.addResult(resultText);
fileUploadSubmission.setParticipation(participationFileUpload);
fileUploadSubmission.addResult(resultFileUpload);
quizSubmission.setParticipation(participationQuiz);
quizSubmission.addResult(resultQuiz);
programmingSubmission.setParticipation(participationProgramming);
programmingSubmission.addResult(resultProgramming);
// Save submissions
modelingSubmission = submissionRepository.save(modelingSubmission);
textSubmission = submissionRepository.save(textSubmission);
fileUploadSubmission = submissionRepository.save(fileUploadSubmission);
quizSubmission = submissionRepository.save(quizSubmission);
programmingSubmission = submissionRepository.save(programmingSubmission);
// Save exercises
exerciseRepo.save(modelingExercise);
exerciseRepo.save(textExercise);
exerciseRepo.save(fileUploadExercise);
exerciseRepo.save(programmingExercise);
exerciseRepo.save(quizExercise);
// Connect participations with submissions
participationModeling.setSubmissions(Set.of(modelingSubmission));
participationText.setSubmissions(Set.of(textSubmission));
participationFileUpload.setSubmissions(Set.of(fileUploadSubmission));
participationQuiz.setSubmissions(Set.of(quizSubmission));
participationProgramming.setSubmissions(Set.of(programmingSubmission));
// Save participations
studentParticipationRepo.save(participationModeling);
studentParticipationRepo.save(participationText);
studentParticipationRepo.save(participationFileUpload);
studentParticipationRepo.save(participationQuiz);
studentParticipationRepo.save(participationProgramming);
return courseSaved;
}
use of de.tum.in.www1.artemis.domain.FileUploadSubmission in project Artemis by ls1intum.
the class DatabaseUtilService method saveFileUploadSubmissionWithResultAndAssessorFeedback.
public FileUploadSubmission saveFileUploadSubmissionWithResultAndAssessorFeedback(FileUploadExercise exercise, FileUploadSubmission fileUploadSubmission, String login, String assessorLogin, List<Feedback> feedbacks) {
StudentParticipation participation = createAndSaveParticipationForExercise(exercise, login);
submissionRepository.save(fileUploadSubmission);
participation.addSubmission(fileUploadSubmission);
Result result = new Result();
result.setAssessor(getUserByLogin(assessorLogin));
result.setScore(100D);
result.setParticipation(participation);
result.setResultString(exercise.getMaxPoints(), exercise.getMaxPoints());
if (exercise.getReleaseDate() != null) {
result.setCompletionDate(exercise.getReleaseDate());
} else {
// exam exercises do not have a release date
result.setCompletionDate(ZonedDateTime.now());
}
result.setFeedbacks(feedbacks);
result = resultRepo.save(result);
for (Feedback feedback : feedbacks) {
feedback.setResult(result);
}
result = resultRepo.save(result);
result.setSubmission(fileUploadSubmission);
fileUploadSubmission.setParticipation(participation);
fileUploadSubmission.addResult(result);
fileUploadSubmission.getParticipation().addResult(result);
fileUploadSubmission = fileUploadSubmissionRepo.save(fileUploadSubmission);
studentParticipationRepo.save(participation);
return fileUploadSubmission;
}
Aggregations