Search in sources :

Example 56 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class PostService method getAllLecturePosts.

/**
 * Checks course, user, lecture and post validity,
 * retrieves and filters posts for a lecture by its id
 * and ensures that sensitive information is filtered out
 *
 * @param postContextFilter filter object
 * @return page of posts that belong to the lecture
 */
public List<Post> getAllLecturePosts(PostContextFilter postContextFilter) {
    final User user = userRepository.getUserWithGroupsAndAuthorities();
    // checks
    preCheckUserAndCourse(user, postContextFilter.getCourseId());
    preCheckLecture(user, postContextFilter.getCourseId(), postContextFilter.getLectureId());
    // retrieve posts
    List<Post> lecturePosts;
    lecturePosts = postRepository.findPostsByLectureId(postContextFilter.getLectureId(), postContextFilter.getFilterToUnresolved(), postContextFilter.getFilterToOwn(), postContextFilter.getFilterToAnsweredOrReacted(), user.getId());
    // protect sample solution, grading instructions, etc.
    lecturePosts.stream().map(Post::getExercise).filter(Objects::nonNull).forEach(Exercise::filterSensitiveInformation);
    return lecturePosts;
}
Also used : User(de.tum.in.www1.artemis.domain.User) Exercise(de.tum.in.www1.artemis.domain.Exercise) Post(de.tum.in.www1.artemis.domain.metis.Post)

Example 57 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class PostService method changeDisplayPriority.

/**
 * Invokes the updatePost method to persist the change of displayPriority
 *
 * @param courseId          id of the course the post belongs to
 * @param postId            id of the post to change the pin state for
 * @param displayPriority   new displayPriority
 * @return updated post that was persisted
 */
public Post changeDisplayPriority(Long courseId, Long postId, DisplayPriority displayPriority) {
    Post post = postRepository.findByIdElseThrow(postId);
    post.setDisplayPriority(displayPriority);
    return updatePost(courseId, postId, post);
}
Also used : Post(de.tum.in.www1.artemis.domain.metis.Post)

Example 58 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class ExamResource method createExam.

/**
 * POST /courses/{courseId}/exams : Create a new exam.
 *
 * @param courseId the course to which the exam belongs
 * @param exam     the exam to create
 * @return the ResponseEntity with status 201 (Created) and with body the new exam, or with status 400 (Bad Request) if the exam has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/courses/{courseId}/exams")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<Exam> createExam(@PathVariable Long courseId, @RequestBody Exam exam) throws URISyntaxException {
    log.debug("REST request to create an exam : {}", exam);
    if (exam.getId() != null) {
        throw new BadRequestAlertException("A new exam cannot already have an ID", ENTITY_NAME, "idexists");
    }
    checkForExamConflictsElseThrow(courseId, exam);
    // Check that exerciseGroups are not set to prevent manipulation of associated exerciseGroups
    if (!exam.getExerciseGroups().isEmpty()) {
        throw new ConflictException("A new exam cannot have exercise groups yet", ENTITY_NAME, "groupsExist");
    }
    examAccessService.checkCourseAccessForInstructorElseThrow(courseId);
    Exam result = examRepository.save(exam);
    return ResponseEntity.created(new URI("/api/courses/" + courseId + "/exams/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.getTitle())).body(result);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) ConflictException(de.tum.in.www1.artemis.web.rest.errors.ConflictException) URI(java.net.URI) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 59 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class ExamResource method generateMissingStudentExams.

/**
 * POST /courses/:courseId/exams/:examId/generate-missing-student-exams:
 * Generates exams for students, who don't have an individual exam yet.
 * They are created randomly based on the exam configuration and the exercise groups.
 *
 * @param courseId the id of the course
 * @param examId   the id of the exam
 * @return the list of student exams with their corresponding users
 */
