Esempio n. 1
0
 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;
 }
Esempio n. 2
0
  public static boolean deleteRecordByCode(String code, int objectType) {
    // TODO by the candidate
    /*
     * This method is called when you click delete button on an edit view
     * the code parameter is the code of (Customer - PRoduct ) or order
     * number of Sales Order and the type is identifier of the object type
     * and may be TYPE_PRODUCT , TYPE_CUSTOMER or TYPE_SALESORDER
     */

    Session session = sessionFactory.getCurrentSession();
    session.beginTransaction();

    try {
      switch (objectType) {
        case TYPE_CUSTOMER:
          Customer c = new Customer();
          c.setCode(code);
          session.delete(c);
          break;
        case TYPE_PRODUCT:
          Product p = new Product();
          p.setCode(code);
          session.delete(p);
          break;
        case TYPE_SALESORDER:
          SalesOrder s = (SalesOrder) session.get(SalesOrder.class, code);
          if (s != null) {
            for (OrderLines ol : s.getOrderLinesList()) {
              session.delete(ol);
            }
            session.delete(s);
          }
          break;
        default:
          break;
      }
      session.flush();
      session.getTransaction().commit();
      return true;
    } catch (HibernateException e) {
      logger.error("Error While Deleting", e);
      session.getTransaction().rollback();
    }
    return false;
  }
Esempio n. 3
0
  @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;
  }
Esempio n. 4
0
  public static double getProductPrice(String productCode) {
    // TODO by the candidate
    /*
     * This method is used to get unit price of product with the code passed
     * as a parameter
     */
    Session session = sessionFactory.getCurrentSession();
    session.beginTransaction();
    Double price = null;
    try {
      Product p = (Product) session.get(Product.class, productCode);
      price = p.getPrice();
      session.getTransaction().commit();
    } catch (HibernateException e) {
      logger.error("Error while retrieving price", e);
      session.getTransaction().rollback();
    }

    return price;
  }
Esempio n. 5
0
  private static boolean handleCustCreditAndProdQuant(Session session, SalesOrder s) {

    Customer c = (Customer) session.get(Customer.class, s.getCustomer().getCode());
    if (s.getTotalPrice() > (c.getCreditLimit() - c.getCurrentCredit())) {
      return false;
    } else {
      Double curCredit = c.getCreditLimit() - s.getTotalPrice() - c.getCurrentCredit();
      c.setCurrentCredit(curCredit);
      session.saveOrUpdate(c);
    }
    for (OrderLines ol : s.getOrderLinesList()) {
      Product p = (Product) session.get(Product.class, ol.getProduct().getCode());
      int remQuantity = p.getQuantity() - ol.getQuantity();
      if (remQuantity < 0) {
        return false;
      } else {
        p.setQuantity(remQuantity);
        session.saveOrUpdate(p);
      }
    }
    return true;
  }