public void removeProduct(ProductDTO productDTO) {

    productDAO.setEm(em);

    Product product = em.find(Product.class, productDTO.getId());

    productDAO.removeTop5(product.getId());

    em.remove(product);
  }
  public ProductDTO createProduct(ProductDTO productDTO) {

    Product product = new Product();
    product.setProdId(productDTO.getProdId());
    product.setName(productDTO.getName());
    product.setDescription(productDTO.getDescription());
    product.setCategory(productDTO.getCategory());
    product.setPrice(productDTO.getPrice());
    product.setProducer(productDTO.getProducer());

    String image_full_url = null;
    if (productDTO.getImage_full_bytes() != null && productDTO.getImage_full_bytes().length > 0) {
      //			image_full_url = ImagesLoadManager.getInstance().uploadJPG(
      //					productDTO.getImage_full_bytes(),
      //					productDTO.getName() + FULL_IMG_PREFIX);

      image_full_url = ImagesLoadManager.getInstance().loadRadomImage(false);
    }

    product.setImage_url_full(image_full_url);

    String image_full_thumbl = null;
    if (productDTO.getImage_thumb_bytes() != null && productDTO.getImage_thumb_bytes().length > 0) {
      //			image_full_thumbl = ImagesLoadManager.getInstance().uploadJPG(
      //					productDTO.getImage_thumb_bytes(),
      //					productDTO.getName() + THUMB_IMG_PREFIX);
      image_full_thumbl = ImagesLoadManager.getInstance().loadRadomImage(true);
    }

    product.setImage_url_thumb(image_full_thumbl);

    em.persist(product);

    return productDTO;
  }
  public ProductDTO getProductDetail(Long prodId) {
    productDAO.setEm(em);
    Product product = productDAO.getProduct(prodId);
    Top5 productTop5 = productDAO.getProductTop5(product.getId());

    ProductDTO productDTO = OMSMapper.mapProduct(product);
    if (productTop5 != null) {
      productDTO.setTop5(OMSMapper.mapTop5(productDAO.getTopProducts(productTop5)));
    }

    return productDTO;
  }
  public ProductDTO getProductDetailById(Long id) {
    productDAO.setEm(em);
    Product product = em.find(Product.class, id);
    Top5 productTop5 = productDAO.getProductTop5(product.getId());

    ProductDTO productDTO = OMSMapper.mapProduct(product);
    if (productTop5 != null) {
      productDTO.setTop5(OMSMapper.mapTop5(productDAO.getTopProducts(productTop5)));
    }

    return productDTO;
  }
  public ProductDTO updateProduct(ProductDTO productDTO) {

    Product product = em.find(Product.class, productDTO.getId());

    product.setProdId(productDTO.getProdId());
    product.setName(productDTO.getName());
    product.setDescription(productDTO.getDescription());
    product.setCategory(productDTO.getCategory());
    product.setPrice(productDTO.getPrice());
    product.setProducer(productDTO.getProducer());

    if (productDTO.getImage_full_bytes() != null && productDTO.getImage_full_bytes().length > 0) {
      //			image_full_url = ImagesLoadManager.getInstance().uploadJPG(
      //					productDTO.getImage_full_bytes(),
      //					productDTO.getName() + FULL_IMG_PREFIX);
      String image_full_url = ImagesLoadManager.getInstance().loadRadomImage(false);
      productDTO.setImage_url_full(image_full_url);
      productDTO.setImage_full_bytes(null);
    }

    if (productDTO.getImage_thumb_bytes() != null && productDTO.getImage_thumb_bytes().length > 0) {
      // image_full_thumbl =
      // ImagesLoadManager.getInstance().uploadJPG(productDTO.getImage_thumb_bytes(),
      // productDTO.getName()+THUMB_IMG_PREFIX);

      String image_full_thumbl = ImagesLoadManager.getInstance().loadRadomImage(true);
      product.setImage_url_thumb(image_full_thumbl);
      productDTO.setImage_thumb_bytes(null);
    }

    return productDTO;
  }