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());
}
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));
}
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);
}
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());
}
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);
}
Aggregations