Search in sources :

Example 26 with Product

use of com.google.cloud.vision.v1.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 = System.getenv("PROJECT_ID");
    String defaultBranchName = String.format("projects/%s/locations/global/catalogs/default_catalog/" + "branches/default_branch", projectId);
    String generatedProductId = UUID.randomUUID().toString();
    Product createdProduct = createProduct(generatedProductId, defaultBranchName);
    deleteProduct(createdProduct.getName());
}
Also used : SetupCleanup.deleteProduct(setup.SetupCleanup.deleteProduct) Product(com.google.cloud.retail.v2.Product)

Example 27 with Product

use of com.google.cloud.vision.v1.Product in project java-notes by esalkan.

the class HashSetOfProducts method main.

/**
 * @param args
 */
public static void main(String[] args) {
    Set<Product> prodSet = new TreeSet<>();
    // Add product to prodSet via Product Class
    prodSet.add(new Product("book", 25.99));
    prodSet.add(new Product("book", 19.99));
    prodSet.add(new Product("magazine", 7.99));
    prodSet.add(new Product("phone", 100));
    System.out.println(prodSet.toString());
    // print each product by using for each loop
    for (Product product : prodSet) {
        System.out.println(product.getPrice());
    }
    // print each product by using forEach method
    prodSet.forEach(x -> System.out.println(x.getName()));
// prodSet.forEach(product -> System.out.println(product));
}
Also used : TreeSet(java.util.TreeSet) Product(oop.JOOP46_Collections_Part01.Product)

Example 28 with Product

use of com.google.cloud.vision.v1.Product in project cuba by cuba-platform.

the class TransactionalActionUsageTest method testOnFailAction.

@Test
public void testOnFailAction() {
    EntitySet entities = transactionalActionFactory.getTransactionalAction().withCommitContext(() -> {
        CommitContext cc = new CommitContext();
        Product p = metadata.create(Product.class);
        p.setName("test");
        p.setQuantity(100);
        p.setId(null);
        cc.addInstanceToCommit(p);
        return cc;
    }).onFail((cc, t) -> {
        messageFromOnFailAction = "[testOnFailAction] commit failed";
    }).perform();
    assertNull(entities);
    assertEquals("[testOnFailAction] commit failed", messageFromOnFailAction);
}
Also used : Test(org.junit.jupiter.api.Test) BeforeEach(org.junit.jupiter.api.BeforeEach) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Assertions(org.junit.jupiter.api.Assertions) QueryRunner(com.haulmont.bali.db.QueryRunner) Product(com.haulmont.cuba.testmodel.sales_1.Product) Id(com.haulmont.cuba.core.entity.contracts.Id) TestContainer(com.haulmont.cuba.testsupport.TestContainer) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Product(com.haulmont.cuba.testmodel.sales_1.Product) Test(org.junit.jupiter.api.Test)

Example 29 with Product

use of com.google.cloud.vision.v1.Product in project cuba by cuba-platform.

the class TransactionalActionUsageTest method testOnSuccessAction.

@Test
public void testOnSuccessAction() {
    EntitySet entities = transactionalActionFactory.getTransactionalAction().withCommitContext(() -> {
        CommitContext cc = new CommitContext();
        Product p = metadata.create(Product.class);
        p.setName("test");
        p.setQuantity(100);
        cc.addInstanceToCommit(p);
        return cc;
    }).onSuccess(es -> {
        es.stream().filter(e -> Product.class.equals(e.getMetaClass().getJavaClass())).forEach(e -> ((Product) e).setName("newName"));
    }).perform();
    Product product = (Product) entities.stream().filter(e -> Product.class.equals(e.getMetaClass().getJavaClass())).findFirst().orElse(null);
    assertNotNull(product);
    assertEquals("newName", product.getName());
    Product productFromDb = transactionalDataManager.load(Id.of(product)).one();
    assertNotNull(productFromDb);
    assertEquals("test", productFromDb.getName());
}
Also used : Test(org.junit.jupiter.api.Test) BeforeEach(org.junit.jupiter.api.BeforeEach) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Assertions(org.junit.jupiter.api.Assertions) QueryRunner(com.haulmont.bali.db.QueryRunner) Product(com.haulmont.cuba.testmodel.sales_1.Product) Id(com.haulmont.cuba.core.entity.contracts.Id) TestContainer(com.haulmont.cuba.testsupport.TestContainer) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Product(com.haulmont.cuba.testmodel.sales_1.Product) Test(org.junit.jupiter.api.Test)

Example 30 with Product

use of com.google.cloud.vision.v1.Product in project cuba by cuba-platform.

the class TransactionalActionUsageTest method testAllActions.

@Test
public void testAllActions() {
    EntitySet entities = transactionalDataManager.commitAction(() -> {
        CommitContext cc = new CommitContext();
        Product p = transactionalDataManager.create(Product.class);
        p.setName("allActionsTest");
        p.setQuantity(100);
        cc.addInstanceToCommit(p);
        return cc;
    }).onSuccess(es -> {
        es.stream().filter(e -> Product.class.equals(e.getMetaClass().getJavaClass())).forEach(e -> ((Product) e).setName("onSuccessName"));
    }).onFail((cc, t) -> {
        messageFromOnFailAction = "[testAllActions] commit failed";
    }).afterCompletion(cc -> {
        messageFromAfterCommitAction = "[testAllActions] transaction ended";
    }).perform();
    Product product = (Product) entities.stream().filter(e -> Product.class.equals(e.getMetaClass().getJavaClass())).findFirst().orElse(null);
    assertNotNull(product);
    assertEquals("onSuccessName", product.getName());
    Product productFromDb = transactionalDataManager.load(Id.of(product)).one();
    assertNotNull(productFromDb);
    assertEquals("allActionsTest", productFromDb.getName());
    assertNotEquals("[testAllActions] commit failed", messageFromOnFailAction);
    assertEquals("[testAllActions] transaction ended", messageFromAfterCommitAction);
}
Also used : Test(org.junit.jupiter.api.Test) BeforeEach(org.junit.jupiter.api.BeforeEach) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Assertions(org.junit.jupiter.api.Assertions) QueryRunner(com.haulmont.bali.db.QueryRunner) Product(com.haulmont.cuba.testmodel.sales_1.Product) Id(com.haulmont.cuba.core.entity.contracts.Id) TestContainer(com.haulmont.cuba.testsupport.TestContainer) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Product(com.haulmont.cuba.testmodel.sales_1.Product) Test(org.junit.jupiter.api.Test)

Aggregations

ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)19 Product (com.google.cloud.retail.v2.Product)14 Product (com.google.cloud.vision.v1.Product)10 Test (org.junit.Test)9 SetupCleanup.deleteProduct (setup.SetupCleanup.deleteProduct)6 ReferenceImage (com.google.cloud.vision.v1.ReferenceImage)5 AbstractMessage (com.google.protobuf.AbstractMessage)5 ProductSet (com.google.cloud.vision.v1.ProductSet)4 Product (com.haulmont.cuba.testmodel.sales_1.Product)4 Test (org.junit.jupiter.api.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 BeforeEach (org.junit.jupiter.api.BeforeEach)3 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)3