Search in sources :

Example 11 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient in project java-vision by googleapis.

the class PurgeProductsInProductSet method purgeProductsInProductSet.

// Delete all products in a product set.
public static void purgeProductsInProductSet(String projectId, String location, String productSetId) throws Exception {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        String parent = LocationName.format(projectId, location);
        ProductSetPurgeConfig productSetPurgeConfig = ProductSetPurgeConfig.newBuilder().setProductSetId(productSetId).build();
        PurgeProductsRequest request = PurgeProductsRequest.newBuilder().setParent(parent).setProductSetPurgeConfig(productSetPurgeConfig).setForce(true).build();
        OperationFuture<Empty, BatchOperationMetadata> response = client.purgeProductsAsync(request);
        response.getPollingFuture().get(180, TimeUnit.SECONDS);
        System.out.println("Products removed from product set.");
    }
}
Also used : Empty(com.google.protobuf.Empty) PurgeProductsRequest(com.google.cloud.vision.v1.PurgeProductsRequest) ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) ProductSetPurgeConfig(com.google.cloud.vision.v1.ProductSetPurgeConfig) BatchOperationMetadata(com.google.cloud.vision.v1.BatchOperationMetadata)

Example 12 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient 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.");
            }
        }
    }
}
Also used : ImportProductSetsResponse(com.google.cloud.vision.v1.ImportProductSetsResponse) ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) Builder(com.google.cloud.vision.v1.ImportProductSetsGcsSource.Builder) BatchOperationMetadata(com.google.cloud.vision.v1.BatchOperationMetadata) ReferenceImage(com.google.cloud.vision.v1.ReferenceImage) ImportProductSetsInputConfig(com.google.cloud.vision.v1.ImportProductSetsInputConfig)

Example 13 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient in project java-vision by googleapis.

the class ProductManagement method deleteProduct.

// [END vision_product_search_update_product_labels]
// [START vision_product_search_delete_product]
/**
 * Delete the product and all its reference images.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @throws IOException - on I/O errors.
 */
public static void deleteProduct(String projectId, String computeRegion, String productId) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // Get the full path of the product.
        String formattedName = ProductSearchClient.formatProductName(projectId, computeRegion, productId);
        // Delete a product.
        client.deleteProduct(formattedName);
        System.out.println("Product deleted.");
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient)

Example 14 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient in project java-vision by googleapis.

the class ProductSetManagement method deleteProductSet.

// [END vision_product_search_get_product_set]
// [START vision_product_search_delete_product_set]
/**
 * Delete a product set.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productSetId - Id of the product set.
 * @throws IOException - on I/O errors.
 */
public static void deleteProductSet(String projectId, String computeRegion, String productSetId) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // Get the full path of the product set.
        String formattedName = ProductSearchClient.formatProductSetName(projectId, computeRegion, productSetId);
        // Delete the product set.
        client.deleteProductSet(formattedName);
        System.out.println(String.format("Product set deleted"));
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient)

Example 15 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient in project java-vision by googleapis.

the class ProductSetManagement method createProductSet.

// [START vision_product_search_create_product_set]
/**
 * Create a product set
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productSetId - Id of the product set.
 * @param productSetDisplayName - Display name of the product set.
 * @throws IOException - on I/O errors.
 */
public static void createProductSet(String projectId, String computeRegion, String productSetId, String productSetDisplayName) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // A resource that represents Google Cloud Platform location.
        String formattedParent = ProductSearchClient.formatLocationName(projectId, computeRegion);
        // Create a product set with the product set specification in the region.
        ProductSet myProductSet = ProductSet.newBuilder().setDisplayName(productSetDisplayName).build();
        CreateProductSetRequest request = CreateProductSetRequest.newBuilder().setParent(formattedParent).setProductSet(myProductSet).setProductSetId(productSetId).build();
        ProductSet productSet = client.createProductSet(request);
        // Display the product set information
        System.out.println(String.format("Product set name: %s", productSet.getName()));
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) CreateProductSetRequest(com.google.cloud.vision.v1.CreateProductSetRequest) ProductSet(com.google.cloud.vision.v1.ProductSet)

Aggregations

ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)19 Product (com.google.cloud.vision.v1.Product)6 ReferenceImage (com.google.cloud.vision.v1.ReferenceImage)5 ProductSet (com.google.cloud.vision.v1.ProductSet)4 BatchOperationMetadata (com.google.cloud.vision.v1.BatchOperationMetadata)2 CreateProductSetRequest (com.google.cloud.vision.v1.CreateProductSetRequest)2 KeyValue (com.google.cloud.vision.v1.Product.KeyValue)2 PurgeProductsRequest (com.google.cloud.vision.v1.PurgeProductsRequest)2 OperationFuture (com.google.api.gax.longrunning.OperationFuture)1 AddProductToProductSetRequest (com.google.cloud.vision.v1.AddProductToProductSetRequest)1 CreateProductRequest (com.google.cloud.vision.v1.CreateProductRequest)1 CreateReferenceImageRequest (com.google.cloud.vision.v1.CreateReferenceImageRequest)1 Builder (com.google.cloud.vision.v1.ImportProductSetsGcsSource.Builder)1 ImportProductSetsInputConfig (com.google.cloud.vision.v1.ImportProductSetsInputConfig)1 ImportProductSetsResponse (com.google.cloud.vision.v1.ImportProductSetsResponse)1 ProductSetPurgeConfig (com.google.cloud.vision.v1.ProductSetPurgeConfig)1 Empty (com.google.protobuf.Empty)1 FieldMask (com.google.protobuf.FieldMask)1 BeforeClass (org.junit.BeforeClass)1