use of com.haulmont.cuba.testmodel.sales_1.Product 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;
}
}
use of com.haulmont.cuba.testmodel.sales_1.Product in project java-retail by googleapis.
the class CrudProduct method updateProduct.
// update product
public static void updateProduct(Product originalProduct, String productName) throws IOException {
UpdateProductRequest updateProductRequest = UpdateProductRequest.newBuilder().setProduct(generateProductForUpdate(originalProduct.getId(), productName)).setAllowMissing(true).build();
System.out.printf("Update product request: %s%n", updateProductRequest);
try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
Product updatedProduct = serviceClient.updateProduct(updateProductRequest);
System.out.printf("Updated product: %s%n", updatedProduct);
}
}
use of com.haulmont.cuba.testmodel.sales_1.Product in project java-retail by googleapis.
the class CrudProduct 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);
Product createdProduct = ProductServiceClient.create().createProduct(createProductRequest);
System.out.printf("Created product: %s%n", createdProduct);
return createdProduct;
}
use of com.haulmont.cuba.testmodel.sales_1.Product in project java-retail by googleapis.
the class CrudProduct method main.
public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = ServiceOptions.getDefaultProjectId();
String generatedProductId = UUID.randomUUID().toString();
String branchName = String.format("projects/%s/locations/global/catalogs/default_catalog/branches/0", projectId);
String productName = String.format("%s/products/%s", branchName, generatedProductId);
Product createdProduct = createProduct(generatedProductId, branchName);
getProduct(productName);
updateProduct(createdProduct, productName);
deleteProduct(productName);
}
use of com.haulmont.cuba.testmodel.sales_1.Product in project java-retail by googleapis.
the class GetProduct method main.
public static void main(String[] args) throws IOException {
String generatedProductId = UUID.randomUUID().toString();
Product createdProduct = createProduct(generatedProductId);
Product product = getProduct(createdProduct.getName());
deleteProduct(product.getName());
}
Aggregations