use of com.google.cloud.vision.v1.ImportProductSetsResponse in project java-vision by googleapis.
the class ImportProductSets method importProductSets.
// [START vision_product_search_import_product_images]
/**
* Import images of different products in the product set.
*
* @param projectId - Id of the project.
* @param computeRegion - Region name.
* @param gcsUri - Google Cloud Storage URI.Target files must be in Product Search CSV format.
* @throws Exception - on client errors.
*/
public static void importProductSets(String projectId, String computeRegion, String gcsUri) throws Exception {
try (ProductSearchClient client = ProductSearchClient.create()) {
// A resource that represents Google Cloud Platform location.
String formattedParent = ProductSearchClient.formatLocationName(projectId, computeRegion);
Builder gcsSource = ImportProductSetsGcsSource.newBuilder().setCsvFileUri(gcsUri);
// Set the input configuration along with Google Cloud Storage URI
ImportProductSetsInputConfig inputConfig = ImportProductSetsInputConfig.newBuilder().setGcsSource(gcsSource).build();
// Import the product sets from the input URI.
OperationFuture<ImportProductSetsResponse, BatchOperationMetadata> response = client.importProductSetsAsync(formattedParent, inputConfig);
System.out.println(String.format("Processing operation name: %s", response.getName()));
ImportProductSetsResponse results = response.get();
System.out.println("Processing done.");
System.out.println("Results of the processing:");
for (int i = 0; i < results.getStatusesCount(); i++) {
System.out.println(String.format("Status of processing line %s of the csv: %s", i, results.getStatuses(i)));
// Check the status of reference image.
if (results.getStatuses(i).getCode() == 0) {
ReferenceImage referenceImage = results.getReferenceImages(i);
System.out.println(referenceImage);
} else {
System.out.println("No reference image.");
}
}
}
}
Aggregations