use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product in project java-retail by googleapis.
the class UpdateProduct method updateProduct.
// call the Retail API to update product
public static void updateProduct(Product originalProduct, String defaultBranchName) throws IOException {
try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
Product updatedProduct = serviceClient.updateProduct(getUpdateProductRequest(generateProductForUpdate(originalProduct.getId(), defaultBranchName)));
System.out.printf("Updated product: %s%n", updatedProduct);
}
}
use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product in project java-retail by googleapis.
the class RemoveTestResources method deleteAllProducts.
public static void deleteAllProducts(String branchName) throws IOException {
System.out.println("Deleting products in process, please wait...");
try (ProductServiceClient productServiceClient = ProductServiceClient.create()) {
ListProductsRequest listRequest = ListProductsRequest.newBuilder().setParent(branchName).build();
ListProductsPagedResponse products = productServiceClient.listProducts(listRequest);
int deleteCount = 0;
for (Product product : products.iterateAll()) {
DeleteProductRequest deleteRequest = DeleteProductRequest.newBuilder().setName(product.getName()).build();
try {
productServiceClient.deleteProduct(deleteRequest);
deleteCount++;
} catch (PermissionDeniedException e) {
System.out.println("Ignore PermissionDenied in case the product does not exist " + "at time of deletion.");
}
}
System.out.printf("%s products were deleted from %s%n", deleteCount, branchName);
}
}
use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product in project java-retail by googleapis.
the class SetupCleanup method getUserEvent.
public static UserEvent getUserEvent(String visitorId) {
int value = 3;
Timestamp timestamp = Timestamp.newBuilder().setSeconds(Instant.now().getEpochSecond()).build();
Product product = Product.newBuilder().setId(UUID.randomUUID().toString()).build();
ProductDetail productDetail = ProductDetail.newBuilder().setProduct(product).setQuantity(Int32Value.newBuilder().setValue(value).build()).build();
UserEvent userEvent = UserEvent.newBuilder().setEventType("detail-page-view").setVisitorId(visitorId).setEventTime(timestamp).addAllProductDetails(Collections.singletonList(productDetail)).build();
System.out.println(userEvent);
return userEvent;
}
use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product in project java-retail by googleapis.
the class SetupCleanup method createProduct.
public static Product createProduct(String productId) throws IOException {
CreateProductRequest createProductRequest = CreateProductRequest.newBuilder().setProduct(generateProduct()).setProductId(productId).setParent(DEFAULT_BRANCH_NAME).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.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product 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;
}
}
Aggregations