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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations