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