use of com.google.cloud.retail.v2.ImportProductsResponse in project java-retail by googleapis.
the class CreateTestResources method importProductsFromGcs.
public static void importProductsFromGcs() throws IOException, InterruptedException {
ImportProductsRequest importGcsRequest = getImportProductsGcsRequest("products.json");
try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
String operationName = serviceClient.importProductsCallable().call(importGcsRequest).getName();
System.out.printf("OperationName = %s\n", operationName);
OperationsClient operationsClient = serviceClient.getOperationsClient();
Operation operation = operationsClient.getOperation(operationName);
while (!operation.getDone()) {
System.out.println("Please wait till operation is completed.");
// Keep polling the operation periodically until the import task is done.
int awaitDuration = 30000;
Thread.sleep(awaitDuration);
operation = operationsClient.getOperation(operationName);
}
System.out.println("Import products operation is completed.");
if (operation.hasMetadata()) {
ImportMetadata metadata = operation.getMetadata().unpack(ImportMetadata.class);
System.out.printf("Number of successfully imported products: %s\n", metadata.getSuccessCount());
System.out.printf("Number of failures during the importing: %s\n", metadata.getFailureCount());
}
if (operation.hasResponse()) {
ImportProductsResponse response = operation.getResponse().unpack(ImportProductsResponse.class);
System.out.printf("Operation result: %s", response);
}
}
}
use of com.google.cloud.retail.v2.ImportProductsResponse in project java-retail by googleapis.
the class ImportProductsBigQueryTable method waitForOperationCompletion.
public static void waitForOperationCompletion(ImportProductsRequest importRequest) throws IOException, InterruptedException {
try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
String operationName = serviceClient.importProductsCallable().call(importRequest).getName();
System.out.printf("OperationName = %s\n", operationName);
OperationsClient operationsClient = serviceClient.getOperationsClient();
Operation operation = operationsClient.getOperation(operationName);
while (!operation.getDone()) {
// Keep polling the operation periodically until the import task is done.
Thread.sleep(30_000);
operation = operationsClient.getOperation(operationName);
}
if (operation.hasMetadata()) {
ImportMetadata metadata = operation.getMetadata().unpack(ImportMetadata.class);
System.out.printf("Number of successfully imported products: %s\n", metadata.getSuccessCount());
System.out.printf("Number of failures during the importing: %s\n", metadata.getFailureCount());
}
if (operation.hasResponse()) {
ImportProductsResponse response = operation.getResponse().unpack(ImportProductsResponse.class);
System.out.printf("Operation result: %s%n", response);
}
}
}
use of com.google.cloud.retail.v2.ImportProductsResponse in project java-retail by googleapis.
the class ImportProductsGcs method waitForOperationCompletion.
public static void waitForOperationCompletion(ImportProductsRequest importRequest) throws IOException, InterruptedException {
try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
String operationName = serviceClient.importProductsCallable().call(importRequest).getName();
System.out.printf("OperationName = %s\n", operationName);
OperationsClient operationsClient = serviceClient.getOperationsClient();
Operation operation = operationsClient.getOperation(operationName);
while (!operation.getDone()) {
// Keep polling the operation periodically until the import task is done.
Thread.sleep(30_000);
operation = operationsClient.getOperation(operationName);
}
if (operation.hasMetadata()) {
ImportMetadata metadata = operation.getMetadata().unpack(ImportMetadata.class);
System.out.printf("Number of successfully imported products: %s\n", metadata.getSuccessCount());
System.out.printf("Number of failures during the importing: %s\n", metadata.getFailureCount());
}
if (operation.hasResponse()) {
ImportProductsResponse response = operation.getResponse().unpack(ImportProductsResponse.class);
System.out.printf("Operation result: %s%n", response);
}
}
}
use of com.google.cloud.retail.v2.ImportProductsResponse in project java-retail by googleapis.
the class ImportProductsInlineSource method waitForOperationCompletion.
public static void waitForOperationCompletion(ImportProductsRequest importRequest) throws IOException, InterruptedException {
try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
String operationName = serviceClient.importProductsCallable().call(importRequest).getName();
System.out.printf("OperationName = %s\n", operationName);
OperationsClient operationsClient = serviceClient.getOperationsClient();
Operation operation = operationsClient.getOperation(operationName);
while (!operation.getDone()) {
// Keep polling the operation periodically until the import task is done.
Thread.sleep(30_000);
operation = operationsClient.getOperation(operationName);
}
if (operation.hasMetadata()) {
ImportMetadata metadata = operation.getMetadata().unpack(ImportMetadata.class);
System.out.printf("Number of successfully imported products: %s\n", metadata.getSuccessCount());
System.out.printf("Number of failures during the importing: %s\n", metadata.getFailureCount());
}
if (operation.hasResponse()) {
ImportProductsResponse response = operation.getResponse().unpack(ImportProductsResponse.class);
System.out.printf("Operation result: %s%n", response);
}
}
}
use of com.google.cloud.retail.v2.ImportProductsResponse in project java-retail by googleapis.
the class CreateTestResources method importProductsFromGcs.
public static void importProductsFromGcs(String bucketName, String gcsErrorBucket, String branchName) throws IOException, InterruptedException {
GcsSource gcsSource = GcsSource.newBuilder().addAllInputUris(Collections.singleton(String.format("gs://%s/%s", bucketName, "products.json"))).build();
ProductInputConfig inputConfig = ProductInputConfig.newBuilder().setGcsSource(gcsSource).build();
System.out.println("GRS source: " + gcsSource.getInputUrisList());
ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().setGcsPrefix(gcsErrorBucket).build();
ImportProductsRequest importRequest = ImportProductsRequest.newBuilder().setParent(branchName).setReconciliationMode(ReconciliationMode.INCREMENTAL).setInputConfig(inputConfig).setErrorsConfig(errorsConfig).build();
System.out.println("Import products from google cloud source request: " + importRequest);
try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
String operationName = serviceClient.importProductsCallable().call(importRequest).getName();
System.out.printf("OperationName = %s\n", operationName);
OperationsClient operationsClient = serviceClient.getOperationsClient();
Operation operation = operationsClient.getOperation(operationName);
while (!operation.getDone()) {
System.out.println("Please wait till operation is completed.");
// Keep polling the operation periodically until the import task is done.
Thread.sleep(30_000);
operation = operationsClient.getOperation(operationName);
}
System.out.println("Import products operation is completed.");
if (operation.hasMetadata()) {
ImportMetadata metadata = operation.getMetadata().unpack(ImportMetadata.class);
System.out.printf("Number of successfully imported products: %s\n", metadata.getSuccessCount());
System.out.printf("Number of failures during the importing: %s\n", metadata.getFailureCount());
}
if (operation.hasResponse()) {
ImportProductsResponse response = operation.getResponse().unpack(ImportProductsResponse.class);
System.out.printf("Operation result: %s", response);
}
}
}
Aggregations