Search in sources :

Example 16 with Product

use of com.google.cloud.retail.v2.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 branchName) throws IOException {
    CreateProductRequest createProductRequest = CreateProductRequest.newBuilder().setProduct(generateProduct()).setProductId(productId).setParent(branchName).build();
    System.out.printf("Create product request: %s%n", createProductRequest);
    try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
        Product createdProduct = serviceClient.createProduct(createProductRequest);
        System.out.printf("Created product: %s%n", createdProduct);
        return createdProduct;
    }
}
Also used : CreateProductRequest(com.google.cloud.retail.v2.CreateProductRequest) ProductServiceClient(com.google.cloud.retail.v2.ProductServiceClient) SetupCleanup.deleteProduct(setup.SetupCleanup.deleteProduct) Product(com.google.cloud.retail.v2.Product)

Example 17 with Product

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

the class CrudProduct method generateProductForUpdate.

// generate product for update
public static Product generateProductForUpdate(String productId, String productName) {
    final float price = 20.0f;
    final float originalPrice = 25.5f;
    PriceInfo priceInfo = PriceInfo.newBuilder().setPrice(price).setOriginalPrice(originalPrice).setCurrencyCode("EUR").build();
    return Product.newBuilder().setId(productId).setName(productName).setTitle("Updated Nest Mini").setType(Type.PRIMARY).addCategories("Updated Speakers and displays").addBrands("Updated Google").setAvailability(Availability.OUT_OF_STOCK).setPriceInfo(priceInfo).build();
}
Also used : PriceInfo(com.google.cloud.retail.v2.PriceInfo)

Example 18 with Product

use of com.google.cloud.retail.v2.Product 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);
    try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
        serviceClient.deleteProduct(deleteProductRequest);
        System.out.printf("Product %s was deleted.%n", productName);
    }
}
Also used : DeleteProductRequest(com.google.cloud.retail.v2.DeleteProductRequest) ProductServiceClient(com.google.cloud.retail.v2.ProductServiceClient)

Example 19 with Product

use of com.google.cloud.retail.v2.Product 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);
    try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
        serviceClient.deleteProduct(deleteProductRequest);
        System.out.printf("Product %s was deleted.%n", productName);
    }
}
Also used : DeleteProductRequest(com.google.cloud.retail.v2.DeleteProductRequest) ProductServiceClient(com.google.cloud.retail.v2.ProductServiceClient)

Example 20 with Product

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

the class ImportProductsGcs method main.

public static void main(String[] args) throws IOException, InterruptedException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = ServiceOptions.getDefaultProjectId();
    String branchName = String.format("projects/%s/locations/global/catalogs/default_catalog/branches/0", projectId);
    String gcsBucket = String.format("gs://%s", System.getenv("BUCKET_NAME"));
    String gcsErrorBucket = String.format("%s/errors", gcsBucket);
    String gscProductsObject = "products.json";
    // TO CHECK ERROR HANDLING USE THE JSON WITH INVALID PRODUCT
    // GCS_PRODUCTS_OBJECT = "products_some_invalid.json"
    ImportProductsRequest importGcsRequest = getImportProductsGcsRequest(gscProductsObject, gcsBucket, gcsErrorBucket, branchName);
    waitForOperationCompletion(importGcsRequest);
}
Also used : ImportProductsRequest(com.google.cloud.retail.v2.ImportProductsRequest)

Aggregations

Product (com.google.cloud.retail.v2.Product)20 ProductServiceClient (com.google.cloud.retail.v2.ProductServiceClient)12 Product (com.google.cloud.vision.v1.Product)10 SetupCleanup.deleteProduct (setup.SetupCleanup.deleteProduct)9 PriceInfo (com.google.cloud.retail.v2.PriceInfo)7 Test (org.junit.Test)6 SetupCleanup.createProduct (setup.SetupCleanup.createProduct)6 DeleteProductRequest (com.google.cloud.retail.v2.DeleteProductRequest)5 ImportProductsRequest (com.google.cloud.retail.v2.ImportProductsRequest)5 ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)5 Product (com.haulmont.cuba.testmodel.sales_1.Product)5 ListProductsPagedResponse (com.google.cloud.retail.v2.ProductServiceClient.ListProductsPagedResponse)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 PrintStream (java.io.PrintStream)4 Before (org.junit.Before)4 Test (org.junit.jupiter.api.Test)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 CreateProductRequest (com.google.cloud.retail.v2.CreateProductRequest)3 FulfillmentInfo (com.google.cloud.retail.v2.FulfillmentInfo)3 GetProductRequest (com.google.cloud.retail.v2.GetProductRequest)3