Search in sources :

Example 1 with de.tum.in.www1.artemis.domain.lecture

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());
}
Also used : Lecture(de.tum.in.www1.artemis.domain.Lecture) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) AttachmentUnit(de.tum.in.www1.artemis.domain.lecture.AttachmentUnit) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with de.tum.in.www1.artemis.domain.lecture

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);
}
Also used : TextUnit(de.tum.in.www1.artemis.domain.lecture.TextUnit) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 3 with de.tum.in.www1.artemis.domain.lecture

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);
}
Also used : TextUnit(de.tum.in.www1.artemis.domain.lecture.TextUnit) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 4 with de.tum.in.www1.artemis.domain.lecture

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;
}
Also used : java.util(java.util) TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) Collectors(java.util.stream.Collectors) CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) Stream(java.util.stream.Stream) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) Service(org.springframework.stereotype.Service) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit) CourseExerciseStatisticsDTO(de.tum.in.www1.artemis.web.rest.dto.CourseExerciseStatisticsDTO) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) IndividualLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.IndividualLearningGoalProgress) CourseLearningGoalProgress(de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit)

Example 5 with de.tum.in.www1.artemis.domain.lecture

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

Aggregations

PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)50 Lecture (de.tum.in.www1.artemis.domain.Lecture)42 LectureUnit (de.tum.in.www1.artemis.domain.lecture.LectureUnit)34 WithMockUser (org.springframework.security.test.context.support.WithMockUser)32 Post (de.tum.in.www1.artemis.domain.metis.Post)31 Test (org.junit.jupiter.api.Test)30 ConflictException (de.tum.in.www1.artemis.web.rest.errors.ConflictException)28 ExerciseUnit (de.tum.in.www1.artemis.domain.lecture.ExerciseUnit)22 Course (de.tum.in.www1.artemis.domain.Course)20 TextUnit (de.tum.in.www1.artemis.domain.lecture.TextUnit)18 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)18 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)16 AttachmentUnit (de.tum.in.www1.artemis.domain.lecture.AttachmentUnit)16 URI (java.net.URI)14 User (de.tum.in.www1.artemis.domain.User)13 BadRequestException (javax.ws.rs.BadRequestException)12 BeforeEach (org.junit.jupiter.api.BeforeEach)12 LearningGoal (de.tum.in.www1.artemis.domain.LearningGoal)10 AnswerPost (de.tum.in.www1.artemis.domain.metis.AnswerPost)10 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)10