Search in sources :

Example 21 with Product

use of com.google.cloud.vision.v1.Product 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 22 with Product

use of com.google.cloud.vision.v1.Product in project java-retail by googleapis.

the class UpdateProduct method updateProduct.

// call the Retail API to update product
public static void updateProduct(Product originalProduct, String defaultBranchName) throws IOException {
    Product updatedProduct = ProductServiceClient.create().updateProduct(getUpdateProductRequest(generateProductForUpdate(originalProduct.getId(), defaultBranchName)));
    System.out.printf("Updated product: %s%n", updatedProduct);
}
Also used : SetupCleanup.deleteProduct(setup.SetupCleanup.deleteProduct) Product(com.google.cloud.retail.v2.Product) SetupCleanup.createProduct(setup.SetupCleanup.createProduct)

Example 23 with Product

use of com.google.cloud.vision.v1.Product in project java-retail by googleapis.

the class SetupCleanup method getProduct.

public static Product getProduct(String productName) throws IOException {
    Product product = Product.newBuilder().build();
    GetProductRequest getProductRequest = GetProductRequest.newBuilder().setName(productName).build();
    try {
        product = ProductServiceClient.create().getProduct(getProductRequest);
        System.out.println("Get product response: " + product);
        return product;
    } catch (NotFoundException e) {
        System.out.printf("Product %s not found", productName);
        return product;
    }
}
Also used : GetProductRequest(com.google.cloud.retail.v2.GetProductRequest) Product(com.google.cloud.retail.v2.Product) NotFoundException(com.google.api.gax.rpc.NotFoundException)

Example 24 with Product

use of com.google.cloud.vision.v1.Product in project java-retail by googleapis.

the class SetupCleanup method createProduct.

public static Product createProduct(String productId) throws IOException {
    CreateProductRequest createProductRequest = CreateProductRequest.newBuilder().setProduct(generateProduct()).setProductId(productId).setParent(DEFAULT_BRANCH_NAME).build();
    System.out.printf("Create product request: %s%n", createProductRequest);
    Product createdProduct = ProductServiceClient.create().createProduct(createProductRequest);
    System.out.printf("Created product: %s%n", createdProduct);
    return createdProduct;
}
Also used : CreateProductRequest(com.google.cloud.retail.v2.CreateProductRequest) Product(com.google.cloud.retail.v2.Product)

Example 25 with Product

use of com.google.cloud.vision.v1.Product in project java-retail by googleapis.

the class CreateProduct method createProduct.

// call the Retail API to create product
public static Product createProduct(String productId, String defaultBranchName) throws IOException {
    CreateProductRequest createProductRequest = CreateProductRequest.newBuilder().setProduct(generateProduct()).setProductId(productId).setParent(defaultBranchName).build();
    System.out.printf("Create product request: %s%n", createProductRequest);
    Product createdProduct = ProductServiceClient.create().createProduct(createProductRequest);
    System.out.printf("Created product: %s%n", createdProduct);
    return createdProduct;
}
Also used : CreateProductRequest(com.google.cloud.retail.v2.CreateProductRequest) SetupCleanup.deleteProduct(setup.SetupCleanup.deleteProduct) Product(com.google.cloud.retail.v2.Product)

Aggregations

ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)19 Product (com.google.cloud.retail.v2.Product)14 Product (com.google.cloud.vision.v1.Product)10 Test (org.junit.Test)9 SetupCleanup.deleteProduct (setup.SetupCleanup.deleteProduct)6 ReferenceImage (com.google.cloud.vision.v1.ReferenceImage)5 AbstractMessage (com.google.protobuf.AbstractMessage)5 ProductSet (com.google.cloud.vision.v1.ProductSet)4 Product (com.haulmont.cuba.testmodel.sales_1.Product)4 Test (org.junit.jupiter.api.Test)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 CreateProductRequest (com.google.cloud.retail.v2.CreateProductRequest)3 GetProductRequest (com.google.cloud.retail.v2.GetProductRequest)3 QueryRunner (com.haulmont.bali.db.QueryRunner)3 Id (com.haulmont.cuba.core.entity.contracts.Id)3 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)3 TestContainer (com.haulmont.cuba.testsupport.TestContainer)3 Assertions (org.junit.jupiter.api.Assertions)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)3