/** {@inheritDoc} */
  public List<ProductRelease> findAll(
      String pName,
      String osType,
      Integer page,
      Integer pageSize,
      String orderBy,
      String orderType) {

    ProductReleaseSearchCriteria criteria = new ProductReleaseSearchCriteria();

    if (!StringUtils.isEmpty(pName)) {
      try {
        Product product = productManager.load(pName);
        criteria.setProduct(product);
      } catch (EntityNotFoundException ex) {
        throw new WebApplicationException(ex, Response.Status.NOT_FOUND);
      }
    }

    if (!StringUtils.isEmpty(osType)) {
      criteria.setOSType(osType);
    }
    if (page != null && pageSize != null) {
      criteria.setPage(page);
      criteria.setPageSize(pageSize);
    }
    if (!StringUtils.isEmpty(orderBy)) {
      criteria.setOrderBy(orderBy);
    }
    if (!StringUtils.isEmpty(orderType)) {
      criteria.setOrderBy(orderType);
    }
    return productReleaseManager.findReleasesByCriteria(criteria);
  }
  @Before
  public void setUp() throws Exception {
    productResource = new ProductResourceImpl();
    ProductManager productManager = mock(ProductManager.class);
    productResource.setProductManager(productManager);
    Product product = new Product(PRODUCT_NAME, "description");
    OS os = new OS("os1", "1", "os1 description", "v1");

    ProductRelease productRelease =
        new ProductRelease(PRODUCT_VERSION, "releaseNotes", product, Arrays.asList(os), null);
    List<ProductRelease> lProductRelease = new ArrayList<ProductRelease>();
    lProductRelease.add(productRelease);

    when(productManager.insert(any(Product.class))).thenReturn(product);
    when(productManager.load(any(String.class))).thenReturn(product);
    doNothing().when(productManager).delete(any(Product.class));
  }
  @Override
  public List<ProductAndReleaseDto> findAllProductAndRelease(
      Integer page, Integer pageSize, String orderBy, String orderType) {
    ProductSearchCriteria criteria = new ProductSearchCriteria();

    if (page != null && pageSize != null) {
      criteria.setPage(page);
      criteria.setPageSize(pageSize);
    }
    if (!StringUtils.isEmpty(orderBy)) {
      criteria.setOrderBy(orderBy);
    }
    if (!StringUtils.isEmpty(orderType)) {
      criteria.setOrderBy(orderType);
    }
    return filterProductsAndReleases(productManager.findProductAndReleaseByCriteria(criteria));
  }
  /** {@inheritDoc} */
  @Override
  public void delete(String pName, String version)
      throws ProductReleaseNotFoundException, ProductReleaseStillInstalledException {

    log.log(
        Level.INFO,
        "Delete ProductRelease. ProductName : " + pName + " ProductVersion : " + version);

    Product product;
    try {
      product = productManager.load(pName);
    } catch (EntityNotFoundException e) {
      throw new ProductReleaseNotFoundException(e);
    }

    ProductRelease productRelease;
    try {
      productRelease = productReleaseManager.load(product, version);
    } catch (EntityNotFoundException e) {
      throw new ProductReleaseNotFoundException(e);
    }

    productReleaseManager.delete(productRelease);
  }
 /** {@inheritDoc} */
 @Override
 public ProductRelease load(String pName, String version) throws EntityNotFoundException {
   Product product = productManager.load(pName);
   return productReleaseManager.load(product, version);
 }