Search in sources :

Example 1 with CourseAssessmentRequest

use of fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest in project pyramus by otavanopisto.

the class StudentRESTService method deleteCourseAssessmentRequest.

@Path("/students/{STUDENTID:[0-9]*}/courses/{COURSEID}/assessmentRequests/{ID}")
@DELETE
@RESTPermit(handling = Handling.INLINE)
public Response deleteCourseAssessmentRequest(@PathParam("STUDENTID") Long studentId, @PathParam("COURSEID") Long courseId, @PathParam("ID") Long id) {
    Student student = studentController.findStudentById(studentId);
    Course course = courseController.findCourseById(courseId);
    Status studentStatus = checkStudent(student);
    if (studentStatus != Status.OK)
        return Response.status(studentStatus).build();
    if (course == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (course.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!restSecurity.hasPermission(new String[] { CourseAssessmentPermissions.DELETE_COURSEASSESSMENTREQUEST, StudentPermissions.STUDENT_OWNER }, student, Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    CourseAssessmentRequest courseAssessmentRequest = assessmentController.findCourseAssessmentRequestById(id);
    if (courseAssessmentRequest == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!course.getId().equals(courseAssessmentRequest.getCourseStudent().getCourse().getId())) {
        return Response.status(Status.BAD_REQUEST).entity("Course ids mismatch.").build();
    }
    if (!student.getId().equals(courseAssessmentRequest.getCourseStudent().getStudent().getId())) {
        return Response.status(Status.BAD_REQUEST).entity("Student ids mismatch.").build();
    }
    assessmentController.deleteCourseAssessmentRequest(courseAssessmentRequest);
    return Response.noContent().build();
}
Also used : Status(javax.ws.rs.core.Response.Status) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit)

Example 2 with CourseAssessmentRequest

use of fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest in project pyramus by otavanopisto.

the class StudentRESTService method updateCourseAssessmentRequest.

@Path("/students/{STUDENTID:[0-9]*}/courses/{COURSEID:[0-9]*}/assessmentRequests/{ID:[0-9]*}")
@PUT
@RESTPermit(handling = Handling.INLINE)
public Response updateCourseAssessmentRequest(@PathParam("STUDENTID") Long studentId, @PathParam("COURSEID") Long courseId, @PathParam("ID") Long id, fi.otavanopisto.pyramus.rest.model.CourseAssessmentRequest entity) {
    Student student = studentController.findStudentById(studentId);
    Course course = courseController.findCourseById(courseId);
    CourseAssessmentRequest courseAssessmentRequest = assessmentController.findCourseAssessmentRequestById(id);
    if (courseAssessmentRequest == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (entity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Status studentStatus = checkStudent(student);
    if (studentStatus != Status.OK)
        return Response.status(studentStatus).build();
    if (course == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (course.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!course.getId().equals(courseAssessmentRequest.getCourseStudent().getCourse().getId())) {
        return Response.status(Status.BAD_REQUEST).entity("Course ids mismatch.").build();
    }
    if (!student.getId().equals(courseAssessmentRequest.getCourseStudent().getStudent().getId())) {
        return Response.status(Status.BAD_REQUEST).entity("Student ids mismatch.").build();
    }
    if (!courseAssessmentRequest.getCourseStudent().getId().equals(entity.getCourseStudentId())) {
        return Response.status(Status.BAD_REQUEST).entity("CourseAssessmentRequest ids mismatch.").build();
    }
    if (!restSecurity.hasPermission(new String[] { CourseAssessmentPermissions.UPDATE_COURSEASSESSMENTREQUEST, StudentPermissions.STUDENT_OWNER }, student, Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    CourseAssessmentRequest updatedCourseAssessmentRequest = assessmentController.updateCourseAssessmentRequest(courseAssessmentRequest, Date.from(entity.getCreated().toInstant()), entity.getRequestText(), entity.getArchived(), entity.getHandled());
    return Response.ok(objectFactory.createModel(updatedCourseAssessmentRequest)).build();
}
Also used : Status(javax.ws.rs.core.Response.Status) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) PUT(javax.ws.rs.PUT)

Example 3 with CourseAssessmentRequest

use of fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest in project pyramus by otavanopisto.

the class StudentRESTService method listCourseAssessmentRequests.

@Path("/students/{STUDENTID:[0-9]*}/courses/{COURSEID:[0-9]*}/assessmentRequests/")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response listCourseAssessmentRequests(@PathParam("STUDENTID") Long studentId, @PathParam("COURSEID") Long courseId) {
    Student student = studentController.findStudentById(studentId);
    Status studentStatus = checkStudent(student);
    if (studentStatus != Status.OK)
        return Response.status(studentStatus).build();
    if (!restSecurity.hasPermission(new String[] { CourseAssessmentPermissions.LIST_COURSEASSESSMENTREQUESTS, PersonPermissions.PERSON_OWNER }, student.getPerson(), Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    Course course = courseController.findCourseById(courseId);
    if (course == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (course.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    List<CourseAssessmentRequest> assessmentRequests = assessmentController.listCourseAssessmentRequestsByCourseAndStudent(course, student);
    return Response.ok(objectFactory.createModel(assessmentRequests)).build();
}
Also used : Status(javax.ws.rs.core.Response.Status) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 4 with CourseAssessmentRequest

use of fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest in project pyramus by otavanopisto.

the class StudentRESTService method findLatestStudentAssessmentRequest.

@Path("/students/{STUDENTID:[0-9]*}/latestAssessmentRequest/")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response findLatestStudentAssessmentRequest(@PathParam("STUDENTID") Long studentId) {
    Student student = studentController.findStudentById(studentId);
    if (student == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (student.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!restSecurity.hasPermission(new String[] { CourseAssessmentPermissions.LIST_COURSEASSESSMENTREQUESTS, StudentPermissions.STUDENT_OWNER }, student, Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    List<CourseAssessmentRequest> assessmentRequests = assessmentController.listCourseAssessmentRequestsByStudent(student);
    if (CollectionUtils.isEmpty(assessmentRequests)) {
        return Response.status(Status.NOT_FOUND).build();
    }
    Collections.sort(assessmentRequests, new Comparator<CourseAssessmentRequest>() {

        public int compare(CourseAssessmentRequest o1, CourseAssessmentRequest o2) {
            return o2.getCreated().compareTo(o1.getCreated());
        }
    });
    return Response.ok(objectFactory.createModel(assessmentRequests.get(0))).build();
}
Also used : CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 5 with CourseAssessmentRequest

use of fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest in project pyramus by otavanopisto.

the class StudentRESTService method createCourseAssessmentRequest.

@Path("/students/{STUDENTID:[0-9]*}/courses/{COURSEID:[0-9]*}/assessmentRequests/")
@POST
@RESTPermit(handling = Handling.INLINE)
public Response createCourseAssessmentRequest(@PathParam("STUDENTID") Long studentId, @PathParam("COURSEID") Long courseId, fi.otavanopisto.pyramus.rest.model.CourseAssessmentRequest entity) {
    if (entity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Student student = studentController.findStudentById(studentId);
    Status studentStatus = checkStudent(student);
    if (studentStatus != Status.OK)
        return Response.status(studentStatus).build();
    Course course = courseController.findCourseById(courseId);
    if (course == null) {
        return Response.status(Status.NOT_FOUND).entity("Could not find course").build();
    }
    if (course.getArchived()) {
        return Response.status(Status.NOT_FOUND).entity("Course is archived").build();
    }
    if (!restSecurity.hasPermission(new String[] { CourseAssessmentPermissions.CREATE_COURSEASSESSMENTREQUEST, StudentPermissions.STUDENT_OWNER }, student, Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    CourseStudent courseStudent = courseController.findCourseStudentById(entity.getCourseStudentId());
    if (courseStudent == null) {
        return Response.status(Status.BAD_REQUEST).entity("Could not find coursestudent").build();
    }
    if (courseStudent.getArchived()) {
        return Response.status(Status.BAD_REQUEST).entity("Coursestudent is archived").build();
    }
    if (!courseStudent.getStudent().getId().equals(student.getId())) {
        return Response.status(Status.BAD_REQUEST).entity("Coursestudent doesnt match student").build();
    }
    if (!courseStudent.getCourse().getId().equals(course.getId())) {
        return Response.status(Status.BAD_REQUEST).entity("Coursestudent doesnt match course").build();
    }
    CourseAssessmentRequest courseAssessmentRequest = assessmentController.createCourseAssessmentRequest(courseStudent, Date.from(entity.getCreated().toInstant()), entity.getRequestText());
    return Response.ok(objectFactory.createModel(courseAssessmentRequest)).build();
}
Also used : Status(javax.ws.rs.core.Response.Status) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) POST(javax.ws.rs.POST)

Aggregations

CourseAssessmentRequest (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest)25 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)19 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)12 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)10 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)10 Path (javax.ws.rs.Path)10 StudentGroupStudent (fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent)8 EntityManager (javax.persistence.EntityManager)7 GET (javax.ws.rs.GET)7 CourseAssessment (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment)6 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 ArrayList (java.util.ArrayList)5 Status (javax.ws.rs.core.Response.Status)5 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)4 CourseAssessmentRequestDAO (fi.otavanopisto.pyramus.dao.grading.CourseAssessmentRequestDAO)4 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)4 CreditLink (fi.otavanopisto.pyramus.domainmodel.grading.CreditLink)3 TransferCredit (fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit)3 HashMap (java.util.HashMap)3 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)2