use of de.tum.in.www1.artemis.domain.participation.StudentParticipation 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;
}
use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.
the class DatabaseUtilService method generateTestRunForInstructor.
public StudentExam generateTestRunForInstructor(Exam exam, User instructor, List<Exercise> exercises) {
var testRun = ModelFactory.generateExamTestRun(exam);
testRun.setUser(instructor);
examRepository.findWithExerciseGroupsAndExercisesById(exam.getId()).get();
for (final var exercise : exercises) {
testRun.addExercise(exercise);
assertThat(exercise.isExamExercise()).isTrue();
Submission submission;
if (exercise instanceof ModelingExercise) {
submission = addModelingSubmission((ModelingExercise) exercise, ModelFactory.generateModelingSubmission("", false), instructor.getLogin());
} else if (exercise instanceof TextExercise) {
submission = saveTextSubmission((TextExercise) exercise, ModelFactory.generateTextSubmission("", null, false), instructor.getLogin());
} else {
submission = new ProgrammingSubmission().submitted(true);
addProgrammingSubmission((ProgrammingExercise) exercise, (ProgrammingSubmission) submission, instructor.getLogin());
submission = submissionRepository.save(submission);
}
var studentParticipation = (StudentParticipation) submission.getParticipation();
studentParticipation.setTestRun(true);
studentParticipationRepo.save(studentParticipation);
}
return testRun;
}
use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.
the class DatabaseUtilService method createCoursesWithExercisesAndLectures.
public List<Course> createCoursesWithExercisesAndLectures(boolean withParticipations) throws Exception {
ZonedDateTime pastTimestamp = ZonedDateTime.now().minusDays(5);
ZonedDateTime futureTimestamp = ZonedDateTime.now().plusDays(5);
ZonedDateTime futureFutureTimestamp = ZonedDateTime.now().plusDays(8);
Course course1 = ModelFactory.generateCourse(null, pastTimestamp, futureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
Course course2 = ModelFactory.generateCourse(null, ZonedDateTime.now().minusDays(8), pastTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, DiagramType.ClassDiagram, course1);
modelingExercise.setGradingInstructions("some grading instructions");
modelingExercise.setExampleSolutionModel("Example solution model");
modelingExercise.setExampleSolutionExplanation("Example Solution");
addGradingInstructionsToExercise(modelingExercise);
modelingExercise.getCategories().add("Modeling");
modelingExercise.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
course1.addExercises(modelingExercise);
TextExercise textExercise = ModelFactory.generateTextExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, course1);
textExercise.setGradingInstructions("some grading instructions");
textExercise.setExampleSolution("Example Solution");
addGradingInstructionsToExercise(textExercise);
textExercise.getCategories().add("Text");
textExercise.setKnowledge(textAssessmentKnowledgeService.createNewKnowledge());
course1.addExercises(textExercise);
FileUploadExercise fileUploadExercise = ModelFactory.generateFileUploadExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, "png", course1);
fileUploadExercise.setGradingInstructions("some grading instructions");
fileUploadExercise.setExampleSolution("Example Solution");
addGradingInstructionsToExercise(fileUploadExercise);
fileUploadExercise.getCategories().add("File");
course1.addExercises(fileUploadExercise);
ProgrammingExercise programmingExercise = ModelFactory.generateProgrammingExercise(pastTimestamp, futureTimestamp, course1);
programmingExercise.setGradingInstructions("some grading instructions");
addGradingInstructionsToExercise(programmingExercise);
programmingExercise.getCategories().add("Programming");
course1.addExercises(programmingExercise);
QuizExercise quizExercise = ModelFactory.generateQuizExercise(pastTimestamp, futureTimestamp, course1);
programmingExercise.getCategories().add("Quiz");
course1.addExercises(quizExercise);
Lecture lecture1 = ModelFactory.generateLecture(pastTimestamp, futureFutureTimestamp, course1);
Attachment attachment1 = ModelFactory.generateAttachment(pastTimestamp, lecture1);
lecture1.addAttachments(attachment1);
course1.addLectures(lecture1);
Lecture lecture2 = ModelFactory.generateLecture(pastTimestamp, futureFutureTimestamp, course1);
Attachment attachment2 = ModelFactory.generateAttachment(pastTimestamp, lecture2);
lecture2.addAttachments(attachment2);
course1.addLectures(lecture2);
course1 = courseRepo.save(course1);
course2 = courseRepo.save(course2);
lectureRepo.save(lecture1);
lectureRepo.save(lecture2);
attachmentRepo.save(attachment1);
attachmentRepo.save(attachment2);
modelingExercise = exerciseRepo.save(modelingExercise);
textExercise = exerciseRepo.save(textExercise);
exerciseRepo.save(fileUploadExercise);
exerciseRepo.save(programmingExercise);
exerciseRepo.save(quizExercise);
if (withParticipations) {
// create 5 tutor participations and 5 example submissions and connect all of them (to test the many-to-many relationship)
var tutorParticipations = new ArrayList<TutorParticipation>();
for (int i = 1; i < 6; i++) {
var tutorParticipation = new TutorParticipation().tutor(getUserByLogin("tutor" + i));
tutorParticipationRepo.save(tutorParticipation);
tutorParticipations.add(tutorParticipation);
}
for (int i = 0; i < 5; i++) {
String validModel = FileUtils.loadFileFromResources("test-data/model-submission/model.54727.json");
var exampleSubmission = addExampleSubmission(generateExampleSubmission(validModel, modelingExercise, true));
exampleSubmission.assessmentExplanation("exp");
for (var tutorParticipation : tutorParticipations) {
exampleSubmission.addTutorParticipations(tutorParticipation);
}
exampleSubmissionRepo.save(exampleSubmission);
}
User user = (userRepo.findOneByLogin("student1")).get();
StudentParticipation participation1 = ModelFactory.generateStudentParticipation(InitializationState.INITIALIZED, modelingExercise, user);
StudentParticipation participation2 = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, textExercise, user);
StudentParticipation participation3 = ModelFactory.generateStudentParticipation(InitializationState.UNINITIALIZED, modelingExercise, user);
Submission modelingSubmission1 = ModelFactory.generateModelingSubmission("model1", true);
Submission modelingSubmission2 = ModelFactory.generateModelingSubmission("model2", true);
Submission textSubmission = ModelFactory.generateTextSubmission("text", Language.ENGLISH, true);
Result result1 = ModelFactory.generateResult(true, 10D);
Result result2 = ModelFactory.generateResult(true, 12D);
Result result3 = ModelFactory.generateResult(false, 0D);
participation1 = studentParticipationRepo.save(participation1);
participation2 = studentParticipationRepo.save(participation2);
participation3 = studentParticipationRepo.save(participation3);
submissionRepository.save(modelingSubmission1);
submissionRepository.save(modelingSubmission2);
submissionRepository.save(textSubmission);
modelingSubmission1.setParticipation(participation1);
textSubmission.setParticipation(participation2);
modelingSubmission2.setParticipation(participation3);
result1.setParticipation(participation1);
result2.setParticipation(participation3);
result3.setParticipation(participation2);
result1 = resultRepo.save(result1);
result2 = resultRepo.save(result2);
result3 = resultRepo.save(result3);
result1.setSubmission(modelingSubmission1);
result2.setSubmission(modelingSubmission2);
result3.setSubmission(textSubmission);
modelingSubmission1.addResult(result1);
modelingSubmission2.addResult(result2);
textSubmission.addResult(result3);
submissionRepository.save(modelingSubmission1);
submissionRepository.save(modelingSubmission2);
submissionRepository.save(textSubmission);
}
return Arrays.asList(course1, course2);
}
use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.
the class DatabaseUtilService method createParticipationSubmissionAndResult.
public Result createParticipationSubmissionAndResult(long exerciseId, Participant participant, Double points, Double bonusPoints, long scoreAwarded, boolean rated) {
Exercise exercise = exerciseRepo.findById(exerciseId).get();
if (!exercise.getMaxPoints().equals(points)) {
exercise.setMaxPoints(points);
}
if (!exercise.getBonusPoints().equals(bonusPoints)) {
exercise.setBonusPoints(bonusPoints);
}
exercise = exerciseRepo.saveAndFlush(exercise);
StudentParticipation studentParticipation = participationService.startExercise(exercise, participant, false);
return createSubmissionAndResult(studentParticipation, scoreAwarded, rated);
}
use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.
the class DatabaseUtilService method addProgrammingSubmissionWithResult.
/**
* Add a submission with a result to the given programming exercise. The submission will be assigned to the corresponding participation of the given login (if exists or create a new participation).
* The method will make sure that all necessary entities are connected.
*
* @param exercise for which to create the submission/participation/result combination.
* @param submission to use for adding to the exercise/participation/result.
* @param login of the user to identify the corresponding student participation.
*/
public void addProgrammingSubmissionWithResult(ProgrammingExercise exercise, ProgrammingSubmission submission, String login) {
StudentParticipation participation = addStudentParticipationForProgrammingExercise(exercise, login);
submission = programmingSubmissionRepo.save(submission);
Result result = resultRepo.save(new Result().participation(participation));
participation.addSubmission(submission);
submission.setParticipation(participation);
submission.addResult(result);
submission = programmingSubmissionRepo.save(submission);
result.setSubmission(submission);
result = resultRepo.save(result);
participation.addResult(result);
studentParticipationRepo.save(participation);
}
Aggregations