Search in sources :

Example 6 with TutorParticipation

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();
}
Also used : Exercise(de.tum.in.www1.artemis.domain.Exercise) User(de.tum.in.www1.artemis.domain.User) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 7 with TutorParticipation

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);
}
Also used : Exercise(de.tum.in.www1.artemis.domain.Exercise) User(de.tum.in.www1.artemis.domain.User) TutorParticipation(de.tum.in.www1.artemis.domain.participation.TutorParticipation) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 8 with 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);
}
Also used : User(de.tum.in.www1.artemis.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ExampleSubmission(de.tum.in.www1.artemis.domain.ExampleSubmission) TutorParticipation(de.tum.in.www1.artemis.domain.participation.TutorParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 9 with TutorParticipation

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;
}
Also used : TutorParticipation(de.tum.in.www1.artemis.domain.participation.TutorParticipation)

Example 10 with TutorParticipation

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;
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) java.util(java.util) JsonProcessingException(org.springframework.cloud.cloudfoundry.com.fasterxml.jackson.core.JsonProcessingException) Logger(org.slf4j.Logger) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) FeedbackCorrectionErrorType(de.tum.in.www1.artemis.service.TutorParticipationService.FeedbackCorrectionErrorType) ObjectMapper(org.springframework.cloud.cloudfoundry.com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) Stream(java.util.stream.Stream) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) Service(org.springframework.stereotype.Service) TutorParticipationStatus(de.tum.in.www1.artemis.domain.enumeration.TutorParticipationStatus) ExampleSubmissionRepository(de.tum.in.www1.artemis.repository.ExampleSubmissionRepository) TutorParticipation(de.tum.in.www1.artemis.domain.participation.TutorParticipation) TutorParticipationRepository(de.tum.in.www1.artemis.repository.TutorParticipationRepository) FeedbackType(de.tum.in.www1.artemis.domain.enumeration.FeedbackType) TutorParticipation(de.tum.in.www1.artemis.domain.participation.TutorParticipation) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)

Aggregations

TutorParticipation (de.tum.in.www1.artemis.domain.participation.TutorParticipation)22 Exercise (de.tum.in.www1.artemis.domain.Exercise)8 User (de.tum.in.www1.artemis.domain.User)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 ExampleSubmission (de.tum.in.www1.artemis.domain.ExampleSubmission)4 TutorParticipationStatus (de.tum.in.www1.artemis.domain.enumeration.TutorParticipationStatus)4 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 Service (org.springframework.stereotype.Service)4 JsonParser.parseString (com.google.gson.JsonParser.parseString)2 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)2 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)2 ExerciseMapEntry (de.tum.in.www1.artemis.domain.assessment.dashboard.ExerciseMapEntry)2 FeedbackType (de.tum.in.www1.artemis.domain.enumeration.FeedbackType)2 Exam (de.tum.in.www1.artemis.domain.exam.Exam)2 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)2