Search in sources :

Example 21 with Product

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

the class RemoveFulfillmentPlaces method removeFulfillmentPlaces.

// remove fulfillment places to product
public static void removeFulfillmentPlaces(String productName, Timestamp timestamp, String storeId) throws IOException, InterruptedException {
    RemoveFulfillmentPlacesRequest removeFulfillmentRequest = getRemoveFulfillmentRequest(productName, timestamp, storeId);
    try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
        serviceClient.removeFulfillmentPlacesAsync(removeFulfillmentRequest);
        /*
      This is a long-running operation and its result is not immediately
      present with get operations,thus we simulate wait with sleep method.
      */
        System.out.println("Remove fulfillment places, wait 30 seconds.");
        Thread.sleep(30_000);
    }
}
Also used : RemoveFulfillmentPlacesRequest(com.google.cloud.retail.v2.RemoveFulfillmentPlacesRequest) ProductServiceClient(com.google.cloud.retail.v2.ProductServiceClient)

Example 22 with Product

use of com.google.cloud.retail.v2.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);
    }
}
Also used : ProductServiceClient(com.google.cloud.retail.v2.ProductServiceClient) SetupCleanup.deleteProduct(setup.SetupCleanup.deleteProduct) Product(com.google.cloud.retail.v2.Product) SetupCleanup.createProduct(setup.SetupCleanup.createProduct)

Example 23 with Product

use of com.google.cloud.retail.v2.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);
    }
}
Also used : DeleteProductRequest(com.google.cloud.retail.v2.DeleteProductRequest) ListProductsRequest(com.google.cloud.retail.v2.ListProductsRequest) ProductServiceClient(com.google.cloud.retail.v2.ProductServiceClient) Product(com.google.cloud.retail.v2.Product) PermissionDeniedException(com.google.api.gax.rpc.PermissionDeniedException) ListProductsPagedResponse(com.google.cloud.retail.v2.ProductServiceClient.ListProductsPagedResponse)

Example 24 with Product

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

the class SetupCleanup method deleteProduct.

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 25 with Product

use of com.google.cloud.retail.v2.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;
}
Also used : ProductDetail(com.google.cloud.retail.v2.ProductDetail) Product(com.google.cloud.retail.v2.Product) Timestamp(com.google.protobuf.Timestamp) UserEvent(com.google.cloud.retail.v2.UserEvent)

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