Search in sources :

Example 1 with GetProductRequest

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

the class ITSystemTest method getProductTest.

@Test
public void getProductTest() {
    GetProductRequest request = GetProductRequest.newBuilder().setName(formatProductName).build();
    Product actualProduct = productSearchClient.getProduct(request);
    assertEquals(product.getName(), actualProduct.getName());
    assertEquals(PRODUCT_DISPLAY_NAME, actualProduct.getDisplayName());
    assertEquals(PRODUCT_CATEGORY, actualProduct.getProductCategory());
}
Also used : GetProductRequest(com.google.cloud.vision.v1.GetProductRequest) Product(com.google.cloud.vision.v1.Product) Test(org.junit.Test)

Example 2 with GetProductRequest

use of com.google.cloud.retail.v2.GetProductRequest 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 (ProductServiceClient serviceClient = ProductServiceClient.create()) {
        product = serviceClient.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) ProductServiceClient(com.google.cloud.retail.v2.ProductServiceClient) NotFoundException(com.google.api.gax.rpc.NotFoundException)

Example 3 with GetProductRequest

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

the class CrudProduct method getProduct.

// get product
public static Product getProduct(String productName) throws IOException {
    Product product = Product.newBuilder().build();
    GetProductRequest getProductRequest = GetProductRequest.newBuilder().setName(productName).build();
    try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
        product = serviceClient.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) ProductServiceClient(com.google.cloud.retail.v2.ProductServiceClient) NotFoundException(com.google.api.gax.rpc.NotFoundException)

Example 4 with GetProductRequest

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

the class GetProduct method getProduct.

// call the Retail API to get product
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) SetupCleanup.deleteProduct(setup.SetupCleanup.deleteProduct) Product(com.google.cloud.retail.v2.Product) SetupCleanup.createProduct(setup.SetupCleanup.createProduct) NotFoundException(com.google.api.gax.rpc.NotFoundException)

Aggregations

NotFoundException (com.google.api.gax.rpc.NotFoundException)3 GetProductRequest (com.google.cloud.retail.v2.GetProductRequest)3 Product (com.google.cloud.retail.v2.Product)3 ProductServiceClient (com.google.cloud.retail.v2.ProductServiceClient)2 GetProductRequest (com.google.cloud.vision.v1.GetProductRequest)1 Product (com.google.cloud.vision.v1.Product)1 Test (org.junit.Test)1 SetupCleanup.createProduct (setup.SetupCleanup.createProduct)1 SetupCleanup.deleteProduct (setup.SetupCleanup.deleteProduct)1