Search in sources :

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

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

the class LectureResource method getLectureWithDetails.

/**
 * GET /lectures/:lectureId/details : get the "lectureId" lecture.
 *
 * @param lectureId the lectureId of the lecture to retrieve
 * @return the ResponseEntity with status 200 (OK) and with body the lecture including posts, lecture units and learning goals, or with status 404 (Not Found)
 */
@GetMapping("/lectures/{lectureId}/details")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Lecture> getLectureWithDetails(@PathVariable Long lectureId) {
    log.debug("REST request to get lecture {} with details", lectureId);
    Lecture lecture = lectureRepository.findByIdWithPostsAndLectureUnitsAndLearningGoalsElseThrow(lectureId);
    Course course = lecture.getCourse();
    if (course == null) {
        return ResponseEntity.badRequest().build();
    }
    User user = userRepository.getUserWithGroupsAndAuthorities();
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
    lecture = filterLectureContentForUser(lecture, user);
    return ResponseEntity.ok(lecture);
}
Also used : Lecture(de.tum.in.www1.artemis.domain.Lecture) User(de.tum.in.www1.artemis.domain.User) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

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

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

the class LectureResource method createLecture.

/**
 * POST /lectures : Create a new lecture.
 *
 * @param lecture the lecture to create
 * @return the ResponseEntity with status 201 (Created) and with body the new lecture, or with status 400 (Bad Request) if the lecture has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/lectures")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Lecture> createLecture(@RequestBody Lecture lecture) throws URISyntaxException {
    log.debug("REST request to save Lecture : {}", lecture);
    if (lecture.getId() != null) {
        throw new BadRequestAlertException("A new lecture cannot already have an ID", ENTITY_NAME, "idexists");
    }
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, lecture.getCourse(), null);
    Lecture result = lectureRepository.save(lecture);
    return ResponseEntity.created(new URI("/api/lectures/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) Lecture(de.tum.in.www1.artemis.domain.Lecture) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

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

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

the class LearningGoalIntegrationTest method creatingLectureUnitsOfLectureOne.

private void creatingLectureUnitsOfLectureOne() {
    // creating lecture units for lecture one
    TextUnit textUnit = new TextUnit();
    textUnit.setName("TextUnitOfLectureOne");
    textUnit = textUnitRepository.save(textUnit);
    idOfTextUnitOfLectureOne = textUnit.getId();
    Exercise textExercise = exerciseRepository.findById(idOfTextExercise).get();
    ExerciseUnit textExerciseUnit = new ExerciseUnit();
    textExerciseUnit.setExercise(textExercise);
    textExerciseUnit = exerciseUnitRepository.save(textExerciseUnit);
    idOfExerciseUnitTextOfLectureOne = textExerciseUnit.getId();
    Exercise modelingExercise = exerciseRepository.findById(idOfModelingExercise).get();
    ExerciseUnit modelingExerciseUnit = new ExerciseUnit();
    modelingExerciseUnit.setExercise(modelingExercise);
    modelingExerciseUnit = exerciseUnitRepository.save(modelingExerciseUnit);
    idOfExerciseUnitModelingOfLectureOne = modelingExerciseUnit.getId();
    Exercise textTeamExercise = exerciseRepository.findById(idOfTeamTextExercise).get();
    ExerciseUnit teamTextExerciseUnit = new ExerciseUnit();
    teamTextExerciseUnit.setExercise(textTeamExercise);
    teamTextExerciseUnit = exerciseUnitRepository.save(teamTextExerciseUnit);
    List<LectureUnit> lectureUnitsOfLectureOne = List.of(textUnit, textExerciseUnit, modelingExerciseUnit, teamTextExerciseUnit);
    Lecture lectureOne = lectureRepository.findByIdWithPostsAndLectureUnitsAndLearningGoals(idOfLectureOne).get();
    for (LectureUnit lectureUnit : lectureUnitsOfLectureOne) {
        lectureOne.addLectureUnit(lectureUnit);
    }
    lectureRepository.save(lectureOne);
}
Also used : QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) TextUnit(de.tum.in.www1.artemis.domain.lecture.TextUnit)

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

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

the class TextUnitIntegrationTest method updateTextUnit_asEditor_shouldKeepOrdering.

@Test
@WithMockUser(username = "editor1", roles = "EDITOR")
public void updateTextUnit_asEditor_shouldKeepOrdering() throws Exception {
    persistTextUnitWithLecture();
    // Add a second lecture unit
    TextUnit textUnit = database.createTextUnit();
    lecture.addLectureUnit(textUnit);
    lecture = lectureRepository.save(lecture);
    List<LectureUnit> orderedUnits = lecture.getLectureUnits();
    // Updating the lecture unit should not change order attribute
    request.putWithResponseBody("/api/lectures/" + lecture.getId() + "/text-units", textUnit, TextUnit.class, HttpStatus.OK);
    List<LectureUnit> updatedOrderedUnits = lectureRepository.findByIdWithLectureUnits(lecture.getId()).get().getLectureUnits();
    assertThat(updatedOrderedUnits).containsExactlyElementsOf(orderedUnits);
}
Also used : LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) TextUnit(de.tum.in.www1.artemis.domain.lecture.TextUnit) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

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

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

the class LectureImportServiceTest method testImportLectureToCourse.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testImportLectureToCourse() {
    int lectureCount = this.course2.getLectures().size();
    lectureImportService.importLecture(this.lecture1, this.course2);
    assertThat(this.course2.getLectures().size()).isEqualTo(lectureCount + 1);
    // Find the imported lecture and fetch it with lecture units
    Long lecture2Id = this.course2.getLectures().stream().skip(lectureCount).findFirst().get().getId();
    Lecture lecture2 = this.lectureRepository.findByIdWithLectureUnitsElseThrow(lecture2Id);
    assertThat(lecture2.getTitle()).isEqualTo(this.lecture1.getTitle());
    // Assert that all lecture units (except exercise units) were copied
    assertThat(lecture2.getLectureUnits().stream().map(LectureUnit::getName).toList()).containsExactlyElementsOf(this.lecture1.getLectureUnits().stream().filter(lectureUnit -> !(lectureUnit instanceof ExerciseUnit)).map(LectureUnit::getName).toList());
    assertThat(lecture2.getAttachments().stream().map(Attachment::getName).toList()).containsExactlyElementsOf(this.lecture1.getAttachments().stream().map(Attachment::getName).toList());
    lectureRepository.delete(lecture2);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CourseRepository(de.tum.in.www1.artemis.repository.CourseRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Course(de.tum.in.www1.artemis.domain.Course) Autowired(org.springframework.beans.factory.annotation.Autowired) Lecture(de.tum.in.www1.artemis.domain.Lecture) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Attachment(de.tum.in.www1.artemis.domain.Attachment) WithMockUser(org.springframework.security.test.context.support.WithMockUser) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit) LectureRepository(de.tum.in.www1.artemis.repository.LectureRepository) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Lecture(de.tum.in.www1.artemis.domain.Lecture) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit) LectureUnit(de.tum.in.www1.artemis.domain.lecture.LectureUnit) Attachment(de.tum.in.www1.artemis.domain.Attachment) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

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