Search in sources :

Example 11 with SectionResourceLinks

use of com.remswork.project.alice.resource.links.SectionResourceLinks in project classify-system by anverliedoit.

the class StudentResource method addStudent.

@POST
public Response addStudent(Student student) {
    try {
        StudentResourceLinks resourceLinks = new StudentResourceLinks(uriInfo);
        SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        student = studentService.addStudent(student, sectionId);
        student.addLink(resourceLinks.self(student.getId()));
        if (student.getSection() != null) {
            Section section = student.getSection();
            section.addLink(sectionResourceLinks.self(section.getId()));
            if (section.getDepartment() != null)
                section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
        }
        return Response.status(Response.Status.CREATED).entity(student).build();
    } catch (StudentException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : StudentException(com.remswork.project.alice.exception.StudentException) Message(com.remswork.project.alice.model.support.Message) StudentResourceLinks(com.remswork.project.alice.resource.links.StudentResourceLinks) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Example 12 with SectionResourceLinks

use of com.remswork.project.alice.resource.links.SectionResourceLinks in project classify-system by anverliedoit.

the class StudentResource method updateStudentById.

@PUT
@Path("{studentId}")
public Response updateStudentById(@PathParam("studentId") long id, Student newStudent) {
    try {
        StudentResourceLinks resourceLinks = new StudentResourceLinks(uriInfo);
        SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        Student student = studentService.updateStudentById(id, newStudent, sectionId);
        student.addLink(resourceLinks.self(id));
        if (student.getSection() != null) {
            Section section = student.getSection();
            section.addLink(sectionResourceLinks.self(section.getId()));
            if (section.getDepartment() != null)
                section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
        }
        return Response.status(Response.Status.OK).entity(student).build();
    } catch (StudentException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : StudentException(com.remswork.project.alice.exception.StudentException) Message(com.remswork.project.alice.model.support.Message) StudentResourceLinks(com.remswork.project.alice.resource.links.StudentResourceLinks) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) Student(com.remswork.project.alice.model.Student) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Example 13 with SectionResourceLinks

use of com.remswork.project.alice.resource.links.SectionResourceLinks in project classify-system by anverliedoit.

the class StudentResource method getStudentById.

@GET
@Path("{studentId}")
public Response getStudentById(@PathParam("studentId") long id) {
    try {
        StudentResourceLinks resourceLinks = new StudentResourceLinks(uriInfo);
        SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        Student student = studentService.getStudentById(id);
        student.addLink(resourceLinks.self(id));
        if (student.getSection() != null) {
            Section section = student.getSection();
            section.addLink(sectionResourceLinks.self(section.getId()));
            if (section.getDepartment() != null)
                section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
        }
        return Response.status(Response.Status.OK).entity(student).build();
    } catch (StudentException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : StudentException(com.remswork.project.alice.exception.StudentException) Message(com.remswork.project.alice.model.support.Message) StudentResourceLinks(com.remswork.project.alice.resource.links.StudentResourceLinks) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) Student(com.remswork.project.alice.model.Student) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Example 14 with SectionResourceLinks

use of com.remswork.project.alice.resource.links.SectionResourceLinks in project classify-system by anverliedoit.

the class StudentResource method deleteStudentById.

@DELETE
@Path("{studentId}")
public Response deleteStudentById(@PathParam("studentId") long id) {
    try {
        StudentResourceLinks resourceLinks = new StudentResourceLinks(uriInfo);
        SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        Student student = studentService.deleteStudentById(id);
        student.addLink(resourceLinks.self(id));
        if (student.getSection() != null) {
            Section section = student.getSection();
            section.addLink(sectionResourceLinks.self(section.getId()));
            if (section.getDepartment() != null)
                section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
        }
        return Response.status(Response.Status.OK).entity(student).build();
    } catch (StudentException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : StudentException(com.remswork.project.alice.exception.StudentException) Message(com.remswork.project.alice.model.support.Message) StudentResourceLinks(com.remswork.project.alice.resource.links.StudentResourceLinks) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) Student(com.remswork.project.alice.model.Student) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Example 15 with SectionResourceLinks

use of com.remswork.project.alice.resource.links.SectionResourceLinks in project classify-system by anverliedoit.

the class ClassResource method deleteClassById.

@DELETE
@Path("{classId}")
public Response deleteClassById(@PathParam("classId") long id) {
    try {
        ClassResourceLinks resourceLinks = new ClassResourceLinks(uriInfo);
        TeacherResourceLinks teacherResourceLinks = new TeacherResourceLinks(uriInfo);
        SubjectResourceLinks subjectResourceLinks = new SubjectResourceLinks(uriInfo);
        SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
        Class _class = classService.deleteClassById(id);
        _class.addLink(resourceLinks.self(id));
        _class.addLink(resourceLinks.schedule(id));
        _class.addLink(resourceLinks.student(id));
        if (_class.getTeacher() != null)
            _class.getTeacher().addLink(teacherResourceLinks.self(_class.getTeacher().getId()));
        if (_class.getSubject() != null)
            _class.getSubject().addLink(subjectResourceLinks.self(_class.getSubject().getId()));
        if (_class.getSection() != null)
            _class.getSection().addLink(sectionResourceLinks.self(_class.getSection().getId()));
        return Response.status(Response.Status.OK).entity(_class).build();
    } catch (ClassException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : ClassResourceLinks(com.remswork.project.alice.resource.links.ClassResourceLinks) SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) Message(com.remswork.project.alice.model.support.Message) ClassException(com.remswork.project.alice.exception.ClassException) TeacherResourceLinks(com.remswork.project.alice.resource.links.TeacherResourceLinks) Class(com.remswork.project.alice.model.Class) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Aggregations

Message (com.remswork.project.alice.model.support.Message)15 SectionResourceLinks (com.remswork.project.alice.resource.links.SectionResourceLinks)15 DepartmentResourceLinks (com.remswork.project.alice.resource.links.DepartmentResourceLinks)10 Section (com.remswork.project.alice.model.Section)9 ClassException (com.remswork.project.alice.exception.ClassException)5 SectionException (com.remswork.project.alice.exception.SectionException)5 StudentException (com.remswork.project.alice.exception.StudentException)5 ClassResourceLinks (com.remswork.project.alice.resource.links.ClassResourceLinks)5 StudentResourceLinks (com.remswork.project.alice.resource.links.StudentResourceLinks)5 SubjectResourceLinks (com.remswork.project.alice.resource.links.SubjectResourceLinks)5 TeacherResourceLinks (com.remswork.project.alice.resource.links.TeacherResourceLinks)5 Class (com.remswork.project.alice.model.Class)4 Student (com.remswork.project.alice.model.Student)4 List (java.util.List)3