Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sinhaashish committed Jun 15, 2020
1 parent 0292d83 commit 0cf5205
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 788 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/io/minio/BaseArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ protected void validateNullOrNotEmptyString(String arg, String argName) {
}
}

protected void validateNullOrEmpty(Long arg, String argName) {
if (arg != null && arg < 0) {
protected void validateNullOrPositive(Number arg, String argName) {
if (arg != null && arg.longValue() < 0) {
throw new IllegalArgumentException(argName + " cannot be non-negative.");
}
}
Expand Down
14 changes: 10 additions & 4 deletions api/src/main/java/io/minio/ComposeObjectArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import java.util.List;

public class ComposeObjectArgs extends ObjectWriteArgs {
List<ComposeSourceArgs> sources;
List<ComposeSource> sources;

public List<ComposeSourceArgs> sources() {
public List<ComposeSource> sources() {
return sources;
}

Expand All @@ -30,13 +30,19 @@ public static Builder builder() {
}

public static final class Builder extends ObjectWriteArgs.Builder<Builder, ComposeObjectArgs> {
public Builder sources(List<ComposeSourceArgs> sources) {
@Override
protected void validate(ComposeObjectArgs args) {
super.validate(args);
validateSources(args.sources);
}

public Builder sources(List<ComposeSource> sources) {
validateSources(sources);
operations.add(args -> args.sources = sources);
return this;
}

private void validateSources(List<ComposeSourceArgs> sources) {
private void validateSources(List<ComposeSource> sources) {
if (sources.isEmpty()) {
throw new IllegalArgumentException("compose sources cannot be empty");
}
Expand Down
223 changes: 111 additions & 112 deletions api/src/main/java/io/minio/ComposeSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,105 +17,108 @@

package io.minio;

import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import java.time.ZonedDateTime;

/** Source information to compose object. */
public class ComposeSource {
private String bucketName;
private String objectName;
public class ComposeSource extends ObjectVersionArgs {
private Long offset;
private Long length;
private Map<String, String> headerMap;
private CopyConditions copyConditions;
private ServerSideEncryptionCustomerKey ssec;
private long objectSize;
private Map<String, String> headers;
private String matchETag;
private String notMatchETag;
private ZonedDateTime modifiedSince;
private ZonedDateTime unmodifiedSince;
private ServerSideEncryptionCustomerKey ssec;

private Multimap<String, String> headers;

public Long offset() {
return offset;
}

public Long length() {
return length;
}

public long objectSize() {
return objectSize;
}

public ServerSideEncryptionCustomerKey srcSsec() {
return ssec;
}

/** Create new ComposeSource for given bucket and object. */
public ComposeSource(String bucketName, String objectName) throws IllegalArgumentException {
this(bucketName, objectName, null, null, null, null, null);
public String matchETag() {
return matchETag;
}

/** Create new ComposeSource for given bucket, object, offset and length. */
public ComposeSource(String bucketName, String objectName, Long offset, Long length)
throws IllegalArgumentException {
this(bucketName, objectName, offset, length, null, null, null);
public String notMatchETag() {
return notMatchETag;
}

/** Create new ComposeSource for given bucket, object, offset, length and headerMap. */
public ComposeSource(
String bucketName, String objectName, Long offset, Long length, Map<String, String> headerMap)
throws IllegalArgumentException {
this(bucketName, objectName, offset, length, headerMap, null, null);
public ZonedDateTime modifiedSince() {
return modifiedSince;
}

/**
* Create new ComposeSource for given bucket, object, offset, length, headerMap and
* CopyConditions.
*/
public ComposeSource(
String bucketName,
String objectName,
Long offset,
Long length,
Map<String, String> headerMap,
CopyConditions copyConditions)
throws IllegalArgumentException {
this(bucketName, objectName, offset, length, headerMap, copyConditions, null);
public ZonedDateTime unmodifiedSince() {
return unmodifiedSince;
}

/**
* Creates new ComposeSource for given bucket, object, offset, length, headerMap, CopyConditions
* and server side encryption.
*
* @throws IllegalArgumentException upon invalid value is passed to a method.
*/
public ComposeSource(
String bucketName,
String objectName,
Long offset,
Long length,
Map<String, String> headerMap,
CopyConditions copyConditions,
ServerSideEncryptionCustomerKey ssec)
throws IllegalArgumentException {
if (bucketName == null) {
throw new IllegalArgumentException("Source bucket name cannot be empty");
public Multimap<String, String> headers() {
return headers;
}

public ServerSideEncryptionCustomerKey ssec() {
return ssec;
}

public static Builder builder() {
return new Builder();
}

/** Constructs header . */
public void buildHeaders(long objectSize, String etag) throws IllegalArgumentException {
validateSize(objectSize);
Multimap<String, String> headers = HashMultimap.create();
headers.put("x-amz-copy-source", S3Escaper.encodePath(bucketName + "/" + objectName));
headers.put("x-amz-copy-source-if-match", etag);

if (extraHeaders() != null) {
headers.putAll(extraHeaders());
}

if (objectName == null) {
throw new IllegalArgumentException("Source object name cannot be empty");
if (matchETag != null) {
headers.put("x-amz-copy-source-if-match", matchETag);
}

if (offset != null && offset < 0) {
throw new IllegalArgumentException("Offset cannot be negative");
if (ssec != null) {
headers.putAll(Multimaps.forMap(ssec.copySourceHeaders()));
}

if (length != null && length < 0) {
throw new IllegalArgumentException("Length cannot be negative");
if (notMatchETag != null) {
headers.put("x-amz-copy-source-if-none-match", notMatchETag);
}

if (length != null && offset == null) {
offset = 0L;
if (modifiedSince != null) {
headers.put(
"x-amz-copy-source-if-modified-since",
modifiedSince.format(Time.HTTP_HEADER_DATE_FORMAT));
}

this.bucketName = bucketName;
this.objectName = objectName;
this.offset = offset;
this.length = length;
if (headerMap != null) {
this.headerMap = Collections.unmodifiableMap(headerMap);
} else {
this.headerMap = null;
if (unmodifiedSince != null) {
headers.put(
"x-amz-copy-source-if-unmodified-since",
unmodifiedSince.format(Time.HTTP_HEADER_DATE_FORMAT));
}
this.copyConditions = copyConditions;
this.ssec = ssec;

this.objectSize = objectSize;
this.headers = headers;
}

/** Constructs header . */
public void buildHeaders(long objectSize, String etag) throws IllegalArgumentException {
private void validateSize(long objectSize) throws IllegalArgumentException {
if (offset != null && offset >= objectSize) {
throw new IllegalArgumentException(
"source "
Expand Down Expand Up @@ -153,56 +156,52 @@ public void buildHeaders(long objectSize, String etag) throws IllegalArgumentExc
+ objectSize);
}
}
}

Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
headers.put("x-amz-copy-source", S3Escaper.encodePath(bucketName + "/" + objectName));
headers.put("x-amz-copy-source-if-match", etag);

if (headerMap != null) {
headers.putAll(headerMap);
/** Argument builder of {@link ComposeSource}. */
public static final class Builder extends ObjectVersionArgs.Builder<Builder, ComposeSource> {
@Override
protected void validate(ComposeSource args) {
super.validate(args);
}

if (copyConditions != null) {
headers.putAll(copyConditions.getConditions());
public Builder offset(long offset) {
validateNullOrPositive(offset, "offset");
operations.add(args -> args.offset = offset);
return this;
}

if (ssec != null) {
headers.putAll(ssec.copySourceHeaders());
public Builder length(long length) {
validateNullOrPositive(length, "length");
operations.add(args -> args.length = length);
return this;
}

this.objectSize = objectSize;
this.headers = Collections.unmodifiableMap(headers);
}

public String bucketName() {
return bucketName;
}

public String objectName() {
return objectName;
}

public Long offset() {
return offset;
}

public Long length() {
return length;
}
public Builder ssec(ServerSideEncryptionCustomerKey ssec) {
operations.add(args -> args.ssec = ssec);
return this;
}

public CopyConditions copyConditions() {
return copyConditions;
}
public Builder matchETag(String etag) {
validateNullOrNotEmptyString(etag, "etag");
operations.add(args -> args.matchETag = etag);
return this;
}

public ServerSideEncryptionCustomerKey ssec() {
return ssec;
}
public Builder notMatchETag(String etag) {
validateNullOrNotEmptyString(etag, "etag");
operations.add(args -> args.notMatchETag = etag);
return this;
}

public Map<String, String> headers() {
return headers;
}
public Builder modifiedSince(ZonedDateTime modifiedTime) {
operations.add(args -> args.modifiedSince = modifiedTime);
return this;
}

public long objectSize() {
return objectSize;
public Builder unmodifiedSince(ZonedDateTime unmodifiedTime) {
operations.add(args -> args.unmodifiedSince = unmodifiedTime);
return this;
}
}
}
Loading

0 comments on commit 0cf5205

Please sign in to comment.