private List<Product> getFoundedProductsList() {
   List<Product> productList = new ArrayList<Product>();
   Product product = new ProductImpl();
   long uid = PRODUCT_UID;
   product.setUidPk(uid);
   productList.add(product);
   return productList;
 }
  @Override
  public Collection<ProductBundle> findProductBundlesContaining(final Product product) {
    final Set<ProductBundle> bundles = new HashSet<ProductBundle>();
    bundles.addAll(getProductBundleDao().findByProduct(product.getCode()));
    for (final ProductSku sku : product.getProductSkus().values()) {
      bundles.addAll(getProductSkuService().findProductBundlesContaining(sku));
    }

    return bundles;
  }
  /**
   * Returns the product with the given <code>productGuid</code>.
   *
   * @param productGuid - The guid of the product
   * @return The product with the given <code>productGuid</code>.
   */
  private Product getProduct(final String productGuid) {

    final long productUid = productService.findUidById(productGuid);
    final Product product = productService.get(productUid);

    if (product == null
        || !product.isInCatalog(getRequestHelper().getStoreConfig().getStore().getCatalog())) {
      throw new ProductUnavailableException("Product is not available, product id:" + productUid);
    }

    return product;
  }
    private void prepareProductSkuCollection(final Product product, final ProductDTO productDTO) {

      if (isProductSkusClearCollection || !product.getProductType().isWithMultipleSkus()) {
        Map<String, ProductSku> productSkuMap = new HashMap<String, ProductSku>();
        for (ProductSkuDTO productSkuDTO : productDTO.getProductSkus()) {
          ProductSku productSku = product.getSkuByGuid(productSkuDTO.getGuid());
          if (productSku != null) {
            productSkuMap.put(productSkuDTO.getSkuCode(), productSku);
          }
        }
        product.setProductSkus(productSkuMap);
      }
    }
 private void prepareSkuAttributesCollection(final Product product) {
   if (isSkuAttributesClearCollection) {
     for (ProductSku productSku : product.getProductSkus().values()) {
       productSku.getAttributeValueMap().clear();
     }
   }
 }
  /**
   * Finds id tuples of ProductBundles that directly contain the given product or any of the
   * product's skus as a BundleConstituent.
   *
   * <p>Each tuple is an 2 element Object array containing the ProductBundle's id as the first
   * element and the bundle's product code as the second element.
   *
   * @param product the product
   * @return a list of [uidpk, code] tuples
   */
  private List<Object[]> findProductBundleIdsContainingProduct(final Product product) {
    final List<Object[]> bundleProductIds =
        findProductBundleUidsContainingProductCode(product.getCode());

    final List<Object[]> bundleProductSkuIds =
        getPersistenceEngine()
            .retrieveByNamedQueryWithList(
                "FIND_BUNDLE_IDS_BY_CONSTITUENT_PRODUCT_SKUS",
                "list",
                new ArrayList<String>(product.getProductSkus().keySet()));

    List<Object[]> result = new ArrayList<Object[]>();
    result.addAll(bundleProductIds);
    result.addAll(bundleProductSkuIds);

    return result;
  }
  /**
   * Creates a new product.
   *
   * @param destCatalog catalog.
   * @param taxCode tax code.
   * @return created product.
   */
  protected Product createSimpleProduct(final Catalog destCatalog, final TaxCode taxCode) {
    final Product product = new ProductImpl();
    product.initialize();
    product.setLastModifiedDate(new Date());
    product.setStartDate(new Date());
    product.setCode(Utils.uniqueCode("product"));

    ProductLocaleDependantFieldsImpl f = createDependentField();
    f.setLocale(Locale.ENGLISH);
    product.addOrUpdateLocaleDependantFields(f);

    ProductType productType = new ProductTypeImpl();
    productType.setName(Utils.uniqueCode("productName"));
    productType.initialize();
    productType.setCatalog(destCatalog);
    productType.setTemplate("template1");
    productType.setTaxCode(taxCode);

    productType = persist(productType);

    productType = getPersistenceEngine().load(ProductTypeImpl.class, productType.getUidPk());
    product.setProductType(productType);

    return product;
  }
  /**
   * Tries to downcast {@link Product} to {@link ProductBundle} and do a safe check.
   *
   * @param product
   * @throws EpServiceException
   */
  private ProductBundle downcastToProductBundle(final Product product) throws EpServiceException {
    if (product == null) {
      return null;
    }

    if (product instanceof ProductBundle) {
      return (ProductBundle) product;
    }

    throw new EpServiceException(product.getGuid() + " is not a product bundle.");
  }
 private void prepareAttributesCollection(final Product product) {
   if (isProductAttributesClearCollection) {
     product.getAttributeValueMap().clear();
   }
 }