Search in sources :

Example 1 with PurgeProductsRequest

use of com.google.cloud.vision.v1.PurgeProductsRequest 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 2 with PurgeProductsRequest

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

the class PurgeProducts method purgeOrphanProducts.

// Delete the product and all its reference images.
public static void purgeOrphanProducts(String projectId, String computeRegion) throws Exception {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        String parent = LocationName.format(projectId, computeRegion);
        // The purge operation is async.
        PurgeProductsRequest request = PurgeProductsRequest.newBuilder().setDeleteOrphanProducts(true).setForce(true).setParent(parent).build();
        OperationFuture response = client.purgeProductsAsync(request);
        response.getPollingFuture().get(180, TimeUnit.SECONDS);
        System.out.println("Orphan products deleted.");
    }
}
Also used : PurgeProductsRequest(com.google.cloud.vision.v1.PurgeProductsRequest) ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) OperationFuture(com.google.api.gax.longrunning.OperationFuture)

Aggregations

ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)2 PurgeProductsRequest (com.google.cloud.vision.v1.PurgeProductsRequest)2 OperationFuture (com.google.api.gax.longrunning.OperationFuture)1 BatchOperationMetadata (com.google.cloud.vision.v1.BatchOperationMetadata)1 ProductSetPurgeConfig (com.google.cloud.vision.v1.ProductSetPurgeConfig)1 Empty (com.google.protobuf.Empty)1