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