private static boolean validateEmptyvalues(Object object, int objectType) { switch (objectType) { case TYPE_CUSTOMER: Customer c = (Customer) object; if (c.getCode().isEmpty() || c.getName().isEmpty() || c.getAddress().isEmpty() || c.getPhone1().isEmpty()) { return false; } break; case TYPE_PRODUCT: Product p = (Product) object; if (p.getCode().isEmpty() || p.getDescription().isEmpty()) { return false; } break; case TYPE_SALESORDER: SalesOrder s = (SalesOrder) object; return (!s.getOrderNumber().isEmpty()); default: break; } return true; }
@SuppressWarnings("unchecked") public static List<ComboBoxItem> listCurrentRecordRefernces(int objectType) { // TODO by the candidate /* * This method is called when a Combo Box need to be initialized and * should return list of ComboBoxItem which contains code and * description/name for all records of specified type */ Session session = sessionFactory.getCurrentSession(); session.beginTransaction(); List<ComboBoxItem> cbox = new LinkedList<ComboBoxItem>(); try { switch (objectType) { case TYPE_CUSTOMER: List<Customer> list = session.createCriteria(Customer.class).list(); for (Customer item : list) { cbox.add(new ComboBoxItem(item.getCode(), item.getName())); } break; case TYPE_PRODUCT: List<Product> pList = session.createCriteria(Product.class).list(); for (Product item : pList) { cbox.add(new ComboBoxItem(item.getCode(), item.getDescription())); } break; case TYPE_SALESORDER: List<SalesOrder> sList = session.createCriteria(SalesOrder.class).list(); for (SalesOrder item : sList) { cbox.add(new ComboBoxItem(item.getOrderNumber(), item.getOrderNumber())); } break; default: break; } session.getTransaction().commit(); } catch (HibernateException e) { logger.error("Error while retrieving records", e); session.getTransaction().rollback(); } return cbox; }