Search in sources :

Example 6 with LearningGoal

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

the class LearningGoalResource method getLearningGoals.

/**
 * GET /courses/:courseId/goals : gets all the learning goals of a course
 * @param courseId the id of the course for which the learning goals should be fetched
 * @return the ResponseEntity with status 200 (OK) and with body the found learning goals
 */
@GetMapping("/courses/{courseId}/goals")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<List<LearningGoal>> getLearningGoals(@PathVariable Long courseId) {
    log.debug("REST request to get learning goals for course with id: {}", courseId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
    Set<LearningGoal> learningGoals = learningGoalRepository.findAllByCourseIdWithLectureUnitsUnidirectional(courseId);
    // if the user is a student the not yet released lecture units need to be filtered out
    if (authorizationCheckService.isOnlyStudentInCourse(course, user)) {
        for (LearningGoal learningGoal : learningGoals) {
            Set<LectureUnit> visibleLectureUnits = learningGoal.getLectureUnits().parallelStream().filter(LectureUnit::isVisibleToStudents).collect(Collectors.toSet());
            learningGoal.setLectureUnits(visibleLectureUnits);
        }
    }
    return ResponseEntity.ok(new ArrayList<>(learningGoals));
}
Also used : User(de.tum.in.www1.artemis.domain.User) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) LearningGoal(de.tum.in.www1.artemis.domain.LearningGoal) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 7 with LearningGoal

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

the class LearningGoalIntegrationTest method updateLearningGoal_asInstructor_shouldUpdateLearningGoal.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateLearningGoal_asInstructor_shouldUpdateLearningGoal() throws Exception {
    LearningGoal existingLearningGoal = learningGoalRepository.findByIdWithLectureUnitsBidirectionalElseThrow(idOfLearningGoal);
    LectureUnit textLectureUnit = lectureUnitRepository.findByIdWithLearningGoalsBidirectionalElseThrow(idOfTextUnitOfLectureOne);
    existingLearningGoal.setTitle("Updated");
    existingLearningGoal.removeLectureUnit(textLectureUnit);
    existingLearningGoal.setDescription("Updated Description");
    LearningGoal updatedLearningGoal = request.putWithResponseBody("/api/courses/" + idOfCourse + "/goals", existingLearningGoal, LearningGoal.class, HttpStatus.OK);
    assertThat(updatedLearningGoal.getTitle()).isEqualTo("Updated");
    assertThat(updatedLearningGoal.getDescription()).isEqualTo("Updated Description");
    assertThat(updatedLearningGoal.getLectureUnits().stream().map(DomainObject::getId).collect(Collectors.toSet())).doesNotContain(textLectureUnit.getId());
}
Also used : LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 8 with LearningGoal

use of de.tum.in.www1.artemis.domain.LearningGoal in project Artemis by ls1intum.

the class LectureUnitService method disconnectLectureUnitAndLearningGoal.

/**
 * Remove connection between lecture unit and learning goal in the database
 *
 * @param lectureUnit  Lecture unit connected to learning goal
 * @param learningGoal Learning goal connected to lecture unit
 */
public void disconnectLectureUnitAndLearningGoal(LectureUnit lectureUnit, LearningGoal learningGoal) {
    Optional<LearningGoal> learningGoalFromDbOptional = learningGoalRepository.findByIdWithLectureUnitsBidirectional(learningGoal.getId());
    if (learningGoalFromDbOptional.isPresent()) {
        LearningGoal learningGoalFromDb = learningGoalFromDbOptional.get();
        learningGoalFromDb.removeLectureUnit(lectureUnit);
        learningGoalRepository.save(learningGoalFromDb);
    }
}
Also used : LearningGoal(de.tum.in.www1.artemis.domain.LearningGoal)

Example 9 with LearningGoal

use of de.tum.in.www1.artemis.domain.LearningGoal in project Artemis by ls1intum.

the class LearningGoalIntegrationTest method updateLearningGoal_asInstructor_shouldUpdateLearningGoal.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateLearningGoal_asInstructor_shouldUpdateLearningGoal() throws Exception {
    LearningGoal existingLearningGoal = learningGoalRepository.findByIdWithLectureUnitsBidirectionalElseThrow(idOfLearningGoal);
    LectureUnit textLectureUnit = lectureUnitRepository.findByIdWithLearningGoalsBidirectionalElseThrow(idOfTextUnitOfLectureOne);
    existingLearningGoal.setTitle("Updated");
    existingLearningGoal.removeLectureUnit(textLectureUnit);
    existingLearningGoal.setDescription("Updated Description");
    LearningGoal updatedLearningGoal = request.putWithResponseBody("/api/courses/" + idOfCourse + "/goals", existingLearningGoal, LearningGoal.class, HttpStatus.OK);
    assertThat(updatedLearningGoal.getTitle()).isEqualTo("Updated");
    assertThat(updatedLearningGoal.getDescription()).isEqualTo("Updated Description");
    assertThat(updatedLearningGoal.getLectureUnits().stream().map(DomainObject::getId).collect(Collectors.toSet())).doesNotContain(textLectureUnit.getId());
}
Also used : LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 10 with LearningGoal

