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;
}
}
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();
}
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);
}
}
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);
}
}
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);
}
Aggregations