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());
}
}
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";
}
}
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";
}
}
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";
}
}
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";
}
}
Aggregations