use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product in project java-vision by googleapis.
the class ProductManagement method getProduct.
// [END vision_product_search_list_products]
// [START vision_product_search_get_product]
/**
* Get information about a product.
*
* @param projectId - Id of the project.
* @param computeRegion - Region name.
* @param productId - Id of the product.
* @throws IOException - on I/O errors.
*/
public static void getProduct(String projectId, String computeRegion, String productId) throws IOException {
try (ProductSearchClient client = ProductSearchClient.create()) {
// Get the full path of the product.
String formattedName = ProductSearchClient.formatProductName(projectId, computeRegion, productId);
// Get complete detail of the product.
Product product = client.getProduct(formattedName);
// Display the product information
System.out.println(String.format("Product name: %s", product.getName()));
System.out.println(String.format("Product id: %s", product.getName().substring(product.getName().lastIndexOf('/') + 1)));
System.out.println(String.format("Product display name: %s", product.getDisplayName()));
System.out.println(String.format("Product description: %s", product.getDescription()));
System.out.println(String.format("Product category: %s", product.getProductCategory()));
System.out.println(String.format("Product labels: "));
for (Product.KeyValue element : product.getProductLabelsList()) {
System.out.println(String.format("%s: %s", element.getKey(), element.getValue()));
}
}
}
use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product in project java-vision by googleapis.
the class ITSystemTest method listProductsInProductSetTest.
@Test
public void listProductsInProductSetTest() {
ListProductsInProductSetRequest request = ListProductsInProductSetRequest.newBuilder().setName(formatProductSetName).build();
for (Product actualProduct : productSearchClient.listProductsInProductSet(request).iterateAll()) {
assertEquals(product.getName(), actualProduct.getName());
assertEquals(PRODUCT_DISPLAY_NAME, actualProduct.getDisplayName());
assertEquals(PRODUCT_CATEGORY, actualProduct.getProductCategory());
}
}
use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product 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());
}
use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product in project java-retail by googleapis.
the class CreateProduct method main.
public static void main(String[] args) throws IOException {
// 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 generatedProductId = UUID.randomUUID().toString();
Product createdProduct = createProduct(generatedProductId, branchName);
deleteProduct(createdProduct.getName());
}
use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.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;
}
}
Aggregations