use of de.tum.in.www1.artemis.domain.participation.TutorParticipation in project ArTEMiS by ls1intum.
the class TutorParticipationResource method deleteTutorParticipationForGuidedTour.
/**
* DELETE /guided-tour/exercises/:exerciseId/example-submission: delete the tutor participation for example submissions of the "exerciseId" exercise for guided tutorials (e.g. when restarting a tutorial)
* Please note: all tutors can delete their own tutor participation for example submissions when it belongs to a guided tutorial
* @param exerciseId the exercise id which has example submissions and tutor participations
* @return the ResponseEntity with status 200 (OK) or 403 (FORBIDDEN)
*/
@DeleteMapping(value = "/guided-tour/exercises/{exerciseId}/example-submission")
@PreAuthorize("hasRole('TA')")
public ResponseEntity<TutorParticipation> deleteTutorParticipationForGuidedTour(@PathVariable Long exerciseId) {
log.debug("REST request to remove tutor participation of the example submission for exercise id : {}", exerciseId);
Exercise exercise = this.exerciseRepository.findByIdElseThrow(exerciseId);
User user = userRepository.getUserWithGroupsAndAuthorities();
// Allow all tutors to delete their own participation if it's for a tutorial
authorizationCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.TEACHING_ASSISTANT, exercise, user);
guidedTourConfiguration.checkExerciseForTutorialElseThrow(exercise);
tutorParticipationService.removeTutorParticipations(exercise, user);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, exerciseId.toString())).build();
}
use of de.tum.in.www1.artemis.domain.participation.TutorParticipation in project ArTEMiS by ls1intum.
the class TutorParticipationResource method initTutorParticipation.
/**
* POST /exercises/:exerciseId/tutor-participations : start the "id" exercise for the current tutor. A tutor participation will be created and returned for the exercise given by
* the exercise id. The tutor participation status will be assigned based on which features are available for the exercise (e.g. grading instructions) The method is valid only
* for tutors, since it inits the tutor participation to the exercise, which is different from a standard participation
*
* @param exerciseId the id of the exercise for which to init a tutorParticipations
* @return the ResponseEntity with status 200 (OK) and with body the exercise, or with status 404 (Not Found)
* @throws URISyntaxException if URI path can't be created
*/
@PostMapping(value = "/exercises/{exerciseId}/tutor-participations")
@PreAuthorize("hasRole('TA')")
public ResponseEntity<TutorParticipation> initTutorParticipation(@PathVariable Long exerciseId) throws URISyntaxException {
log.debug("REST request to start tutor participation : {}", exerciseId);
Exercise exercise = exerciseRepository.findByIdElseThrow(exerciseId);
User user = userRepository.getUserWithGroupsAndAuthorities();
authorizationCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.TEACHING_ASSISTANT, exercise, user);
if (tutorParticipationRepository.existsByAssessedExerciseIdAndTutorId(exerciseId, user.getId())) {
// tutorParticipation already exists
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, ENTITY_NAME, "tutorParticipationAlreadyExists", "There is already a tutorParticipations for the given exercise and user.")).body(null);
}
TutorParticipation tutorParticipation = tutorParticipationService.createNewParticipation(exercise, user);
return ResponseEntity.created(new URI("/api/exercises/" + exerciseId + "tutor-participations/" + tutorParticipation.getId())).body(tutorParticipation);
}
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);
}
use of de.tum.in.www1.artemis.domain.participation.TutorParticipation in project Artemis by ls1intum.
the class TutorParticipationService method findByExerciseAndTutor.
/**
* Given an exercise and a tutor, it retrieves the participation of the tutor for that exercise. If there isn't any participation in the database, it returns a participation
* with status NOT_PARTICIPATED
*
* @param exercise the exercise we want to retrieve the tutor participation
* @param tutor the tutor of whom we want to retrieve the participation
* @return a tutor participation object for the pair (exercise, tutor) passed as argument
*/
public TutorParticipation findByExerciseAndTutor(Exercise exercise, User tutor) {
TutorParticipation participation = tutorParticipationRepository.findWithEagerExampleSubmissionAndResultsByAssessedExerciseAndTutor(exercise, tutor);
if (participation == null) {
participation = new TutorParticipation();
participation.setStatus(NOT_PARTICIPATED);
}
return participation;
}
use of de.tum.in.www1.artemis.domain.participation.TutorParticipation in project Artemis by ls1intum.
the class TutorParticipationService method addExampleSubmission.
/**
* Given an exercise, it adds to the tutor participation of that exercise the example submission passed as argument.
* If it is valid (e.g: if it is an example submission used for tutorial, we check the result is close enough to the one of the instructor)
*
* @param exercise - the exercise we are referring to
* @param tutorExampleSubmission - the example submission to add
* @param user - the user who invokes this request
* @return the updated tutor participation
* @throws EntityNotFoundException if example submission or tutor participation is not found
* @throws BadRequestAlertException if tutor didn't review the instructions before assessing example submissions
*/
public TutorParticipation addExampleSubmission(Exercise exercise, ExampleSubmission tutorExampleSubmission, User user) throws EntityNotFoundException, BadRequestAlertException {
TutorParticipation existingTutorParticipation = this.findByExerciseAndTutor(exercise, user);
// Do not trust the user input
Optional<ExampleSubmission> exampleSubmissionFromDatabase = exampleSubmissionRepository.findByIdWithResultsAndTutorParticipations(tutorExampleSubmission.getId());
if (existingTutorParticipation == null || exampleSubmissionFromDatabase.isEmpty()) {
throw new EntityNotFoundException("There isn't such example submission, or there isn't any tutor participation for this exercise");
}
ExampleSubmission originalExampleSubmission = exampleSubmissionFromDatabase.get();
// Cannot start an example submission if the tutor hasn't participated in the exercise yet
if (existingTutorParticipation.getStatus() == NOT_PARTICIPATED) {
throw new BadRequestAlertException("The tutor needs review the instructions before assessing example submissions", ENTITY_NAME, "wrongStatus");
}
// Check if it is a tutorial or not
boolean isTutorial = Boolean.TRUE.equals(originalExampleSubmission.isUsedForTutorial());
// If it is a tutorial we check the assessment
if (isTutorial) {
validateTutorialExampleSubmission(tutorExampleSubmission);
}
List<ExampleSubmission> alreadyAssessedSubmissions = new ArrayList<>(existingTutorParticipation.getTrainedExampleSubmissions());
// If the example submission was already assessed, we do not assess it again, we just return the current participation
if (alreadyAssessedSubmissions.contains(tutorExampleSubmission)) {
return existingTutorParticipation;
}
long numberOfExampleSubmissionsForTutor = exampleSubmissionRepository.findAllWithResultByExerciseId(exercise.getId()).stream().filter(exSub -> exSub.getSubmission() != null && exSub.getSubmission().getLatestResult() != null && Boolean.TRUE.equals(exSub.getSubmission().getLatestResult().isExampleResult())).count();
// +1 because we haven't added yet the one we just did
int numberOfAlreadyAssessedSubmissions = alreadyAssessedSubmissions.size() + 1;
/*
* When the tutor has read and assessed all the exercises, the tutor status goes to the next step.
*/
if (numberOfAlreadyAssessedSubmissions >= numberOfExampleSubmissionsForTutor) {
existingTutorParticipation.setStatus(TRAINED);
}
// keep example submission set reference with loaded submission.results to reconnect after save response from DB
var exampleSubmissionSet = existingTutorParticipation.getTrainedExampleSubmissions();
existingTutorParticipation = existingTutorParticipation.addTrainedExampleSubmissions(originalExampleSubmission);
exampleSubmissionService.save(originalExampleSubmission);
existingTutorParticipation = tutorParticipationRepository.saveAndFlush(existingTutorParticipation);
existingTutorParticipation.setTrainedExampleSubmissions(exampleSubmissionSet);
existingTutorParticipation.getTrainedExampleSubmissions().add(originalExampleSubmission);
return existingTutorParticipation;
}
Aggregations