Example #1
0
  @RolesAllowed("users")
  @POST
  @Path("delete")
  @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  public Response deleteProduct(String productId) {
    if (productId != null) {
      Product product = (Product) genericDAO.findById(Integer.valueOf(productId));
      genericDAO.delete(product);
    }

    return getProducts();
  }
Example #2
0
  @RolesAllowed("users")
  @POST
  @Path("submit")
  @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  public Response editProduct(Product product) {
    Product productBean = null;
    if (product.getId() != 0) {
      productBean = (Product) genericDAO.findById(product.getId());
      if (productBean != null) {
        productBean.setCategory(product.getCategory());
        productBean.setPrice(product.getPrice());
        productBean.setLabel(product.getLabel());
        productBean.setCompany(product.getCompany());
      }
    }

    if (productBean == null && product != null) {
      genericDAO.persist(product);
    } else if (productBean != null) {
      genericDAO.merge(productBean);
    }
    return getProducts();
  }