Search in sources :

Example 6 with TeacherResourceLinks

use of com.remswork.project.alice.resource.links.TeacherResourceLinks 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)

Example 7 with TeacherResourceLinks

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

the class TeacherResource method deleteTeacherById.

@DELETE
@Path("{teacherId}")
public Response deleteTeacherById(@PathParam("teacherId") long id) {
    try {
        TeacherResourceLinks resourceLink = new TeacherResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        Teacher teacher = teacherService.deleteTeacherById(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(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 8 with TeacherResourceLinks

use of com.remswork.project.alice.resource.links.TeacherResourceLinks 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 9 with TeacherResourceLinks

use of com.remswork.project.alice.resource.links.TeacherResourceLinks 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 10 with TeacherResourceLinks

use of com.remswork.project.alice.resource.links.TeacherResourceLinks 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)

Aggregations

Message (com.remswork.project.alice.model.support.Message)16 TeacherResourceLinks (com.remswork.project.alice.resource.links.TeacherResourceLinks)16 SubjectResourceLinks (com.remswork.project.alice.resource.links.SubjectResourceLinks)11 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)6 FormulaResourceLinks (com.remswork.project.alice.resource.links.FormulaResourceLinks)6 ClassException (com.remswork.project.alice.exception.ClassException)5 TeacherException (com.remswork.project.alice.exception.TeacherException)5 Formula (com.remswork.project.alice.model.Formula)5 ClassResourceLinks (com.remswork.project.alice.resource.links.ClassResourceLinks)5 DepartmentResourceLinks (com.remswork.project.alice.resource.links.DepartmentResourceLinks)5 SectionResourceLinks (com.remswork.project.alice.resource.links.SectionResourceLinks)5 Class (com.remswork.project.alice.model.Class)4 Teacher (com.remswork.project.alice.model.Teacher)4 List (java.util.List)3