Search in sources :

Example 6 with Department

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

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

Example 8 with Department

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

the class TeacherController method updateTeacherById.

@RequestMapping(value = "update", method = RequestMethod.POST)
public String updateTeacherById(@RequestParam("id") long id, @RequestParam("firstName") String firstName, @RequestParam("middleName") String middleName, @RequestParam("lastName") String lastName, @RequestParam("email") String email, @RequestParam("departmentId") long departmentId, ModelMap modelMap) {
    try {
        Teacher newTeacher = new Teacher(firstName, lastName, middleName, email);
        try {
            teacherService.updateTeacherById(id, newTeacher, departmentId);
        } catch (TeacherException e) {
            try {
                e.printStackTrace();
                departmentId = 0;
                teacherService.updateTeacherById(id, newTeacher, departmentId);
            } catch (TeacherException e2) {
                e2.printStackTrace();
            }
        }
        List<Teacher> teacherList = teacherService.getTeacherList();
        List<Department> departmentList = departmentService.getDepartmentList();
        modelMap.put("teacherList", teacherList);
        modelMap.put("departmentList", departmentList);
        return "teacher";
    } catch (TeacherException | DepartmentException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : Department(com.remswork.project.alice.model.Department) Teacher(com.remswork.project.alice.model.Teacher) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with Department

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

the class TeacherController method getTeacher.

@RequestMapping(value = "get", method = RequestMethod.POST)
public String getTeacher(@RequestParam("query") String query, ModelMap modelMap) {
    try {
        List<Department> departmentList = departmentService.getDepartmentList();
        List<Teacher> teacherList = new ArrayList<>();
        Teacher teacher = null;
        if (!query.trim().isEmpty()) {
            try {
                long id = Long.parseLong(query.trim());
                teacher = teacherService.getTeacherById(id);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                teacher = null;
            } catch (TeacherException e) {
                e.printStackTrace();
                teacher = null;
            }
            if (teacher != null)
                teacherList.add(teacher);
            else {
                for (Teacher t : teacherService.getTeacherList()) {
                    if (t.getFirstName().equals(query.trim())) {
                        teacherList.add(t);
                        continue;
                    }
                    if (t.getMiddleName().equals(query.trim())) {
                        teacherList.add(t);
                        continue;
                    }
                    if (t.getLastName().equals(query.trim())) {
                        teacherList.add(t);
                        continue;
                    }
                    if (t.getEmail().equals(query.trim())) {
                        teacherList.add(t);
                        continue;
                    }
                }
            }
        }
        if (teacherList.size() < 1) {
            teacherList = teacherService.getTeacherList();
            modelMap.put("responseMessage", "No result found.");
        } else {
            modelMap.put("responseMessage", teacherList.size() + " Result found.");
        }
        modelMap.put("teacherList", teacherList);
        modelMap.put("departmentList", departmentList);
        return "fragment/teacher-table";
    } catch (TeacherException | DepartmentException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : Department(com.remswork.project.alice.model.Department) Teacher(com.remswork.project.alice.model.Teacher) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with Department

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

the class TeacherController method addTeacher.

@RequestMapping(value = "add", method = RequestMethod.POST)
public String addTeacher(@RequestParam("firstName") String firstName, @RequestParam("middleName") String middleName, @RequestParam("lastName") String lastName, @RequestParam("email") String email, @RequestParam("departmentId") long departmentId, ModelMap modelMap) {
    try {
        Teacher teacher = new Teacher(firstName, middleName, lastName, email);
        teacherService.addTeacher(teacher, departmentId);
        List<Teacher> teacherList = teacherService.getTeacherList();
        List<Department> departmentList = departmentService.getDepartmentList();
        modelMap.put("teacherList", teacherList);
        modelMap.put("departmentList", departmentList);
        return "teacher";
    } catch (TeacherException | DepartmentException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : Department(com.remswork.project.alice.model.Department) Teacher(com.remswork.project.alice.model.Teacher) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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