use of de.tum.in.www1.artemis.domain.lecture in project Artemis by ls1intum.
the class LectureUnitResource method updateLectureUnitsOrder.
/**
* PUT /lectures/:lectureId/lecture-units-order
*
* @param lectureId the id of the lecture for which to update the lecture unit order
* @param orderedLectureUnits ordered lecture units
* @return the ResponseEntity with status 200 (OK) and with body the ordered lecture units
*/
@PutMapping("/lectures/{lectureId}/lecture-units-order")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<List<LectureUnit>> updateLectureUnitsOrder(@PathVariable Long lectureId, @RequestBody List<LectureUnit> orderedLectureUnits) {
log.debug("REST request to update the order of lecture units of lecture: {}", lectureId);
Optional<Lecture> lectureOptional = lectureRepository.findByIdWithPostsAndLectureUnitsAndLearningGoals(lectureId);
if (lectureOptional.isEmpty()) {
throw new EntityNotFoundException("Lecture", lectureId);
}
Lecture lecture = lectureOptional.get();
if (lecture.getCourse() == null) {
return conflict();
}
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, lecture.getCourse(), null);
// Ensure that exactly as many lecture units have been received as are currently related to the lecture
if (orderedLectureUnits.size() != lecture.getLectureUnits().size()) {
return conflict();
}
// Ensure that all received lecture units are already related to the lecture
for (LectureUnit lectureUnit : orderedLectureUnits) {
if (!lecture.getLectureUnits().contains(lectureUnit)) {
return conflict();
}
// Set the lecture manually as it won't be included in orderedLectureUnits
lectureUnit.setLecture(lecture);
// keep bidirectional mapping between attachment unit and attachment
if (lectureUnit instanceof AttachmentUnit) {
((AttachmentUnit) lectureUnit).getAttachment().setAttachmentUnit((AttachmentUnit) lectureUnit);
}
}
lecture.setLectureUnits(orderedLectureUnits);
Lecture persistedLecture = lectureRepository.save(lecture);
return ResponseEntity.ok(persistedLecture.getLectureUnits());
}
use of de.tum.in.www1.artemis.domain.lecture in project Artemis by ls1intum.
the class LectureUnitIntegrationTest method updateLectureUnitOrder_asInstructorNewTextUnitInOrderedList_shouldReturnConflict.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateLectureUnitOrder_asInstructorNewTextUnitInOrderedList_shouldReturnConflict() throws Exception {
TextUnitList newlyOrderedList = new TextUnitList();
newlyOrderedList.add(textUnit);
newlyOrderedList.add(textUnit2);
newlyOrderedList.add(textUnit3);
for (TextUnit textUnit : newlyOrderedList) {
textUnit.setLecture(null);
}
request.put("/api/lectures/" + lecture1.getId() + "/lecture-units-order", List.of(), HttpStatus.CONFLICT);
}
use of de.tum.in.www1.artemis.domain.lecture in project Artemis by ls1intum.
the class LectureUnitIntegrationTest method updateLectureUnitOrder_asInstructor_shouldUpdateLectureUnitOrder.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateLectureUnitOrder_asInstructor_shouldUpdateLectureUnitOrder() throws Exception {
long idOfOriginalFirstPosition = lecture1.getLectureUnits().get(0).getId();
long idOfOriginalSecondPosition = lecture1.getLectureUnits().get(1).getId();
TextUnitList newlyOrderedList = new TextUnitList();
newlyOrderedList.add(textUnit);
newlyOrderedList.add(textUnit2);
for (TextUnit textUnit : newlyOrderedList) {
textUnit.setLecture(null);
}
Collections.swap(newlyOrderedList, 0, 1);
List<TextUnit> returnedList = request.putWithResponseBodyList("/api/lectures/" + lecture1.getId() + "/lecture-units-order", newlyOrderedList, TextUnit.class, HttpStatus.OK);
assertThat(returnedList.get(0).getId()).isEqualTo(idOfOriginalSecondPosition);
assertThat(returnedList.get(1).getId()).isEqualTo(idOfOriginalFirstPosition);
}
use of de.tum.in.www1.artemis.domain.lecture in project Artemis by ls1intum.
the class LearningGoalService method calculateLearningGoalCourseProgress.
/**
* Calculate the progress in a learning goal for a whole course
*
* @param useParticipantScoreTable use the participant score table instead of going through participation -> submission -> result
* @param learningGoal learning goal to get the progress for
* @return progress of the course in the learning goal
*/
public CourseLearningGoalProgress calculateLearningGoalCourseProgress(LearningGoal learningGoal, boolean useParticipantScoreTable) {
CourseLearningGoalProgress courseLearningGoalProgress = new CourseLearningGoalProgress();
courseLearningGoalProgress.courseId = learningGoal.getCourse().getId();
courseLearningGoalProgress.learningGoalId = learningGoal.getId();
courseLearningGoalProgress.learningGoalTitle = learningGoal.getTitle();
courseLearningGoalProgress.totalPointsAchievableByStudentsInLearningGoal = 0.0;
courseLearningGoalProgress.averagePointsAchievedByStudentInLearningGoal = 0.0;
// The progress will be calculated from a subset of the connected lecture units (currently only from released exerciseUnits)
List<ExerciseUnit> exerciseUnitsUsableForProgressCalculation = learningGoal.getLectureUnits().parallelStream().filter(LectureUnit::isVisibleToStudents).filter(lectureUnit -> lectureUnit instanceof ExerciseUnit).map(lectureUnit -> (ExerciseUnit) lectureUnit).collect(Collectors.toList());
Set<CourseLearningGoalProgress.CourseLectureUnitProgress> progressInLectureUnits = this.calculateExerciseUnitsProgressForCourse(exerciseUnitsUsableForProgressCalculation, useParticipantScoreTable);
// updating learningGoalPerformance by summing up the points of the individual lecture unit progress
courseLearningGoalProgress.totalPointsAchievableByStudentsInLearningGoal = progressInLectureUnits.stream().map(lectureUnitProgress -> lectureUnitProgress.totalPointsAchievableByStudentsInLectureUnit).reduce(0.0, Double::sum);
courseLearningGoalProgress.averagePointsAchievedByStudentInLearningGoal = progressInLectureUnits.stream().map(lectureUnitProgress -> (lectureUnitProgress.averageScoreAchievedByStudentInLectureUnit / 100.0) * lectureUnitProgress.totalPointsAchievableByStudentsInLectureUnit).reduce(0.0, Double::sum);
courseLearningGoalProgress.progressInLectureUnits = new ArrayList<>(progressInLectureUnits);
return courseLearningGoalProgress;
}
use of de.tum.in.www1.artemis.domain.lecture in project Artemis by ls1intum.
the class DatabaseUtilService method createPostsWithAnswerPostsWithinCourse.
public List<Post> createPostsWithAnswerPostsWithinCourse() {
List<Post> posts = createPostsWithinCourse();
// add answer for one post in each context (lecture, exercise, course-wide)
Post lecturePost = posts.stream().filter(coursePost -> coursePost.getLecture() != null).findFirst().orElseThrow();
lecturePost.setAnswers(createBasicAnswers(lecturePost));
postRepository.save(lecturePost);
Post exercisePost = posts.stream().filter(coursePost -> coursePost.getExercise() != null).findFirst().orElseThrow();
exercisePost.setAnswers(createBasicAnswers(exercisePost));
postRepository.save(exercisePost);
// resolved post
Post courseWidePost = posts.stream().filter(coursePost -> coursePost.getCourseWideContext() != null).findFirst().orElseThrow();
courseWidePost.setAnswers(createBasicAnswersThatResolves(courseWidePost));
postRepository.save(courseWidePost);
return posts;
}
Aggregations