Search in sources :

Example 1 with ConflictException

use of de.tum.in.www1.artemis.web.rest.errors.ConflictException in project Artemis by ls1intum.

the class ExerciseHintResource method deleteExerciseHint.

/**
 * {@code DELETE  exercises/:exerciseId/exercise-hints/:exerciseHintId} : delete the exerciseHint with given id.
 *
 * @param exerciseHintId the id of the exerciseHint to delete
 * @param exerciseId the exercise id of which to delete the exercise hint
 * @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)},
 * or with status {@code 400 (Bad Request)} if the exerciseHint is a codeHint,
 * or with status {@code 409 (Conflict)} if the exerciseId is not valid.
 */
@DeleteMapping("exercises/{exerciseId}/exercise-hints/{exerciseHintId}")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Void> deleteExerciseHint(@PathVariable Long exerciseId, @PathVariable Long exerciseHintId) {
    log.debug("REST request to delete ExerciseHint : {}", exerciseHintId);
    ProgrammingExercise exercise = programmingExerciseRepository.findByIdElseThrow(exerciseId);
    authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, exercise, null);
    var exerciseHint = exerciseHintRepository.findByIdElseThrow(exerciseHintId);
    if (exerciseHint instanceof CodeHint) {
        throw new BadRequestAlertException("A code hint cannot be deleted manually.", CODE_HINT_ENTITY_NAME, "manualCodeHintOperation");
    }
    if (!exerciseHint.getExercise().getId().equals(exerciseId)) {
        throw new ConflictException("An exercise hint can only be deleted if the exerciseIds match.", EXERCISE_HINT_ENTITY_NAME, "exerciseIdsMismatch");
    }
    exerciseHintRepository.deleteById(exerciseHintId);
    return ResponseEntity.noContent().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, EXERCISE_HINT_ENTITY_NAME, exerciseHintId.toString())).build();
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) ConflictException(de.tum.in.www1.artemis.web.rest.errors.ConflictException) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) CodeHint(de.tum.in.www1.artemis.domain.hestia.CodeHint) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with ConflictException

use of de.tum.in.www1.artemis.web.rest.errors.ConflictException in project ArTEMiS by ls1intum.

the class ExerciseHintResource method deleteExerciseHint.

/**
 * {@code DELETE  exercises/:exerciseId/exercise-hints/:exerciseHintId} : delete the exerciseHint with given id.
 *
 * @param exerciseHintId the id of the exerciseHint to delete
 * @param exerciseId the exercise id of which to delete the exercise hint
 * @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)},
 * or with status {@code 400 (Bad Request)} if the exerciseHint is a codeHint,
 * or with status {@code 409 (Conflict)} if the exerciseId is not valid.
 */
@DeleteMapping("exercises/{exerciseId}/exercise-hints/{exerciseHintId}")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Void> deleteExerciseHint(@PathVariable Long exerciseId, @PathVariable Long exerciseHintId) {
    log.debug("REST request to delete ExerciseHint : {}", exerciseHintId);
    ProgrammingExercise exercise = programmingExerciseRepository.findByIdElseThrow(exerciseId);
    authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, exercise, null);
    var exerciseHint = exerciseHintRepository.findByIdElseThrow(exerciseHintId);
    if (exerciseHint instanceof CodeHint) {
        throw new BadRequestAlertException("A code hint cannot be deleted manually.", CODE_HINT_ENTITY_NAME, "manualCodeHintOperation");
    }
    if (!exerciseHint.getExercise().getId().equals(exerciseId)) {
        throw new ConflictException("An exercise hint can only be deleted if the exerciseIds match.", EXERCISE_HINT_ENTITY_NAME, "exerciseIdsMismatch");
    }
    exerciseHintRepository.deleteById(exerciseHintId);
    return ResponseEntity.noContent().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, EXERCISE_HINT_ENTITY_NAME, exerciseHintId.toString())).build();
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) ConflictException(de.tum.in.www1.artemis.web.rest.errors.ConflictException) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) CodeHint(de.tum.in.www1.artemis.domain.hestia.CodeHint) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with ConflictException

use of de.tum.in.www1.artemis.web.rest.errors.ConflictException in project ArTEMiS by ls1intum.

the class ApollonDiagramResource method updateApollonDiagram.

