Skip to content

Commit 42d3897

Browse files
committed
chore: Refactor object filter options and remove specific helpers
1 parent 2b6e35d commit 42d3897

File tree

7 files changed

+16
-74
lines changed

7 files changed

+16
-74
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,59 +2748,13 @@ public static BlobListOption softDeleted(boolean softDeleted) {
27482748
}
27492749

27502750
/**
2751-
* Returns an option to filter list results to objects that have a context with the specified
2752-
* key and value.
2751+
* Returns an option to filter list results based on object attributes, such as object contexts.
27532752
*
2754-
* @param key The context key to match.
2755-
* @param value The context value to match.
2753+
* @param filter The filter string.
27562754
*/
27572755
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
2758-
public static BlobListOption withContext(@NonNull String key, @NonNull String value) {
2759-
requireNonNull(key, "Key must be non null");
2760-
requireNonNull(value, "Value must be non null");
2761-
String filter = String.format("contexts.\"%s\"=\"%s\"", key, value);
2762-
return new BlobListOption(UnifiedOpts.objectContextsFilter(filter));
2763-
}
2764-
2765-
/**
2766-
* Returns an option to filter list results to objects that DO NOT have a context with the
2767-
* specified key and value.
2768-
*
2769-
* @param key The context key to check.
2770-
* @param value The context value to check.
2771-
*/
2772-
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
2773-
public static BlobListOption withoutContext(@NonNull String key, @NonNull String value) {
2774-
requireNonNull(key, "Key must be non null");
2775-
requireNonNull(value, "Value must be non null");
2776-
String filter = String.format("NOT contexts.\"%s\"=\"%s\"", key, value);
2777-
return new BlobListOption(UnifiedOpts.objectContextsFilter(filter));
2778-
}
2779-
2780-
/**
2781-
* Returns an option to filter list results to objects that have a context with the specified
2782-
* key, regardless of its value.
2783-
*
2784-
* @param key The context key to check for presence.
2785-
*/
2786-
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
2787-
public static BlobListOption withContextKey(@NonNull String key) {
2788-
requireNonNull(key, "Key must be non null");
2789-
String filter = String.format("contexts.\"%s\":*", key);
2790-
return new BlobListOption(UnifiedOpts.objectContextsFilter(filter));
2791-
}
2792-
2793-
/**
2794-
* Returns an option to filter list results to objects that DO NOT have a context with the
2795-
* specified key.
2796-
*
2797-
* @param key The context key to check for absence.
2798-
*/
2799-
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
2800-
public static BlobListOption withoutContextKey(@NonNull String key) {
2801-
requireNonNull(key, "Key must be non null");
2802-
String filter = String.format("NOT contexts.\"%s\":*", key);
2803-
return new BlobListOption(UnifiedOpts.objectContextsFilter(filter));
2756+
public static BlobListOption filter(String filter) {
2757+
return new BlobListOption(UnifiedOpts.objectFilter(filter));
28042758
}
28052759

28062760
/**

google-cloud-storage/src/main/java/com/google/cloud/storage/UnifiedOpts.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,8 @@ static Md5MatchExtractor md5MatchExtractor() {
581581
return Md5MatchExtractor.INSTANCE;
582582
}
583583

584-
static ObjectContextsFilter objectContextsFilter(String filter) {
585-
return new ObjectContextsFilter(filter);
584+
static ObjectFilter objectFilter(String filter) {
585+
return new ObjectFilter(filter);
586586
}
587587

588588
static Headers extraHeaders(ImmutableMap<String, String> extraHeaders) {
@@ -2506,11 +2506,11 @@ private Object readResolve() {
25062506
}
25072507
}
25082508

2509-
static final class ObjectContextsFilter extends RpcOptVal<String> implements ObjectListOpt {
2509+
static final class ObjectFilter extends RpcOptVal<String> implements ObjectListOpt {
25102510
private static final long serialVersionUID = -892748218491324843L;
25112511

2512-
private ObjectContextsFilter(String val) {
2513-
super(StorageRpc.Option.OBJECT_CONTEXTS_FILTER, val);
2512+
private ObjectFilter(String val) {
2513+
super(StorageRpc.Option.OBJECT_FILTER, val);
25142514
}
25152515

25162516
@Override

google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public Tuple<String, Iterable<StorageObject>> list(final String bucket, Map<Opti
498498
.setSoftDeleted(Option.SOFT_DELETED.getBoolean(options))
499499
.setIncludeFoldersAsPrefixes(Option.INCLUDE_FOLDERS_AS_PREFIXES.getBoolean(options))
500500
.setIncludeTrailingDelimiter(Option.INCLUDE_TRAILING_DELIMITER.getBoolean(options))
501-
.setFilter(Option.OBJECT_CONTEXTS_FILTER.getString(options));
501+
.setFilter(Option.OBJECT_FILTER.getString(options));
502502
setExtraHeaders(list, options);
503503
Objects objects = list.execute();
504504
Iterable<StorageObject> storageObjects =

google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/StorageRpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ enum Option {
8080
INCLUDE_FOLDERS_AS_PREFIXES("includeFoldersAsPrefixes"),
8181
INCLUDE_TRAILING_DELIMITER("includeTrailingDelimiter"),
8282
X_UPLOAD_CONTENT_LENGTH("x-upload-content-length"),
83-
OBJECT_CONTEXTS_FILTER("objectContextsFilter"),
83+
OBJECT_FILTER("objectFilter"),
8484
/**
8585
* An {@link com.google.common.collect.ImmutableMap ImmutableMap&lt;String, String>} of values
8686
* which will be set as additional headers on the request.

samples/install-without-bom/pom.xml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,12 @@
3030
<dependency>
3131
<groupId>com.google.cloud</groupId>
3232
<artifactId>google-cloud-storage</artifactId>
33-
<<<<<<< HEAD
34-
<version>2.56.0</version>
35-
=======
36-
<version>2.55.1-SNAPSHOT</version>
37-
>>>>>>> 6ded0abe (Add storage_set_object_contexts, storage_get_object_contexts and storage_list_object_contexts samples)
33+
<version>2.56.1-SNAPSHOT</version>
3834
</dependency>
3935
<dependency>
4036
<groupId>com.google.cloud</groupId>
4137
<artifactId>google-cloud-storage-control</artifactId>
42-
<<<<<<< HEAD
43-
<version>2.56.0</version>
44-
=======
45-
<version>2.55.1-SNAPSHOT</version>
46-
>>>>>>> 6ded0abe (Add storage_set_object_contexts, storage_get_object_contexts and storage_list_object_contexts samples)
38+
<version>2.56.1-SNAPSHOT</version>
4739
</dependency>
4840
<!-- [END storage_install_without_bom] -->
4941

samples/snippets/pom.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,7 @@
100100
<!-- tests jars aren't in the bom, manually include the version here -->
101101
<groupId>com.google.cloud</groupId>
102102
<artifactId>google-cloud-storage</artifactId>
103-
<<<<<<< HEAD
104-
<version>2.56.0</version>
105-
=======
106-
<version>2.55.1-SNAPSHOT</version>
107-
>>>>>>> 6ded0abe (Add storage_set_object_contexts, storage_get_object_contexts and storage_list_object_contexts samples)
103+
<version>2.56.1-SNAPSHOT</version>
108104
<classifier>tests</classifier>
109105
<scope>test</scope>
110106
</dependency>

samples/snippets/src/main/java/com/example/storage/object/ListObjectsWithContexts.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public static void listObjectsWithContexts(
4141
// String contextValue = "context-value-to-filter";
4242

4343
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
44-
Page<Blob> blobs =
45-
storage.list(bucketName, Storage.BlobListOption.withContext(contextKey, contextValue));
44+
String filter = String.format("contexts.\"%s\"=\"%s\"", contextKey, contextValue);
45+
Page<Blob> blobs = storage.list(bucketName, Storage.BlobListOption.filter(filter));
4646

4747
System.out.println(
4848
String.format(

0 commit comments

Comments
 (0)