Search in sources :

Example 11 with Product

use of com.haulmont.cuba.testmodel.sales_1.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());
}
Also used : GetProductRequest(com.google.cloud.vision.v1.GetProductRequest) Product(com.google.cloud.vision.v1.Product) Test(org.junit.Test)

Example 12 with Product

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

Example 13 with Product

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

Example 14 with Product

use of com.haulmont.cuba.testmodel.sales_1.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 15 with Product

use of com.haulmont.cuba.testmodel.sales_1.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)

Aggregations

Product (com.google.cloud.retail.v2.Product)20 Product (com.google.cloud.vision.v1.Product)10 SetupCleanup.deleteProduct (setup.SetupCleanup.deleteProduct)9 ProductServiceClient (com.google.cloud.retail.v2.ProductServiceClient)8 SetupCleanup.createProduct (setup.SetupCleanup.createProduct)6 ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)5 Product (com.haulmont.cuba.testmodel.sales_1.Product)5 Test (org.junit.jupiter.api.Test)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 PrintStream (java.io.PrintStream)4 Before (org.junit.Before)4 Test (org.junit.Test)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 CreateProductRequest (com.google.cloud.retail.v2.CreateProductRequest)3 GetProductRequest (com.google.cloud.retail.v2.GetProductRequest)3 QueryRunner (com.haulmont.bali.db.QueryRunner)3 Id (com.haulmont.cuba.core.entity.contracts.Id)3 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)3 TestContainer (com.haulmont.cuba.testsupport.TestContainer)3 Assertions (org.junit.jupiter.api.Assertions)3