Search in sources :

Example 31 with Product

use of com.haulmont.cuba.testmodel.sales_1.Product in project java-retail by googleapis.

the class GetProduct method getProduct.

// call the Retail API to get product
public static Product getProduct(String productName) throws IOException {
    Product product = Product.newBuilder().build();
    GetProductRequest getProductRequest = GetProductRequest.newBuilder().setName(productName).build();
    try {
        product = ProductServiceClient.create().getProduct(getProductRequest);
        System.out.println("Get product response: " + product);
        return product;
    } catch (NotFoundException e) {
        System.out.printf("Product %s not found", productName);
        return product;
    }
}
Also used : GetProductRequest(com.google.cloud.retail.v2.GetProductRequest) SetupCleanup.deleteProduct(setup.SetupCleanup.deleteProduct) Product(com.google.cloud.retail.v2.Product) SetupCleanup.createProduct(setup.SetupCleanup.createProduct) NotFoundException(com.google.api.gax.rpc.NotFoundException)

Example 32 with Product

use of com.haulmont.cuba.testmodel.sales_1.Product in project java-retail by googleapis.

the class ImportProductsInlineSource method getProducts.

public static List<Product> getProducts() {
    List<Product> products = new ArrayList<>();
    Product product1;
    Product product2;
    float price1 = 16f;
    float originalPrice1 = 45.0f;
    float cost1 = 12.0f;
    PriceInfo priceInfo1 = PriceInfo.newBuilder().setPrice(price1).setOriginalPrice(originalPrice1).setCost(cost1).setCurrencyCode("USD").build();
    ColorInfo colorInfo1 = ColorInfo.newBuilder().addColorFamilies("Blue").addAllColors(Arrays.asList("Light blue", "Blue", "Dark blue")).build();
    FulfillmentInfo fulfillmentInfo1 = FulfillmentInfo.newBuilder().setType("pickup-in-store").addAllPlaceIds(Arrays.asList("store1", "store2")).build();
    FieldMask fieldMask1 = FieldMask.newBuilder().addAllPaths(Arrays.asList("title", "categories", "price_info", "color_info")).build();
    // TO CHECK ERROR HANDLING COMMENT OUT THE PRODUCT TITLE HERE:
    product1 = Product.newBuilder().setTitle("#IamRemarkable Pen").setId(UUID.randomUUID().toString()).addAllCategories(Collections.singletonList("Office")).setUri("https://shop.googlemerchandisestore.com/Google+Redesign/" + "Office/IamRemarkable+Pen").addBrands("#IamRemarkable").setPriceInfo(priceInfo1).setColorInfo(colorInfo1).addFulfillmentInfo(fulfillmentInfo1).setRetrievableFields(fieldMask1).build();
    float price2 = 35f;
    float originalPrice2 = 45.0f;
    float cost2 = 12.0f;
    PriceInfo priceInfo2 = PriceInfo.newBuilder().setPrice(price2).setOriginalPrice(originalPrice2).setCost(cost2).setCurrencyCode("USD").build();
    ColorInfo colorInfo2 = ColorInfo.newBuilder().addColorFamilies("Blue").addAllColors(Collections.singletonList("Sky blue")).build();
    FulfillmentInfo fulfillmentInfo2 = FulfillmentInfo.newBuilder().setType("pickup-in-store").addAllPlaceIds(Arrays.asList("store2", "store3")).build();
    FieldMask fieldMask2 = FieldMask.newBuilder().addAllPaths(Arrays.asList("title", "categories", "price_info", "color_info")).build();
    product2 = Product.newBuilder().setTitle("Android Embroidered Crewneck Sweater").setId(UUID.randomUUID().toString()).addCategories("Apparel").setUri("https://shop.googlemerchandisestore.com/Google+Redesign/" + "Apparel/Android+Embroidered+Crewneck+Sweater").addBrands("Android").setPriceInfo(priceInfo2).setColorInfo(colorInfo2).addFulfillmentInfo(fulfillmentInfo2).setRetrievableFields(fieldMask2).build();
    products.add(product1);
    products.add(product2);
    return products;
}
Also used : ArrayList(java.util.ArrayList) Product(com.google.cloud.retail.v2.Product) ColorInfo(com.google.cloud.retail.v2.ColorInfo) FulfillmentInfo(com.google.cloud.retail.v2.FulfillmentInfo) FieldMask(com.google.protobuf.FieldMask) PriceInfo(com.google.cloud.retail.v2.PriceInfo)

Example 33 with Product

use of com.haulmont.cuba.testmodel.sales_1.Product in project java-retail by googleapis.

the class UpdateProduct 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);
    updateProduct(createdProduct, branchName);
    deleteProduct(createdProduct.getName());
}
Also used : SetupCleanup.deleteProduct(setup.SetupCleanup.deleteProduct) Product(com.google.cloud.retail.v2.Product) SetupCleanup.createProduct(setup.SetupCleanup.createProduct)

Example 34 with Product

use of com.haulmont.cuba.testmodel.sales_1.Product in project java-retail by googleapis.

the class UpdateProductTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException, ExecutionException {
    String projectId = ServiceOptions.getDefaultProjectId();
    String branchName = String.format("projects/%s/locations/global/catalogs/default_catalog/branches/0", projectId);
    String generatedProductId = UUID.randomUUID().toString();
    bout = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(bout);
    originalPrintStream = System.out;
    System.setOut(out);
    Product createdProduct = createProduct(generatedProductId);
    updateProduct(createdProduct, branchName);
    deleteProduct(createdProduct.getName());
}
Also used : PrintStream(java.io.PrintStream) SetupCleanup.createProduct(setup.SetupCleanup.createProduct) UpdateProduct.updateProduct(product.UpdateProduct.updateProduct) SetupCleanup.deleteProduct(setup.SetupCleanup.deleteProduct) Product(com.google.cloud.retail.v2.Product) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Example 35 with Product

use of com.haulmont.cuba.testmodel.sales_1.Product in project AN15 by IharDubkou.

the class CategoryServiceImpl method byInBasket.

@Override
public void byInBasket(User user, Product product) {
    System.out.println("Вы хотите купить");
    System.out.println(product);
    System.out.println("\nКорзина покупок теперь");
    for (Product product1 : user.getBasket().getProducts()) {
        System.out.println(product1);
    }
}
Also used : SvProduct(com.teachMeSkills.an15.VorobyovSergey.hwSix.Task3.models.SvProduct) Product(com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product)

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