Search in sources :

Example 1 with Department

use of com.remswork.project.alice.model.Department in project classify-system by anverliedoit.

the class DepartmentResource method deleteDepartmentById.

@DELETE
@Path("{departmentId}")
public Response deleteDepartmentById(@PathParam("departmentId") long id) {
    try {
        DepartmentResourceLinks resourceLinks = new DepartmentResourceLinks(uriInfo);
        Department department = departmentService.deleteDepartmentById(id);
        department.addLink(resourceLinks.self(id));
        return Response.status(Response.Status.OK).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 : 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)

Example 2 with Department

use of com.remswork.project.alice.model.Department in project classify-system by anverliedoit.

the class DepartmentResource method getDepartmentById.

@GET
@Path("{departmentId}")
public Response getDepartmentById(@PathParam("departmentId") long id) {
    try {
        DepartmentResourceLinks resourceLinks = new DepartmentResourceLinks(uriInfo);
        Department department = departmentService.getDepartmentById(id);
        department.addLink(resourceLinks.self(id));
        return Response.status(Response.Status.OK).entity(department).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)

Example 3 with Department

use of com.remswork.project.alice.model.Department in project classify-system by anverliedoit.

the class DepartmentResource method updateDepartmentById.

@PUT
@Path("{departmentId}")
public Response updateDepartmentById(@PathParam("departmentId") long id, Department newDepartment) {
    try {
        DepartmentResourceLinks resourceLinks = new DepartmentResourceLinks(uriInfo);
        Department department = departmentService.updateDepartmentById(id, newDepartment);
        department.addLink(resourceLinks.self(id));
        return Response.status(Response.Status.OK).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 : 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)

Example 4 with Department

use of com.remswork.project.alice.model.Department in project classify-system by anverliedoit.

the class DepartmentDaoImpl method updateDepartmentById.

@Override
public Department updateDepartmentById(long id, Department newDepartment) throws DepartmentException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Department department = session.get(Department.class, id);
        if (department == null)
            throw new DepartmentDaoException("Department with id : " + id + " does not exist.");
        if (newDepartment == null)
            throw new DepartmentDaoException("You tried to update department with a null value");
        if (!(newDepartment.getName() != null ? newDepartment.getName().trim() : "").isEmpty())
            department.setName(newDepartment.getName());
        if (!(newDepartment.getDescription() != null ? newDepartment.getDescription().trim() : "").isEmpty())
            department.setDescription(newDepartment.getDescription());
        session.getTransaction().commit();
        session.close();
        return department;
    } catch (DepartmentDaoException e) {
        session.close();
        throw new DepartmentException(e.getMessage());
    }
}
Also used : Department(com.remswork.project.alice.model.Department) DepartmentException(com.remswork.project.alice.exception.DepartmentException) DepartmentDaoException(com.remswork.project.alice.dao.exception.DepartmentDaoException) Session(org.hibernate.Session)

Example 5 with Department

use of com.remswork.project.alice.model.Department in project classify-system by anverliedoit.

the class DepartmentDaoImpl method getDepartmentList.

@Override
public List<Department> getDepartmentList() throws DepartmentException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    List<Department> departmentList = new ArrayList<>();
    try {
        Query query = session.createQuery("from Department");
        for (Object departmentObj : query.list()) departmentList.add((Department) departmentObj);
        session.getTransaction().commit();
        session.close();
        return departmentList;
    } catch (DepartmentDaoException e) {
        session.close();
        throw new DepartmentException(e.getMessage());
    }
}
Also used : Department(com.remswork.project.alice.model.Department) Query(org.hibernate.Query) DepartmentException(com.remswork.project.alice.exception.DepartmentException) ArrayList(java.util.ArrayList) DepartmentDaoException(com.remswork.project.alice.dao.exception.DepartmentDaoException) Session(org.hibernate.Session)

Aggregations

Department (com.remswork.project.alice.model.Department)25 DepartmentException (com.remswork.project.alice.exception.DepartmentException)22 Message (com.remswork.project.alice.model.support.Message)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 Session (org.hibernate.Session)6 SectionException (com.remswork.project.alice.exception.SectionException)5 Section (com.remswork.project.alice.model.Section)5 DepartmentServiceException (com.remswork.project.alice.web.service.exception.DepartmentServiceException)5 ArrayList (java.util.ArrayList)5 Client (javax.ws.rs.client.Client)5 WebTarget (javax.ws.rs.client.WebTarget)5 Response (javax.ws.rs.core.Response)5 DepartmentDaoException (com.remswork.project.alice.dao.exception.DepartmentDaoException)4 Teacher (com.remswork.project.alice.model.Teacher)4 DepartmentResourceLinks (com.remswork.project.alice.resource.links.DepartmentResourceLinks)4 ClientBuilder (javax.ws.rs.client.ClientBuilder)3 Builder (javax.ws.rs.client.Invocation.Builder)3 SectionDaoException (com.remswork.project.alice.dao.exception.SectionDaoException)2 List (java.util.List)2 Query (org.hibernate.Query)2