/**
 * PUT /course/{courseId}/apollon-diagrams : Updates an existing apollonDiagram.
 *
 * @param apollonDiagram the apollonDiagram to update
 * @param courseId the id of the current course
 * @return the ResponseEntity with status 200 (OK) and with body the updated apollonDiagram, or with status 201 (CREATED) if the apollonDiagram has not been created before, or with status
 *         500 (Internal Server Error) if the apollonDiagram couldn't be updated
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PutMapping("/course/{courseId}/apollon-diagrams")
@PreAuthorize("hasRole('TA')")
public ResponseEntity<ApollonDiagram> updateApollonDiagram(@RequestBody ApollonDiagram apollonDiagram, @PathVariable Long courseId) throws URISyntaxException {
    log.debug("REST request to update ApollonDiagram : {}", apollonDiagram);
    if (apollonDiagram.getId() == null) {
        return createApollonDiagram(apollonDiagram, courseId);
    }
    if (!Objects.equals(apollonDiagram.getCourseId(), courseId)) {
        throw new ConflictException("Specified course id does not match request payload", "ApollonDiagram", "courseMismatch");
    }
    Course course = courseRepository.findByIdElseThrow(courseId);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.TEACHING_ASSISTANT, course, null);
    ApollonDiagram result = apollonDiagramRepository.save(apollonDiagram);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, apollonDiagram.getId().toString())).body(result);
}
Also used : ConflictException(de.tum.in.www1.artemis.web.rest.errors.ConflictException) Course(de.tum.in.www1.artemis.domain.Course) ApollonDiagram(de.tum.in.www1.artemis.domain.modeling.ApollonDiagram) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with ConflictException

use of de.tum.in.www1.artemis.web.rest.errors.ConflictException in project ArTEMiS by ls1intum.

the class AttachmentUnitResource method getAttachmentUnit.

/**
 * GET /lectures/:lectureId/attachment-units/:attachmentUnitId : gets the attachment unit with the specified id
 *
 * @param attachmentUnitId the id of the attachmentUnit to retrieve
 * @param lectureId the id of the lecture to which the unit belongs
 * @return the ResponseEntity with status 200 (OK) and with body the attachment unit, or with status 404 (Not Found)
 */
@GetMapping("/lectures/{lectureId}/attachment-units/{attachmentUnitId}")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<AttachmentUnit> getAttachmentUnit(@PathVariable Long attachmentUnitId, @PathVariable Long lectureId) {
    log.debug("REST request to get AttachmentUnit : {}", attachmentUnitId);
    AttachmentUnit attachmentUnit = attachmentUnitRepository.findByIdElseThrow(attachmentUnitId);
    if (attachmentUnit.getLecture() == null || attachmentUnit.getLecture().getCourse() == null) {
        throw new ConflictException("Lecture unit must be associated to a lecture of a course", "AttachmentUnit", "lectureOrCourseMissing");
    }
    if (!attachmentUnit.getLecture().getId().equals(lectureId)) {
        throw new ConflictException("Requested lecture unit is not part of the specified lecture", "AttachmentUnit", "lectureIdMismatch");
    }
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, attachmentUnit.getLecture().getCourse(), null);
    return ResponseEntity.ok().body(attachmentUnit);
}
Also used : ConflictException(de.tum.in.www1.artemis.web.rest.errors.ConflictException) AttachmentUnit(de.tum.in.www1.artemis.domain.lecture.AttachmentUnit) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with ConflictException

use of de.tum.in.www1.artemis.web.rest.errors.ConflictException in project ArTEMiS by ls1intum.

the class ExerciseUnitResource method getAllExerciseUnitsOfLecture.

/**
 * GET /lectures/:lectureId/exercise-units : gets the exercise units associated with a lecture
 *
 * @param lectureId the id of the lecture to get the exercise-units for
 * @return the ResponseEntity with status 200 (OK) and with body the found exercise units
 */
@GetMapping("/lectures/{lectureId}/exercise-units")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<List<ExerciseUnit>> getAllExerciseUnitsOfLecture(@PathVariable Long lectureId) {
    log.debug("REST request to get all exercise units for lecture : {}", lectureId);
    Lecture lecture = lectureRepository.findByIdWithPostsAndLectureUnitsAndLearningGoalsElseThrow(lectureId);
    if (lecture.getCourse() == null) {
        throw new ConflictException("Specified lecture is not part of a course", "ExerciseUnit", "courseMissing");
    }
    authorizationCheckService.checkHasAtLeastRoleForLectureElseThrow(Role.EDITOR, lecture, null);
    List<ExerciseUnit> exerciseUnitsOfLecture = exerciseUnitRepository.findByLectureId(lectureId);
    return ResponseEntity.ok().body(exerciseUnitsOfLecture);
}
Also used : Lecture(de.tum.in.www1.artemis.domain.Lecture) ExerciseUnit(de.tum.in.www1.artemis.domain.lecture.ExerciseUnit) ConflictException(de.tum.in.www1.artemis.web.rest.errors.ConflictException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ConflictException (de.tum.in.www1.artemis.web.rest.errors.ConflictException)62 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)58 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)18 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)18 URI (java.net.URI)18 Lecture (de.tum.in.www1.artemis.domain.Lecture)12 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)10 BadRequestException (javax.ws.rs.BadRequestException)10 Exam (de.tum.in.www1.artemis.domain.exam.Exam)8 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)8 CodeHint (de.tum.in.www1.artemis.domain.hestia.CodeHint)8 ProgrammingExerciseSolutionEntry (de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseSolutionEntry)8 AttachmentUnit (de.tum.in.www1.artemis.domain.lecture.AttachmentUnit)8 ExerciseUnit (de.tum.in.www1.artemis.domain.lecture.ExerciseUnit)8 Course (de.tum.in.www1.artemis.domain.Course)6 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)6 TextUnit (de.tum.in.www1.artemis.domain.lecture.TextUnit)6 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)6 Exercise (de.tum.in.www1.artemis.domain.Exercise)4 ProgrammingExerciseTestCase (de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase)4