@PostMapping(value = "/courses/{courseId}/exams/{examId}/generate-missing-student-exams")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<StudentExam>> generateMissingStudentExams(@PathVariable Long courseId, @PathVariable Long examId) {
    log.info("REST request to generate missing student exams for exam {}", examId);
    final Exam exam = examRepository.findByIdWithRegisteredUsersExerciseGroupsAndExercisesElseThrow(examId);
    examAccessService.checkCourseAndExamAccessForInstructorElseThrow(courseId, examId);
    // Validate settings of the exam
    examService.validateForStudentExamGeneration(exam);
    List<StudentExam> studentExams = studentExamRepository.generateMissingStudentExams(exam);
    // we need to break a cycle for the serialization
    for (StudentExam studentExam : studentExams) {
        studentExam.getExam().setRegisteredUsers(null);
        studentExam.getExam().setExerciseGroups(null);
        studentExam.getExam().setStudentExams(null);
    }
    log.info("Generated {} missing student exams for exam {}", studentExams.size(), examId);
    return ResponseEntity.ok().body(studentExams);
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 60 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class ExerciseGroupResource method createExerciseGroup.

/**
 * POST /courses/{courseId}/exams/{examId}/exerciseGroups : Create a new exercise group.
 *
 * @param courseId      the course to which the exercise group belongs to
 * @param examId        the exam to which the exercise group belongs to
 * @param exerciseGroup the exercise group to create
 * @return the ResponseEntity with status 201 (Created) and with the new exerciseGroup as body,
 *         or with status 400 (Bad Request) if the exerciseGroup has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/courses/{courseId}/exams/{examId}/exerciseGroups")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<ExerciseGroup> createExerciseGroup(@PathVariable Long courseId, @PathVariable Long examId, @RequestBody ExerciseGroup exerciseGroup) throws URISyntaxException {
    log.debug("REST request to create an exercise group : {}", exerciseGroup);
    if (exerciseGroup.getId() != null) {
        throw new BadRequestAlertException("A new exerciseGroup cannot already have an ID", ENTITY_NAME, "idexists");
    }
    if (exerciseGroup.getExam() == null) {
        throw new ConflictException("The exercise group has to belong no an exam.", ENTITY_NAME, "missingExam");
    }
    if (!exerciseGroup.getExam().getId().equals(examId)) {
        throw new ConflictException("The exam connected to this group does not have the given exam id.", ENTITY_NAME, "wrongExamId");
    }
    examAccessService.checkCourseAndExamAccessForEditorElseThrow(courseId, examId);
    // Save the exerciseGroup as part of the exam to ensure that the order column is set correctly
    Exam examFromDB = examRepository.findByIdWithExerciseGroupsElseThrow(examId);
    examFromDB.addExerciseGroup(exerciseGroup);
    Exam savedExam = examRepository.save(examFromDB);
    ExerciseGroup savedExerciseGroup = savedExam.getExerciseGroups().get(savedExam.getExerciseGroups().size() - 1);
    return ResponseEntity.created(new URI("/api/courses/" + courseId + "/exams/" + examId + "/exerciseGroups/" + savedExerciseGroup.getId())).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, savedExerciseGroup.getTitle())).body(savedExerciseGroup);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) ConflictException(de.tum.in.www1.artemis.web.rest.errors.ConflictException) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) URI(java.net.URI) Exam(de.tum.in.www1.artemis.domain.exam.Exam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

Post (de.tum.in.www1.artemis.domain.metis.Post)155 WithMockUser (org.springframework.security.test.context.support.WithMockUser)150 Test (org.junit.jupiter.api.Test)136 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)118 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)97 User (de.tum.in.www1.artemis.domain.User)88 AnswerPost (de.tum.in.www1.artemis.domain.metis.AnswerPost)87 URI (java.net.URI)63 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)56 Course (de.tum.in.www1.artemis.domain.Course)52 Transactional (org.springframework.transaction.annotation.Transactional)37 Reaction (de.tum.in.www1.artemis.domain.metis.Reaction)36 Test (org.junit.Test)36 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)36 Exercise (de.tum.in.www1.artemis.domain.Exercise)35 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)24 Exam (de.tum.in.www1.artemis.domain.exam.Exam)20 Lecture (de.tum.in.www1.artemis.domain.Lecture)16 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)16 SortingOrder (de.tum.in.www1.artemis.domain.enumeration.SortingOrder)16