use of de.tum.in.www1.artemis.domain.LearningGoal in project Artemis by ls1intum.

the class ParticipantScoreIntegrationTest method setupTestScenario.

@BeforeEach
public void setupTestScenario() {
    ZonedDateTime pastTimestamp = ZonedDateTime.now().minusDays(5);
    // creating the users student1-student5, tutor1-tutor10 and instructors1-instructor10
    this.database.addUsers(5, 10, 0, 10);
    // creating course
    Course course = this.database.createCourse();
    Lecture lecture = new Lecture();
    lecture.setTitle("ExampleLecture");
    lecture.setCourse(course);
    lecture = lectureRepository.saveAndFlush(lecture);
    idOfCourse = course.getId();
    TextExercise textExercise = database.createIndividualTextExercise(course, pastTimestamp, pastTimestamp, pastTimestamp);
    ExerciseUnit exerciseUnit = database.createExerciseUnit(textExercise);
    database.addLectureUnitsToLecture(lecture, Set.of(exerciseUnit));
    lecture = lectureRepository.findByIdWithPostsAndLectureUnitsAndLearningGoals(lecture.getId()).get();
    exerciseUnit = (ExerciseUnit) lecture.getLectureUnits().get(0);
    idOfExerciseUnit = exerciseUnit.getId();
    LearningGoal learningGoal = new LearningGoal();
    learningGoal.setTitle("ExampleLearningGoal");
    learningGoal.setCourse(course);
    learningGoal.addLectureUnit(exerciseUnit);
    learningGoalRepository.saveAndFlush(learningGoal);
    idOfIndividualTextExercise = textExercise.getId();
    Exercise teamExercise = database.createTeamTextExercise(course, pastTimestamp, pastTimestamp, pastTimestamp);
    idOfTeamTextExercise = teamExercise.getId();
    User student1 = userRepository.findOneByLogin("student1").get();
    idOfStudent1 = student1.getId();
    User tutor1 = userRepository.findOneByLogin("tutor1").get();
    idOfTeam1 = database.createTeam(Set.of(student1), tutor1, teamExercise, "team1").getId();
    // Creating result for student1
    database.createParticipationSubmissionAndResult(idOfIndividualTextExercise, student1, 10.0, 10.0, 50, true);
    // Creating result for team1
    Team team = teamRepository.findById(idOfTeam1).get();
    database.createParticipationSubmissionAndResult(idOfTeamTextExercise, team, 10.0, 10.0, 50, true);
    // setting up exam
    Exam exam = ModelFactory.generateExam(course);
    ModelFactory.generateExerciseGroup(true, exam);
    exam.addRegisteredUser(student1);
    exam = examRepository.save(exam);
    idOfExam = exam.getId();
    createIndividualTextExerciseForExam();
    database.createParticipationSubmissionAndResult(getIdOfIndividualTextExerciseOfExam, student1, 10.0, 10.0, 50, true);
}
Also used : ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ZonedDateTime(java.time.ZonedDateTime) Exam(de.tum.in.www1.artemis.domain.exam.Exam) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

LectureUnit (de.tum.in.www1.artemis.domain.lecture.LectureUnit)16 LearningGoal (de.tum.in.www1.artemis.domain.LearningGoal)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Course (de.tum.in.www1.artemis.domain.Course)8 CourseLearningGoalProgress (de.tum.in.www1.artemis.web.rest.dto.CourseLearningGoalProgress)8 User (de.tum.in.www1.artemis.domain.User)6 ExerciseUnit (de.tum.in.www1.artemis.domain.lecture.ExerciseUnit)6 IndividualLearningGoalProgress (de.tum.in.www1.artemis.web.rest.dto.IndividualLearningGoalProgress)6 java.util (java.util)6 Collectors (java.util.stream.Collectors)6 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)4 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)4 ParticipantScore (de.tum.in.www1.artemis.domain.scores.ParticipantScore)4 StudentScore (de.tum.in.www1.artemis.domain.scores.StudentScore)4 TeamScore (de.tum.in.www1.artemis.domain.scores.TeamScore)4 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)4 CourseExerciseStatisticsDTO (de.tum.in.www1.artemis.web.rest.dto.CourseExerciseStatisticsDTO)4 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)4 URI (java.net.URI)4 Stream (java.util.stream.Stream)4