Skip to content

Commit

Permalink
Add versioning support in listObjects API
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurugana committed Jun 19, 2020
1 parent 6d51336 commit 5b356a3
Show file tree
Hide file tree
Showing 15 changed files with 829 additions and 338 deletions.
139 changes: 108 additions & 31 deletions api/src/main/java/io/minio/ListObjectsArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,77 @@

/** Argument class of @see #listObjects(ListObjectsArgs args). */
public class ListObjectsArgs extends BucketArgs {
private String continuationToken;
private String delimiter;
private boolean fetchOwner;
private Integer maxKeys;
private String prefix;
private String startAfter;
private boolean includeUserMetadata;
private String delimiter = "";
private boolean useUrlEncodingType = true;
private String keyMarker; // 'marker' for ListObjectsV1 and 'startAfter' for ListObjectsV2.
private int maxKeys = 1000;
private String prefix = "";
private String continuationToken; // only for ListObjectsV2.
private boolean fetchOwner; // only for ListObjectsV2.
private String versionIdMarker; // only for GetObjectVersions.
private boolean includeUserMetadata; // MinIO extension applicable to ListObjectsV2.
private boolean recursive;
private boolean useVersion1;
private boolean useApiVersion1;
private boolean includeVersions;

public String continuationToken() {
return continuationToken;
public String delimiter() {
if (recursive) {
return "";
}

return (delimiter.isEmpty() ? "/" : delimiter);
}

public boolean includeUserMetadata() {
return includeUserMetadata;
public boolean useUrlEncodingType() {
return useUrlEncodingType;
}

public String keyMarker() {
return keyMarker;
}

public String marker() {
return keyMarker;
}

public String startAfter() {
return startAfter;
return keyMarker;
}

public int maxKeys() {
return maxKeys;
}

public String prefix() {
return prefix;
}

public Integer maxKeys() {
return maxKeys;
public String continuationToken() {
return continuationToken;
}

public boolean fetchOwner() {
return fetchOwner;
}

public String delimiter() {
return delimiter;
public String versionIdMarker() {
return versionIdMarker;
}

public boolean includeUserMetadata() {
return includeUserMetadata;
}

public boolean recursive() {
return recursive;
}

public boolean useVersion1() {
return useVersion1;
public boolean useApiVersion1() {
return useApiVersion1;
}

public boolean includeVersions() {
return includeVersions;
}

public static Builder builder() {
Expand All @@ -70,28 +97,67 @@ public static Builder builder() {

/** Argument builder of @see MinioClient#listObjects(ListObjectArgs args). */
public static final class Builder extends BucketArgs.Builder<Builder, ListObjectsArgs> {
public Builder continuationToken(String continuationToken) {
operations.add(args -> args.continuationToken = continuationToken);
@Override
protected void validate(ListObjectsArgs args) {
super.validate(args);

if (args.useApiVersion1() || args.includeVersions()) {
if (args.continuationToken() != null || args.fetchOwner() || args.includeUserMetadata()) {
throw new IllegalArgumentException(
"continuation token/fetch owner/include metadata are supported only"
+ " for list objects version 2");
}
}

if (args.versionIdMarker != null && args.useApiVersion1()) {
throw new IllegalArgumentException(
"version ID marker is not supported for list objects version 1");
}
}

public Builder delimiter(String delimiter) {
operations.add(args -> args.delimiter = (delimiter == null ? "" : delimiter));
return this;
}

public Builder includeUserMetadata(boolean includeUserMetadata) {
operations.add(args -> args.includeUserMetadata = includeUserMetadata);
public Builder useUrlEncodingType(boolean flag) {
operations.add(args -> args.useUrlEncodingType = flag);
return this;
}

public Builder keyMarker(String keyMarker) {
validateNullOrNotEmptyString(keyMarker, "key marker");
operations.add(args -> args.keyMarker = keyMarker);
return this;
}

public Builder marker(String marker) {
operations.add(args -> args.keyMarker = marker);
return this;
}

public Builder startAfter(String startAfter) {
operations.add(args -> args.startAfter = startAfter);
operations.add(args -> args.keyMarker = startAfter);
return this;
}

public Builder maxKeys(int maxKeys) {
if (maxKeys < 1 || maxKeys > 1000) {
throw new IllegalArgumentException("max keys must be between 1 and 1000");
}

operations.add(args -> args.maxKeys = maxKeys);
return this;
}

public Builder prefix(String prefix) {
operations.add(args -> args.prefix = prefix);
operations.add(args -> args.prefix = (prefix == null ? "" : prefix));
return this;
}

public Builder maxKeys(Integer maxKeys) {
operations.add(args -> args.maxKeys = maxKeys);
public Builder continuationToken(String continuationToken) {
validateNullOrNotEmptyString(continuationToken, "continuation token");
operations.add(args -> args.continuationToken = continuationToken);
return this;
}

Expand All @@ -100,8 +166,14 @@ public Builder fetchOwner(boolean fetchOwner) {
return this;
}

public Builder delimiter(String delimiter) {
operations.add(args -> args.delimiter = delimiter);
public Builder versionIdMarker(String versionIdMarker) {
validateNullOrNotEmptyString(versionIdMarker, "version ID marker");
operations.add(args -> args.versionIdMarker = versionIdMarker);
return this;
}

public Builder includeUserMetadata(boolean includeUserMetadata) {
operations.add(args -> args.includeUserMetadata = includeUserMetadata);
return this;
}

Expand All @@ -110,8 +182,13 @@ public Builder recursive(boolean recursive) {
return this;
}

public Builder useVersion1(boolean useVersion1) {
operations.add(args -> args.useVersion1 = useVersion1);
public Builder useApiVersion1(boolean useApiVersion1) {
operations.add(args -> args.useApiVersion1 = useApiVersion1);
return this;
}

public Builder includeVersions(boolean includeVersions) {
operations.add(args -> args.includeVersions = includeVersions);
return this;
}
}
Expand Down
Loading

0 comments on commit 5b356a3

Please sign in to comment.