Search in sources :

Example 46 with StudentParticipation

use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.

the class ResultResource method getLatestResultWithFeedbacks.

/**
 * GET /participations/:participationId/latest-result : get the latest result with feedbacks for the given participation.
 * The order of results is determined by completionDate desc.
 *
 * @param participationId the id of the participation for which to retrieve the latest result.
 * @return the ResponseEntity with status 200 (OK) and with body the result, or with status 404 (Not Found)
 */
@GetMapping("participations/{participationId}/latest-result")
@PreAuthorize("hasRole('TA')")
public ResponseEntity<Result> getLatestResultWithFeedbacks(@PathVariable Long participationId) {
    log.debug("REST request to get latest result for participation : {}", participationId);
    Participation participation = participationRepository.findByIdElseThrow(participationId);
    if (participation instanceof StudentParticipation && !authCheckService.canAccessParticipation((StudentParticipation) participation) || participation instanceof ProgrammingExerciseParticipation && !programmingExerciseParticipationService.canAccessParticipation((ProgrammingExerciseParticipation) participation)) {
        throw new AccessForbiddenException();
    }
    Result result = resultRepository.findFirstWithFeedbacksByParticipationIdOrderByCompletionDateDescElseThrow(participation.getId());
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : Participation(de.tum.in.www1.artemis.domain.participation.Participation) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) ProgrammingExerciseParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ResponseEntity(org.springframework.http.ResponseEntity) ProgrammingExerciseParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 47 with StudentParticipation

use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.

the class ResultResource method createResultForExternalSubmission.

