use of de.tum.in.www1.artemis.domain.participation.TutorParticipation in project Artemis by ls1intum.
the class ExampleSubmissionService method deleteById.
/**
* Deletes a ExampleSubmission with the given ID, cleans up the tutor participations, removes the result and the submission
* @param exampleSubmissionId the ID of the ExampleSubmission which should be deleted
*/
// ok
@Transactional
public void deleteById(long exampleSubmissionId) {
Optional<ExampleSubmission> optionalExampleSubmission = exampleSubmissionRepository.findByIdWithResultsAndTutorParticipations(exampleSubmissionId);
if (optionalExampleSubmission.isPresent()) {
ExampleSubmission exampleSubmission = optionalExampleSubmission.get();
for (TutorParticipation tutorParticipation : exampleSubmission.getTutorParticipations()) {
tutorParticipation.getTrainedExampleSubmissions().remove(exampleSubmission);
}
Long exerciseId = exampleSubmission.getExercise().getId();
Optional<Exercise> exerciseWithExampleSubmission = exerciseRepository.findByIdWithEagerExampleSubmissions(exerciseId);
// Remove the reference to the exercise when the example submission is deleted
exerciseWithExampleSubmission.ifPresent(exercise -> exercise.removeExampleSubmission(exampleSubmission));
// due to Cascade.Remove this will also remove the submission and the result(s) in case they exist
exampleSubmissionRepository.delete(exampleSubmission);
}
}
use of de.tum.in.www1.artemis.domain.participation.TutorParticipation in project Artemis by ls1intum.
the class TutorParticipationService method createNewParticipation.
/**
* Given an exercise and a tutor it creates the participation of the tutor to that exercise The tutor starts a participation when she reads the grading instruction. If no
* grading instructions are available, then she starts her participation clicking on "Start participation". Usually, the first step is `REVIEWED_INSTRUCTIONS`: after that, she
* has to train reviewing some example submissions, and assessing others. If no example submissions are available, because the instructor hasn't created any, then she goes
* directly to the next step, that allows her to assess students' participations
*
* @param exercise the exercise the tutor is going to participate in
* @param tutor the tutor who is going to participate in the exercise
* @return a TutorParticipation for the exercise
*/
public TutorParticipation createNewParticipation(Exercise exercise, User tutor) {
TutorParticipation tutorParticipation = new TutorParticipation();
Long exampleSubmissionsCount = exampleSubmissionRepository.countAllByExerciseId(exercise.getId());
tutorParticipation.setStatus(exampleSubmissionsCount == 0 ? TRAINED : REVIEWED_INSTRUCTIONS);
tutorParticipation.setTutor(tutor);
tutorParticipation.setAssessedExercise(exercise);
return tutorParticipationRepository.saveAndFlush(tutorParticipation);
}
use of de.tum.in.www1.artemis.domain.participation.TutorParticipation in project Artemis by ls1intum.
the class ExamResource method getExamForAssessmentDashboard.
/**
* GET /courses/:courseId/exams/:examId/exam-for-assessment-dashboard
*
* @param courseId the id of the course to retrieve
* @param examId the id of the exam that contains the exercises
* @return data about a course including all exercises, plus some data for the tutor as tutor status for assessment
*/
@GetMapping("/courses/{courseId}/exams/{examId}/exam-for-assessment-dashboard")
@PreAuthorize("hasRole('TA')")
public ResponseEntity<Exam> getExamForAssessmentDashboard(@PathVariable long courseId, @PathVariable long examId) {
log.debug("REST request /courses/{courseId}/exams/{examId}/exam-for-assessment-dashboard");
Exam exam = examService.findByIdWithExerciseGroupsAndExercisesElseThrow(examId);
Course course = exam.getCourse();
checkExamCourseIdElseThrow(courseId, exam);
User user = userRepository.getUserWithGroupsAndAuthorities();
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.TEACHING_ASSISTANT, course, user);
if (ZonedDateTime.now().isBefore(exam.getEndDate()) && authCheckService.isTeachingAssistantInCourse(course, user)) {
// tutors cannot access the exercises before the exam ends
throw new AccessForbiddenException("exam", examId);
}
Set<Exercise> exercises = new HashSet<>();
// extract all exercises for all the exam
for (ExerciseGroup exerciseGroup : exam.getExerciseGroups()) {
exerciseGroup.setExercises(courseRepository.getInterestingExercisesForAssessmentDashboards(exerciseGroup.getExercises()));
exercises.addAll(exerciseGroup.getExercises());
}
List<TutorParticipation> tutorParticipations = tutorParticipationRepository.findAllByAssessedExercise_ExerciseGroup_Exam_IdAndTutor_Id(examId, user.getId());
assessmentDashboardService.generateStatisticsForExercisesForAssessmentDashboard(exercises, tutorParticipations, true);
return ResponseEntity.ok(exam);
}
use of de.tum.in.www1.artemis.domain.participation.TutorParticipation in project Artemis by ls1intum.
the class ExampleSubmissionIntegrationTest method createAndDeleteExampleModelingSubmissionWithResult.
@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void createAndDeleteExampleModelingSubmissionWithResult(boolean usedForTutorial) throws Exception {
exampleSubmission = database.generateExampleSubmission(validModel, modelingExercise, false, usedForTutorial);
exampleSubmission.addTutorParticipations(new TutorParticipation());
ExampleSubmission returnedExampleSubmission = request.postWithResponseBody("/api/exercises/" + modelingExercise.getId() + "/example-submissions", exampleSubmission, ExampleSubmission.class, HttpStatus.OK);
Long submissionId = returnedExampleSubmission.getSubmission().getId();
database.checkModelingSubmissionCorrectlyStored(submissionId, validModel);
Optional<ExampleSubmission> storedExampleSubmission = exampleSubmissionRepo.findBySubmissionId(submissionId);
assertThat(storedExampleSubmission).as("example submission correctly stored").isPresent();
assertThat(storedExampleSubmission.get().getSubmission().isExampleSubmission()).as("submission flagged as example submission").isTrue();
request.delete("/api/example-submissions/" + storedExampleSubmission.get().getId(), HttpStatus.OK);
assertThat(exampleSubmissionRepo.findAllByExerciseId(submissionId)).isEmpty();
}
use of de.tum.in.www1.artemis.domain.participation.TutorParticipation in project Artemis by ls1intum.
the class TutorParticipationResourceIntegrationTest method testRemoveTutorParticipationForGuidedTour.
@Test
@WithMockUser(username = "tutor1", roles = "TA")
public void testRemoveTutorParticipationForGuidedTour() throws Exception {
assertThat(tutorParticipationRepository.findAll()).hasSize(5);
User tutor = database.getUserByLogin("tutor1");
TutorParticipation tutorParticipation = tutorParticipationRepository.findAll().get(0);
tutorParticipation.tutor(tutor).assessedExercise(exercise);
tutorParticipationRepository.save(tutorParticipation);
ExampleSubmission exampleSubmission = database.addExampleSubmission(database.generateExampleSubmission("", exercise, true));
exampleSubmission.addTutorParticipations(tutorParticipationRepository.findWithEagerExampleSubmissionAndResultsByAssessedExerciseAndTutor(exercise, tutor));
exampleSubmissionRepository.save(exampleSubmission);
Optional<ExampleSubmission> exampleSubmissionWithEagerExercise = exampleSubmissionRepository.findWithSubmissionResultExerciseGradingCriteriaById(exampleSubmission.getId());
if (exampleSubmissionWithEagerExercise.isPresent()) {
exercise = exampleSubmissionWithEagerExercise.get().getExercise();
exercise.setTitle("Patterns in Software Engineering");
exerciseRepository.save(exercise);
}
request.delete("/api/guided-tour/exercises/" + exercise.getId() + "/example-submission", HttpStatus.OK);
assertThat(tutorParticipationRepository.findAll()).as("Removed tutor participation").hasSize(4);
}
Aggregations