Search in sources :

Example 6 with DepartmentException

use of com.remswork.project.alice.exception.DepartmentException 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 7 with DepartmentException

use of com.remswork.project.alice.exception.DepartmentException 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)

Example 8 with DepartmentException

use of com.remswork.project.alice.exception.DepartmentException in project classify-system by anverliedoit.

the class DepartmentDaoImpl method addDepartment.

@Override
public Department addDepartment(Department department) throws DepartmentException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        if (department == null)
            throw new DepartmentDaoException("You tried to add department with a null value");
        if (department.getName() == null)
            throw new DepartmentDaoException("Department's name is required");
        if (department.getName().trim().equals(""))
            throw new DepartmentDaoException("Department can't have an empty name");
        if (department.getDescription() == null)
            throw new DepartmentDaoException("Department's description is required");
        if (department.getDescription().trim().equals(""))
            throw new DepartmentDaoException("Department can't have an empty description");
        session.save(department);
        session.getTransaction().commit();
        session.close();
        return department;
    } catch (DepartmentDaoException e) {
        session.close();
        throw new DepartmentException(e.getMessage());
    }
}
Also used : DepartmentException(com.remswork.project.alice.exception.DepartmentException) DepartmentDaoException(com.remswork.project.alice.dao.exception.DepartmentDaoException) Session(org.hibernate.Session)

Example 9 with DepartmentException

use of com.remswork.project.alice.exception.DepartmentException in project classify-system by anverliedoit.

the class DepartmentDaoImpl method getDepartmentById.

@Override
public Department getDepartmentById(long id) 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");
        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 10 with DepartmentException

use of com.remswork.project.alice.exception.DepartmentException in project classify-system by anverliedoit.

the class SectionController method getSection.

@RequestMapping(value = "get", method = RequestMethod.POST)
public String getSection(@RequestParam("query") String query, ModelMap modelMap) {
    try {
        List<Department> departmentList = departmentService.getDepartmentList();
        List<Section> sectionList = new ArrayList<>();
        Section section = null;
        if (!query.trim().isEmpty()) {
            try {
                long id = Long.parseLong(query.trim());
                section = sectionService.getSectionById(id);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                section = null;
            } catch (SectionException e) {
                e.printStackTrace();
                section = null;
            }
            if (section != null)
                sectionList.add(section);
            else {
                for (Section t : sectionService.getSectionList()) {
                    if (t.getName().equals(query.trim())) {
                        sectionList.add(t);
                        continue;
                    }
                }
            }
        }
        if (sectionList.size() < 1) {
            sectionList = sectionService.getSectionList();
            modelMap.put("responseMessage", "No result found.");
        } else {
            modelMap.put("responseMessage", sectionList.size() + " Result found.");
        }
        modelMap.put("sectionList", sectionList);
        modelMap.put("departmentList", departmentList);
        return "section-table";
    } catch (SectionException | DepartmentException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : Department(com.remswork.project.alice.model.Department) DepartmentException(com.remswork.project.alice.exception.DepartmentException) ArrayList(java.util.ArrayList) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DepartmentException (com.remswork.project.alice.exception.DepartmentException)30 Department (com.remswork.project.alice.model.Department)22 Message (com.remswork.project.alice.model.support.Message)15 Session (org.hibernate.Session)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 AsyncTask (android.os.AsyncTask)5 Gson (com.google.gson.Gson)5 DepartmentDaoException (com.remswork.project.alice.dao.exception.DepartmentDaoException)5 SectionException (com.remswork.project.alice.exception.SectionException)5 Section (com.remswork.project.alice.model.Section)5 DepartmentResourceLinks (com.remswork.project.alice.resource.links.DepartmentResourceLinks)5 DepartmentServiceException (com.remswork.project.alice.web.service.exception.DepartmentServiceException)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 HttpURLConnection (java.net.HttpURLConnection)5 URL (java.net.URL)5 ExecutionException (java.util.concurrent.ExecutionException)5 Client (javax.ws.rs.client.Client)5 WebTarget (javax.ws.rs.client.WebTarget)5 Response (javax.ws.rs.core.Response)5