You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2015/04/09 07:59:46 UTC

[3/4] jclouds git commit: JCLOUDS-651: S3 copy object content metadata

JCLOUDS-651: S3 copy object content metadata


Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/a43dcece
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/a43dcece
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/a43dcece

Branch: refs/heads/master
Commit: a43dcece16b7eb0569cfe2d96c76221c40356c27
Parents: a761f4c
Author: Andrew Gaul <ga...@apache.org>
Authored: Mon Apr 6 17:51:51 2015 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Wed Apr 8 18:07:28 2015 -0700

----------------------------------------------------------------------
 .../org/jclouds/s3/blobstore/S3BlobStore.java   | 27 ++++++--
 .../jclouds/s3/options/CopyObjectOptions.java   | 67 +++++++++++++++++++-
 2 files changed, 89 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/a43dcece/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java
----------------------------------------------------------------------
diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java
index cd38e52..c93f7e2 100644
--- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java
+++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java
@@ -47,6 +47,7 @@ import org.jclouds.blobstore.util.BlobUtils;
 import org.jclouds.collect.Memoized;
 import org.jclouds.domain.Location;
 import org.jclouds.http.options.GetOptions;
+import org.jclouds.io.ContentMetadata;
 import org.jclouds.s3.S3Client;
 import org.jclouds.s3.blobstore.functions.BlobToObject;
 import org.jclouds.s3.blobstore.functions.BucketToResourceList;
@@ -282,10 +283,28 @@ public class S3BlobStore extends BaseBlobStore {
          CopyOptions options) {
       CopyObjectOptions s3Options = new CopyObjectOptions();
 
-      // TODO: content disposition
-      // TODO: content encoding
-      // TODO: content language
-      // TODO: content type
+      Optional<ContentMetadata> contentMetadata = options.getContentMetadata();
+      if (contentMetadata.isPresent()) {
+         String contentDisposition = contentMetadata.get().getContentDisposition();
+         if (contentDisposition != null) {
+            s3Options.contentDisposition(contentDisposition);
+         }
+
+         String contentEncoding = contentMetadata.get().getContentEncoding();
+         if (contentEncoding != null) {
+            s3Options.contentEncoding(contentEncoding);
+         }
+
+         String contentLanguage = contentMetadata.get().getContentLanguage();
+         if (contentLanguage != null) {
+            s3Options.contentLanguage(contentLanguage);
+         }
+
+         String contentType = contentMetadata.get().getContentType();
+         if (contentType != null) {
+            s3Options.contentType(contentType);
+         }
+      }
 
       Optional<Map<String, String>> userMetadata = options.getUserMetadata();
       if (userMetadata.isPresent()) {

http://git-wip-us.apache.org/repos/asf/jclouds/blob/a43dcece/apis/s3/src/main/java/org/jclouds/s3/options/CopyObjectOptions.java
----------------------------------------------------------------------
diff --git a/apis/s3/src/main/java/org/jclouds/s3/options/CopyObjectOptions.java b/apis/s3/src/main/java/org/jclouds/s3/options/CopyObjectOptions.java
index 25f833c..2370bf5 100644
--- a/apis/s3/src/main/java/org/jclouds/s3/options/CopyObjectOptions.java
+++ b/apis/s3/src/main/java/org/jclouds/s3/options/CopyObjectOptions.java
@@ -43,6 +43,7 @@ import org.jclouds.s3.domain.CannedAccessPolicy;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMultimap;
 import com.google.common.collect.Multimap;
+import com.google.common.net.HttpHeaders;
 
 /**
  * Contains options supported in the REST API for the COPY object operation.
@@ -71,6 +72,10 @@ import com.google.common.collect.Multimap;
 public class CopyObjectOptions extends BaseHttpRequestOptions {
    private static final DateService dateService = new SimpleDateFormatDateService();
    public static final CopyObjectOptions NONE = new CopyObjectOptions();
+   private String contentDisposition;
+   private String contentEncoding;
+   private String contentLanguage;
+   private String contentType;
    private Map<String, String> metadata;
    private CannedAccessPolicy acl = CannedAccessPolicy.PRIVATE;
 
@@ -249,16 +254,56 @@ public class CopyObjectOptions extends BaseHttpRequestOptions {
       for (Entry<String, String> entry : headers.entries()) {
          returnVal.put(entry.getKey().replace(DEFAULT_AMAZON_HEADERTAG, headerTag), entry.getValue());
       }
+      boolean replace = false;
+      if (contentDisposition != null) {
+         returnVal.put(HttpHeaders.CONTENT_DISPOSITION, contentDisposition);
+         replace = true;
+      }
+      if (contentEncoding != null) {
+         returnVal.put(HttpHeaders.CONTENT_ENCODING, contentEncoding);
+         replace = true;
+      }
+      if (contentLanguage != null) {
+         returnVal.put(HttpHeaders.CONTENT_LANGUAGE, contentLanguage);
+         replace = true;
+      }
+      if (contentType != null) {
+         returnVal.put(HttpHeaders.CONTENT_TYPE, contentType);
+         replace = true;
+      }
       if (metadata != null) {
-         returnVal.put(METADATA_DIRECTIVE.replace(DEFAULT_AMAZON_HEADERTAG, headerTag), "REPLACE");
          for (Map.Entry<String, String> entry : metadata.entrySet()) {
             String key = entry.getKey();
             returnVal.put(key.startsWith(metadataPrefix) ? key : metadataPrefix + key, entry.getValue());
          }
+         replace = true;
+      }
+      if (replace) {
+         returnVal.put(METADATA_DIRECTIVE.replace(DEFAULT_AMAZON_HEADERTAG, headerTag), "REPLACE");
       }
       return returnVal.build();
    }
 
+   public CopyObjectOptions contentDisposition(String contentDisposition) {
+      this.contentDisposition = checkNotNull(contentDisposition, "contentDisposition");
+      return this;
+   }
+
+   public CopyObjectOptions contentEncoding(String contentEncoding) {
+      this.contentEncoding = checkNotNull(contentEncoding, "contentEncoding");
+      return this;
+   }
+
+   public CopyObjectOptions contentLanguage(String contentLanguage) {
+      this.contentLanguage = checkNotNull(contentLanguage, "contentLanguage");
+      return this;
+   }
+
+   public CopyObjectOptions contentType(String contentType) {
+      this.contentType = checkNotNull(contentType, "contentType");
+      return this;
+   }
+
    /**
     * Use the provided metadata instead of what is on the source object.
     */
@@ -309,6 +354,26 @@ public class CopyObjectOptions extends BaseHttpRequestOptions {
          return options.ifSourceETagDoesntMatch(eTag);
       }
 
+      public static CopyObjectOptions contentDisposition(String contentDisposition) {
+         CopyObjectOptions options = new CopyObjectOptions();
+         return options.contentDisposition(contentDisposition);
+      }
+
+      public static CopyObjectOptions contentEncoding(String contentEncoding) {
+         CopyObjectOptions options = new CopyObjectOptions();
+         return options.contentEncoding(contentEncoding);
+      }
+
+      public static CopyObjectOptions contentLanguage(String contentLanguage) {
+         CopyObjectOptions options = new CopyObjectOptions();
+         return options.contentLanguage(contentLanguage);
+      }
+
+      public static CopyObjectOptions contentType(String contentType) {
+         CopyObjectOptions options = new CopyObjectOptions();
+         return options.contentType(contentType);
+      }
+
       /**
        * @see #overrideMetadataWith(Multimap)
        */