Search in sources :

Example 26 with Section

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

the class SectionDaoImpl method getSectionById.

@Override
public Section getSectionById(long id) throws SectionException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Section section = session.get(Section.class, id);
        if (section == null)
            throw new SectionDaoException("Section with id : " + id + " does not exist");
        session.getTransaction().commit();
        session.close();
        return section;
    } catch (SectionDaoException e) {
        session.close();
        throw new SectionException(e.getMessage());
    }
}
Also used : SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionDaoException(com.remswork.project.alice.dao.exception.SectionDaoException) Session(org.hibernate.Session)

Example 27 with Section

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

the class SectionDaoImpl method updateSectionById.

@Override
public Section updateSectionById(long id, Section newSection, long departmentId) throws SectionException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Section section = session.get(Section.class, id);
        if (section == null)
            throw new SectionDaoException("Section with id : " + id + " does not exist");
        if (newSection == null)
            newSection = new Section();
        if (!(newSection.getName() != null ? newSection.getName() : "").trim().isEmpty())
            section.setName(newSection.getName().trim());
        if (departmentId > 0) {
            Department department = departmentDao.getDepartmentById(departmentId);
            if (department.getId() == (section.getDepartment() != null ? section.getDepartment().getId() : 0))
                throw new SectionDaoException("Can't update section's department with same department");
            section.setDepartment(department);
        }
        session.getTransaction().commit();
        session.close();
        return section;
    } catch (SectionDaoException | DepartmentException e) {
        session.close();
        throw new SectionException(e.getMessage());
    }
}
Also used : Department(com.remswork.project.alice.model.Department) DepartmentException(com.remswork.project.alice.exception.DepartmentException) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionDaoException(com.remswork.project.alice.dao.exception.SectionDaoException) Session(org.hibernate.Session)

Aggregations

Section (com.remswork.project.alice.model.Section)27 SectionException (com.remswork.project.alice.exception.SectionException)20 Message (com.remswork.project.alice.model.support.Message)15 DepartmentResourceLinks (com.remswork.project.alice.resource.links.DepartmentResourceLinks)9 SectionResourceLinks (com.remswork.project.alice.resource.links.SectionResourceLinks)9 StudentException (com.remswork.project.alice.exception.StudentException)8 Student (com.remswork.project.alice.model.Student)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 DepartmentException (com.remswork.project.alice.exception.DepartmentException)5 Department (com.remswork.project.alice.model.Department)5 StudentResourceLinks (com.remswork.project.alice.resource.links.StudentResourceLinks)5 SectionServiceException (com.remswork.project.alice.web.service.exception.SectionServiceException)5 Client (javax.ws.rs.client.Client)5 WebTarget (javax.ws.rs.client.WebTarget)5 Response (javax.ws.rs.core.Response)5 Session (org.hibernate.Session)5 SectionDaoException (com.remswork.project.alice.dao.exception.SectionDaoException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)3 ClientBuilder (javax.ws.rs.client.ClientBuilder)3