コード例 #1
0
 @Override
 public Product saveProduct(Product productVO) throws ProductExistsException {
   Product product = null;
   try {
     // check if the product is already present or not
     try {
       product = productDao.getProductByProductCode(productVO.getCode());
     } catch (ProductCodeNotExistsException cnnee) {
       log.debug("Product Does not exist with name : " + productVO.getCode());
     }
     if (product != null) {
       // product is present, update it
       product.setDescription(productVO.getDescription());
       product.setPrice(productVO.getPrice());
       product.setQuantity(productVO.getQuantity());
     } else {
       // product does not present save it
       product = new Product();
       product.setCode(productVO.getCode());
       product.setDescription(productVO.getDescription());
       product.setPrice(productVO.getPrice());
       product.setQuantity(productVO.getQuantity());
     }
     return productDao.saveProduct(productVO);
   } catch (final Exception e) {
     e.printStackTrace();
     log.warn(e.getMessage());
     throw new ProductExistsException("Product '" + productVO.getCode() + "' already exists!");
   }
 }
コード例 #2
0
 @Override
 public void removeProduct(String code) throws ProductCodeNotExistsException {
   Product product = productDao.getProductByProductCode(code);
   productDao.remove(product);
   log.debug("Please implement this method removeProduct" + code);
 }
コード例 #3
0
 @Override
 public void removeProduct(Product product) {
   log.debug("removing product: " + product);
   productDao.remove(product);
 }
コード例 #4
0
 @Override
 public List<Product> getProducts() {
   return productDao.getAllDistinct();
 }
コード例 #5
0
 /**
  * {@inheritDoc}
  *
  * @throws ProductCodeNotExistsException
  */
 @Override
 public Product getProductByProductName(String code) throws ProductCodeNotExistsException {
   return productDao.getProductByProductCode(code);
 }