/**
 * POST exercises/:exerciseId/external-submission-results : Creates a new result for the provided exercise and student (a participation and an empty submission will also be created if they do not exist yet)
 *
 * @param exerciseId The exercise ID for which a result should get created
 * @param studentLogin The student login (username) for which a result should get created
 * @param result The result to be created
 * @return The newly created result
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("exercises/{exerciseId}/external-submission-results")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<Result> createResultForExternalSubmission(@PathVariable Long exerciseId, @RequestParam String studentLogin, @RequestBody Result result) throws URISyntaxException {
    log.debug("REST request to create Result for External Submission for Exercise : {}", exerciseId);
    if (result.getParticipation() != null && result.getParticipation().getExercise() != null && !result.getParticipation().getExercise().getId().equals(exerciseId)) {
        throw new BadRequestAlertException("exerciseId in RequestBody doesnt match exerciseId in path!", "Exercise", "400");
    }
    Exercise exercise = exerciseRepository.findByIdElseThrow(exerciseId);
    authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.INSTRUCTOR, exercise, null);
    if (!exercise.isExamExercise()) {
        if (exercise.getDueDate() == null || ZonedDateTime.now().isBefore(exercise.getDueDate())) {
            return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, "result", "externalSubmissionBeforeDueDate", "External submissions are not supported before the exercise due date.")).build();
        }
    } else {
        Exam exam = exercise.getExerciseGroup().getExam();
        ZonedDateTime latestIndividualExamEndDate = examDateService.getLatestIndividualExamEndDate(exam);
        if (latestIndividualExamEndDate == null || ZonedDateTime.now().isBefore(latestIndividualExamEndDate)) {
            return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, "result", "externalSubmissionBeforeDueDate", "External submissions are not supported before the end of the exam.")).build();
        }
    }
    if (exercise instanceof QuizExercise) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, "result", "externalSubmissionForQuizExercise", "External submissions are not supported for Quiz exercises.")).build();
    }
    Optional<User> student = userRepository.findOneWithGroupsAndAuthoritiesByLogin(studentLogin);
    authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.INSTRUCTOR, exercise, null);
    if (student.isEmpty() || !authCheckService.isAtLeastStudentInCourse(exercise.getCourseViaExerciseGroupOrCourseMember(), student.get())) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, "result", "studentNotFound", "The student could not be found in this course.")).build();
    }
    // Check if a result exists already for this exercise and student. If so, do nothing and just inform the instructor.
    Optional<StudentParticipation> optionalParticipation = participationService.findOneByExerciseAndStudentLoginAnyStateWithEagerResults(exercise, studentLogin);
    if (optionalParticipation.isPresent() && optionalParticipation.get().getResults() != null && !optionalParticipation.get().getResults().isEmpty()) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, "result", "resultAlreadyExists", "A result already exists for this student in this exercise.")).build();
    }
    // Create a participation and a submitted empty submission if they do not exist yet
    StudentParticipation participation = participationService.createParticipationWithEmptySubmissionIfNotExisting(exercise, student.get(), SubmissionType.EXTERNAL);
    Submission submission = participationRepository.findByIdWithLegalSubmissionsElseThrow(participation.getId()).findLatestSubmission().get();
    result.setParticipation(participation);
    result.setSubmission(submission);
    // Create a new manual result which can be rated or unrated depending on what was specified in the create form
    Result savedResult = resultService.createNewManualResult(result, exercise instanceof ProgrammingExercise, result.isRated());
    return ResponseEntity.created(new URI("/api/results/" + savedResult.getId())).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, savedResult.getId().toString())).body(savedResult);
}
Also used : URI(java.net.URI) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) ZonedDateTime(java.time.ZonedDateTime) Exam(de.tum.in.www1.artemis.domain.exam.Exam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 48 with StudentParticipation

use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.

the class ComplaintResource method createComplaintForExamExercise.

/**
 * POST complaints/exam/examId: create a new complaint for an exam exercise
 *
 * @param complaint the complaint to create
 * @param principal that wants to complain
 * @param examId the examId of the exam which contains the exercise
 * @return the ResponseEntity with status 201 (Created) and with body the new complaints
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
// TODO: should be exams/{examId}/(participations/{participationId}/)complaints
@PostMapping("complaints/exam/{examId}")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Complaint> createComplaintForExamExercise(@PathVariable Long examId, @RequestBody Complaint complaint, Principal principal) throws URISyntaxException {
    log.debug("REST request to save Complaint for exam exercise: {}", complaint);
    if (complaint.getId() != null) {
        throw new BadRequestAlertException("A new complaint cannot already have an id", COMPLAINT_ENTITY_NAME, "idexists");
    }
    if (complaint.getResult() == null || complaint.getResult().getId() == null) {
        throw new BadRequestAlertException("A complaint can be only associated to a result", COMPLAINT_ENTITY_NAME, "noresultid");
    }
    if (complaintRepository.findByResultId(complaint.getResult().getId()).isPresent()) {
        throw new BadRequestAlertException("A complaint for this result already exists", COMPLAINT_ENTITY_NAME, "complaintexists");
    }
    Result result = resultRepository.findByIdElseThrow(complaint.getResult().getId());
    // For non-exam exercises, the POST complaints should be used
    if (!result.getParticipation().getExercise().isExamExercise()) {
        throw new BadRequestAlertException("A complaint for an course exercise cannot be filed using this component", COMPLAINT_ENTITY_NAME, "complaintAboutCourseExerciseWrongComponent");
    }
    authCheckService.isOwnerOfParticipationElseThrow((StudentParticipation) result.getParticipation());
    // To build correct creation alert on the front-end we must check which type is the complaint to apply correct i18n key.
    String entityName = complaint.getComplaintType() == ComplaintType.MORE_FEEDBACK ? MORE_FEEDBACK_ENTITY_NAME : COMPLAINT_ENTITY_NAME;
    Complaint savedComplaint = complaintService.createComplaint(complaint, OptionalLong.of(examId), principal);
    // Remove assessor information from client request
    savedComplaint.getResult().setAssessor(null);
    return ResponseEntity.created(new URI("/api/complaints/" + savedComplaint.getId())).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, entityName, savedComplaint.getId().toString())).body(savedComplaint);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 49 with StudentParticipation

use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.

the class ComplaintResource method filterOutStudentFromComplaint.

private void filterOutStudentFromComplaint(Complaint complaint) {
    complaint.setParticipant(null);
    if (complaint.getResult() != null && complaint.getResult().getParticipation() != null) {
        StudentParticipation studentParticipation = (StudentParticipation) complaint.getResult().getParticipation();
        studentParticipation.setParticipant(null);
    }
}
Also used : StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation)

Example 50 with StudentParticipation

use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.

the class ComplaintResource method filterOutUselessDataFromComplaint.

private void filterOutUselessDataFromComplaint(Complaint complaint) {
    if (complaint.getResult() == null) {
        return;
    }
    StudentParticipation originalParticipation = (StudentParticipation) complaint.getResult().getParticipation();
    if (originalParticipation != null && originalParticipation.getExercise() != null) {
        Exercise exerciseWithOnlyTitle = originalParticipation.getExercise();
        if (exerciseWithOnlyTitle instanceof TextExercise) {
            exerciseWithOnlyTitle = new TextExercise();
        } else if (exerciseWithOnlyTitle instanceof ModelingExercise) {
            exerciseWithOnlyTitle = new ModelingExercise();
        } else if (exerciseWithOnlyTitle instanceof FileUploadExercise) {
            exerciseWithOnlyTitle = new FileUploadExercise();
        } else if (exerciseWithOnlyTitle instanceof ProgrammingExercise) {
            exerciseWithOnlyTitle = new ProgrammingExercise();
        }
        exerciseWithOnlyTitle.setTitle(originalParticipation.getExercise().getTitle());
        exerciseWithOnlyTitle.setId(originalParticipation.getExercise().getId());
        originalParticipation.setExercise(exerciseWithOnlyTitle);
    }
    Submission originalSubmission = complaint.getResult().getSubmission();
    if (originalSubmission != null) {
        Submission submissionWithOnlyId;
        if (originalSubmission instanceof TextSubmission) {
            submissionWithOnlyId = new TextSubmission();
        } else if (originalSubmission instanceof ModelingSubmission) {
            submissionWithOnlyId = new ModelingSubmission();
        } else if (originalSubmission instanceof FileUploadSubmission) {
            submissionWithOnlyId = new FileUploadSubmission();
        } else if (originalSubmission instanceof ProgrammingSubmission) {
            submissionWithOnlyId = new ProgrammingSubmission();
        } else {
            return;
        }
        submissionWithOnlyId.setId(originalSubmission.getId());
        complaint.getResult().setSubmission(submissionWithOnlyId);
    }
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation)

Aggregations

StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)219 Test (org.junit.jupiter.api.Test)118 WithMockUser (org.springframework.security.test.context.support.WithMockUser)112 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)60 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)50 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)48 ZonedDateTime (java.time.ZonedDateTime)44 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)42 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)40 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)36 Exam (de.tum.in.www1.artemis.domain.exam.Exam)30 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)30 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)28 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)28 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)26 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)24 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)24 Participation (de.tum.in.www1.artemis.domain.participation.Participation)24 Collectors (java.util.stream.Collectors)24