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