Search in sources :

Example 1 with RESTPermit

use of fi.otavanopisto.pyramus.rest.annotation.RESTPermit in project pyramus by otavanopisto.

the class StudentPhoneNumberRESTService method listStudentPhoneNumbers.

@Path("/")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response listStudentPhoneNumbers(@PathParam("STUDENTID") Long studentId) {
    Student student = studentController.findStudentById(studentId);
    Status studentStatus = checkStudent(student);
    if (studentStatus != Status.OK) {
        return Response.status(studentStatus).build();
    }
    if (!restSecurity.hasPermission(new String[] { StudentPermissions.LIST_STUDENTPHONENUMBERS }, student) && !restSecurity.hasPermission(new String[] { PersonPermissions.PERSON_OWNER }, student.getPerson())) {
        return Response.status(Status.FORBIDDEN).build();
    }
    List<PhoneNumber> phoneNumbers = student.getContactInfo().getPhoneNumbers();
    if (phoneNumbers.isEmpty()) {
        return Response.noContent().build();
    }
    return Response.ok(objectFactory.createModel(phoneNumbers)).build();
}
Also used : Status(javax.ws.rs.core.Response.Status) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 2 with RESTPermit

use of fi.otavanopisto.pyramus.rest.annotation.RESTPermit in project pyramus by otavanopisto.

the class StudentPhoneNumberRESTService method deleteStudentPhoneNumber.

@Path("/{ID:[0-9]*}")
@DELETE
@RESTPermit(StudentPermissions.DELETE_STUDENTPHONENUMBER)
public Response deleteStudentPhoneNumber(@PathParam("STUDENTID") Long studentId, @PathParam("ID") Long id) {
    Student student = studentController.findStudentById(studentId);
    Status studentStatus = checkStudent(student);
    if (studentStatus != Status.OK) {
        return Response.status(studentStatus).build();
    }
    PhoneNumber phoneNumber = commonController.findPhoneNumberById(id);
    if (phoneNumber == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!phoneNumber.getContactInfo().getId().equals(student.getContactInfo().getId())) {
        return Response.status(Status.NOT_FOUND).build();
    }
    commonController.deletePhoneNumber(phoneNumber);
    return Response.noContent().build();
}
Also used : Status(javax.ws.rs.core.Response.Status) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit)

Example 3 with RESTPermit

use of fi.otavanopisto.pyramus.rest.annotation.RESTPermit in project pyramus by otavanopisto.

the class StudentRESTService method findStudentGroupStaffMember.

@Path("/studentGroups/{GROUPID:[0-9]*}/staffmembers/{ID:[0-9]*}")
@GET
@RESTPermit(StudentGroupPermissions.FIND_STUDENTGROUPSTAFFMEMBER)
public Response findStudentGroupStaffMember(@PathParam("GROUPID") Long studentGroupId, @PathParam("ID") Long id) {
    StudentGroup studentGroup = studentGroupController.findStudentGroupById(studentGroupId);
    if (studentGroup == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (studentGroup.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!UserUtils.canAccessOrganization(sessionController.getUser(), studentGroup.getOrganization())) {
        return Response.status(Status.FORBIDDEN).build();
    }
    StudentGroupUser studentGroupUser = studentGroupController.findStudentGroupUserById(id);
    if (studentGroupUser == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!studentGroupUser.getStudentGroup().getId().equals(studentGroup.getId())) {
        return Response.status(Status.NOT_FOUND).build();
    }
    return Response.ok(objectFactory.createModel(studentGroupUser)).build();
}
Also used : StudentGroupUser(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupUser) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 4 with RESTPermit

use of fi.otavanopisto.pyramus.rest.annotation.RESTPermit in project pyramus by otavanopisto.

the class StudentRESTService method findLatestStudentWorkspaceAssessment.

@Path("/students/{STUDENTID:[0-9]*}/latestCourseAssessment/")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response findLatestStudentWorkspaceAssessment(@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_ALL_STUDENT_COURSEASSESSMENTS, PersonPermissions.PERSON_OWNER }, student.getPerson(), Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    List<CourseAssessment> courseAssessments = assessmentController.listByStudent(student);
    if (CollectionUtils.isEmpty(courseAssessments)) {
        return Response.status(Status.NOT_FOUND).build();
    }
    Collections.sort(courseAssessments, new Comparator<CourseAssessment>() {

        public int compare(CourseAssessment o1, CourseAssessment o2) {
            return o2.getDate().compareTo(o1.getDate());
        }
    });
    return Response.ok(objectFactory.createModel(courseAssessments.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) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 5 with RESTPermit

use of fi.otavanopisto.pyramus.rest.annotation.RESTPermit in project pyramus by otavanopisto.

the class StudentRESTService method listStudentAssessments.

@Path("/students/{STUDENTID:[0-9]*}/assessments/")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response listStudentAssessments(@PathParam("STUDENTID") Long studentId) {
    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_ALL_STUDENT_COURSEASSESSMENTS, StudentPermissions.STUDENT_OWNER }, student, Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    List<CourseAssessment> assessments = assessmentController.listByStudent(student);
    return Response.ok(objectFactory.createModel(assessments)).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) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)233 Path (javax.ws.rs.Path)232 GET (javax.ws.rs.GET)94 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)68 PUT (javax.ws.rs.PUT)53 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)51 POST (javax.ws.rs.POST)51 StudentGroupStudent (fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent)47 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)45 Status (javax.ws.rs.core.Response.Status)41 DELETE (javax.ws.rs.DELETE)38 User (fi.otavanopisto.pyramus.domainmodel.users.User)29 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)26 School (fi.otavanopisto.pyramus.domainmodel.base.School)20 Date (java.util.Date)20 StudentGroup (fi.otavanopisto.pyramus.domainmodel.students.StudentGroup)19 StudentGroupUser (fi.otavanopisto.pyramus.domainmodel.students.StudentGroupUser)15 ArrayList (java.util.ArrayList)15 Email (fi.otavanopisto.pyramus.domainmodel.base.Email)14 EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)13