Search in sources :

Example 6 with DepartmentResourceLinks

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

the class SectionResource method addSection.

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

Example 7 with DepartmentResourceLinks

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

the class SectionResource method updateSectionById.

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

Example 8 with DepartmentResourceLinks

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

the class SectionResource method getSectionList.

@GET
public Response getSectionList() {
    try {
        SectionResourceLinks resourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        List<Section> sectionList = sectionService.getSectionList();
        for (Section section : sectionList) {
            section.addLink(resourceLinks.self(section.getId()));
            if (section.getDepartment() != null)
                section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
        }
        GenericEntity<List<Section>> entity = new GenericEntity<List<Section>>(sectionList) {
        };
        return Response.status(Response.Status.OK).entity(entity).build();
    } catch (SectionException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) List(java.util.List) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Example 9 with DepartmentResourceLinks

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

the class StudentResource method getStudentList.

@GET
public Response getStudentList() {
    try {
        StudentResourceLinks resourceLinks = new StudentResourceLinks(uriInfo);
        SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        List<Student> studentList = studentService.getStudentList();
        if (sn == null) {
            for (Student student : studentList) {
                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()));
                }
            }
            GenericEntity<List<Student>> entity = new GenericEntity<List<Student>>(studentList) {
            };
            return Response.status(Response.Status.OK).entity(entity).build();
        } else {
            Student student = studentService.getStudentBySN(sn);
            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) List(java.util.List) Student(com.remswork.project.alice.model.Student) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Example 10 with DepartmentResourceLinks

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

the class TeacherResource method getAll.

@GET
public Response getAll() {
    try {
        TeacherResourceLinks resourceLink = new TeacherResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        List<Teacher> teacherList = teacherService.getTeacherList();
        for (Teacher teacher : teacherList) {
            teacher.addLink(resourceLink.self(teacher.getId()));
            if (teacher.getDepartment() != null)
                teacher.getDepartment().addLink(departmentResourceLinks.self(teacher.getDepartment().getId()));
        }
        GenericEntity<List<Teacher>> entity = new GenericEntity<List<Teacher>>(teacherList) {
        };
        return Response.status(Response.Status.OK).entity(entity).build();
    } catch (TeacherException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : TeacherException(com.remswork.project.alice.exception.TeacherException) Message(com.remswork.project.alice.model.support.Message) Teacher(com.remswork.project.alice.model.Teacher) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) TeacherResourceLinks(com.remswork.project.alice.resource.links.TeacherResourceLinks) List(java.util.List)

Aggregations

Message (com.remswork.project.alice.model.support.Message)20 DepartmentResourceLinks (com.remswork.project.alice.resource.links.DepartmentResourceLinks)20 SectionResourceLinks (com.remswork.project.alice.resource.links.SectionResourceLinks)10 Section (com.remswork.project.alice.model.Section)9 DepartmentException (com.remswork.project.alice.exception.DepartmentException)5 SectionException (com.remswork.project.alice.exception.SectionException)5 StudentException (com.remswork.project.alice.exception.StudentException)5 TeacherException (com.remswork.project.alice.exception.TeacherException)5 StudentResourceLinks (com.remswork.project.alice.resource.links.StudentResourceLinks)5 TeacherResourceLinks (com.remswork.project.alice.resource.links.TeacherResourceLinks)5 Department (com.remswork.project.alice.model.Department)4 Student (com.remswork.project.alice.model.Student)4 Teacher (com.remswork.project.alice.model.Teacher)4 List (java.util.List)4