Search in sources :

Example 16 with DepartmentResourceLinks

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

the class TeacherResource method getTeacherById.

@GET
@Path("{teacherId}")
public Response getTeacherById(@PathParam("teacherId") long id) {
    try {
        TeacherResourceLinks resourceLink = new TeacherResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        Teacher teacher = teacherService.getTeacherById(id);
        teacher.addLink(resourceLink.self(id));
        if (teacher.getDepartment() != null)
            teacher.getDepartment().addLink(departmentResourceLinks.self(teacher.getDepartment().getId()));
        return Response.status(Response.Status.OK).entity(teacher).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)

Example 17 with DepartmentResourceLinks

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

the class TeacherResource method updateTeacherById.

@PUT
@Path("{teacherId}")
public Response updateTeacherById(@PathParam("teacherId") long id, Teacher newTeacher) {
    try {
        TeacherResourceLinks resourceLink = new TeacherResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        Teacher teacher;
        if (departmentId > 0)
            teacher = teacherService.updateTeacherById(id, newTeacher, departmentId);
        else
            teacher = teacherService.updateTeacherById(id, newTeacher);
        teacher.addLink(resourceLink.self(id));
        if (teacher.getDepartment() != null)
            teacher.getDepartment().addLink(departmentResourceLinks.self(teacher.getDepartment().getId()));
        return Response.status(Response.Status.OK).entity(teacher).build();
    } catch (TeacherException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).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)

Example 18 with DepartmentResourceLinks

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

the class TeacherResource method addTeacher.

@POST
public Response addTeacher(Teacher teacher) {
    try {
        TeacherResourceLinks resourceLink = new TeacherResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        if (departmentId > 0)
            teacher = teacherService.addTeacher(teacher, departmentId);
        else
            teacher = teacherService.addTeacher(teacher);
        teacher.addLink(resourceLink.self(teacher.getId()));
        if (teacher.getDepartment() != null)
            teacher.getDepartment().addLink(departmentResourceLinks.self(teacher.getDepartment().getId()));
        return Response.status(Response.Status.CREATED).entity(teacher).build();
    } catch (TeacherException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : TeacherException(com.remswork.project.alice.exception.TeacherException) Message(com.remswork.project.alice.model.support.Message) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) TeacherResourceLinks(com.remswork.project.alice.resource.links.TeacherResourceLinks)

Example 19 with DepartmentResourceLinks

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

the class DepartmentResource method addDepartment.

@POST
public Response addDepartment(Department department) {
    try {
        DepartmentResourceLinks resourceLinks = new DepartmentResourceLinks(uriInfo);
        department = departmentService.addDepartment(department);
        department.addLink(resourceLinks.self(department.getId()));
        return Response.status(Response.Status.CREATED).entity(department).build();
    } catch (DepartmentException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : DepartmentException(com.remswork.project.alice.exception.DepartmentException) Message(com.remswork.project.alice.model.support.Message) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks)

Example 20 with DepartmentResourceLinks

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

the class DepartmentResource method getDepartmentList.

@GET
public Response getDepartmentList() {
    try {
        DepartmentResourceLinks resourceLinks = new DepartmentResourceLinks(uriInfo);
        List<Department> departmentList = departmentService.getDepartmentList();
        for (Department d : departmentList) d.addLink(resourceLinks.self(d.getId()));
        GenericEntity<List<Department>> entity = new GenericEntity<List<Department>>(departmentList) {
        };
        return Response.status(Response.Status.OK).entity(entity).build();
    } catch (DepartmentException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : Department(com.remswork.project.alice.model.Department) DepartmentException(com.remswork.project.alice.exception.DepartmentException) Message(com.remswork.project.alice.model.support.Message) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) 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