Search in sources :

Example 1 with DeleteProductRequest

use of com.google.cloud.retail.v2.DeleteProductRequest in project java-vision by googleapis.

the class ITSystemTest method tearDown.

@AfterClass
public static void tearDown() {
    /* delete reference image */
    DeleteReferenceImageRequest imageRequest = DeleteReferenceImageRequest.newBuilder().setName(formatReferenceImageName).build();
    productSearchClient.deleteReferenceImage(imageRequest);
    /* remove product from product set */
    RemoveProductFromProductSetRequest removeProductRequest = RemoveProductFromProductSetRequest.newBuilder().setName(formatProductSetName).setProduct(formatProductName).build();
    productSearchClient.removeProductFromProductSet(removeProductRequest);
    /* delete product set */
    DeleteProductSetRequest deleteProductSetRequest = DeleteProductSetRequest.newBuilder().setName(formatProductSetName).build();
    productSearchClient.deleteProductSet(deleteProductSetRequest);
    /* delete product */
    DeleteProductRequest deleteProductRequest = DeleteProductRequest.newBuilder().setName(formatProductName).build();
    productSearchClient.deleteProduct(deleteProductRequest);
    productSearchClient.close();
    imageAnnotatorClient.close();
}
Also used : DeleteProductRequest(com.google.cloud.vision.v1.DeleteProductRequest) DeleteReferenceImageRequest(com.google.cloud.vision.v1.DeleteReferenceImageRequest) DeleteProductSetRequest(com.google.cloud.vision.v1.DeleteProductSetRequest) RemoveProductFromProductSetRequest(com.google.cloud.vision.v1.RemoveProductFromProductSetRequest) AfterClass(org.junit.AfterClass)

Example 2 with DeleteProductRequest

use of com.google.cloud.retail.v2.DeleteProductRequest in project java-retail by googleapis.

the class RemoveTestResources method deleteAllProducts.

public static void deleteAllProducts() throws IOException {
    System.out.println("Deleting products in process, please wait...");
    try (ProductServiceClient productServiceClient = ProductServiceClient.create()) {
        ListProductsRequest listRequest = ListProductsRequest.newBuilder().setParent(DEFAULT_CATALOG).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, DEFAULT_CATALOG);
    }
}
Also used : DeleteProductRequest(com.google.cloud.retail.v2.DeleteProductRequest) ListProductsRequest(com.google.cloud.retail.v2.ListProductsRequest) ProductServiceClient(com.google.cloud.retail.v2.ProductServiceClient) Product(com.google.cloud.retail.v2.Product) PermissionDeniedException(com.google.api.gax.rpc.PermissionDeniedException) ListProductsPagedResponse(com.google.cloud.retail.v2.ProductServiceClient.ListProductsPagedResponse)

Example 3 with DeleteProductRequest

use of com.google.cloud.retail.v2.DeleteProductRequest in project java-retail by googleapis.

the class SetupCleanup method deleteProduct.

public static void deleteProduct(String productName) throws IOException {
    DeleteProductRequest deleteProductRequest = DeleteProductRequest.newBuilder().setName(productName).build();
    System.out.printf("Delete product request %s%n", deleteProductRequest);
    ProductServiceClient.create().deleteProduct(deleteProductRequest);
    System.out.printf("Product %s was deleted.%n", productName);
}
Also used : DeleteProductRequest(com.google.cloud.retail.v2.DeleteProductRequest)

Example 4 with DeleteProductRequest

use of com.google.cloud.retail.v2.DeleteProductRequest in project java-retail by googleapis.

the class CrudProduct method deleteProduct.

// delete product
public static void deleteProduct(String productName) throws IOException {
    DeleteProductRequest deleteProductRequest = DeleteProductRequest.newBuilder().setName(productName).build();
    System.out.printf("Delete product request %s%n", deleteProductRequest);
    ProductServiceClient.create().deleteProduct(deleteProductRequest);
    System.out.printf("Product %s was deleted.%n", productName);
}
Also used : DeleteProductRequest(com.google.cloud.retail.v2.DeleteProductRequest)

Example 5 with DeleteProductRequest

use of com.google.cloud.retail.v2.DeleteProductRequest in project java-retail by googleapis.

the class DeleteProduct method deleteProduct.

// call the Retail API to delete product
public static void deleteProduct(String productName) throws IOException {
    DeleteProductRequest deleteProductRequest = DeleteProductRequest.newBuilder().setName(productName).build();
    System.out.printf("Delete product request %s%n", deleteProductRequest);
    ProductServiceClient.create().deleteProduct(deleteProductRequest);
    System.out.printf("Product %s was deleted.%n", productName);
}
Also used : DeleteProductRequest(com.google.cloud.retail.v2.DeleteProductRequest)

Aggregations

DeleteProductRequest (com.google.cloud.retail.v2.DeleteProductRequest)4 PermissionDeniedException (com.google.api.gax.rpc.PermissionDeniedException)1 ListProductsRequest (com.google.cloud.retail.v2.ListProductsRequest)1 Product (com.google.cloud.retail.v2.Product)1 ProductServiceClient (com.google.cloud.retail.v2.ProductServiceClient)1 ListProductsPagedResponse (com.google.cloud.retail.v2.ProductServiceClient.ListProductsPagedResponse)1 DeleteProductRequest (com.google.cloud.vision.v1.DeleteProductRequest)1 DeleteProductSetRequest (com.google.cloud.vision.v1.DeleteProductSetRequest)1 DeleteReferenceImageRequest (com.google.cloud.vision.v1.DeleteReferenceImageRequest)1 RemoveProductFromProductSetRequest (com.google.cloud.vision.v1.RemoveProductFromProductSetRequest)1 AfterClass (org.junit.AfterClass)1