@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!"); } }
@Override public void removeProduct(String code) throws ProductCodeNotExistsException { Product product = productDao.getProductByProductCode(code); productDao.remove(product); log.debug("Please implement this method removeProduct" + code); }
@Override public void removeProduct(Product product) { log.debug("removing product: " + product); productDao.remove(product); }
@Override public List<Product> getProducts() { return productDao.getAllDistinct(); }
/** * {@inheritDoc} * * @throws ProductCodeNotExistsException */ @Override public Product getProductByProductName(String code) throws ProductCodeNotExistsException { return productDao.getProductByProductCode(code); }