retail/interactive-tutorials/src/main/java/product/setup/RemoveProductsResources.java [45:75]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  public static void deleteAllProducts(String branchName) throws IOException {
    System.out.println("Deleting products in process, please wait...");

    // Initialize client that will be used to send requests. This client only
    // needs to be created once, and can be reused for multiple requests. After
    // completing all of your requests, call the "close" method on the client to
    // safely clean up any remaining background resources.
    try (ProductServiceClient productServiceClient = ProductServiceClient.create()) {
      ListProductsRequest listRequest =
          ListProductsRequest.newBuilder().setParent(branchName).build();
      ListProductsPagedResponse products = productServiceClient.listProducts(listRequest);

      int deleteCount = 0;

      for (Product product : products.iterateAll()) {
        DeleteProductRequest deleteRequest =
            DeleteProductRequest.newBuilder().setName(product.getName()).build();

        try {
          productServiceClient.deleteProduct(deleteRequest);
          deleteCount++;
        } catch (PermissionDeniedException e) {
          System.out.println(
              "Ignore PermissionDenied in case the product does not exist "
                  + "at time of deletion.");
        }
      }

      System.out.printf("%s products were deleted from %s%n", deleteCount, branchName);
    }
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



retail/interactive-tutorials/src/main/java/events/setup/RemoveEventsResources.java [62:88]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  public static void deleteAllProducts(String branchName) throws IOException {
    System.out.println("Deleting products in process, please wait...");

    try (ProductServiceClient productServiceClient = ProductServiceClient.create()) {
      ListProductsRequest listRequest =
          ListProductsRequest.newBuilder().setParent(branchName).build();
      ListProductsPagedResponse products = productServiceClient.listProducts(listRequest);

      int deleteCount = 0;

      for (Product product : products.iterateAll()) {
        DeleteProductRequest deleteRequest =
            DeleteProductRequest.newBuilder().setName(product.getName()).build();

        try {
          productServiceClient.deleteProduct(deleteRequest);
          deleteCount++;
        } catch (PermissionDeniedException e) {
          System.out.println(
              "Ignore PermissionDenied in case the product does not exist "
                  + "at time of deletion.");
        }
      }

      System.out.printf("%s products were deleted from %s%n", deleteCount, branchName);
    }
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



