Repository: jclouds
Updated Branches:
  refs/heads/master 1c6c36b81 -> 9ea76ebe4


JCLOUDS-651: GCS 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/84316704
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/84316704
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/84316704

Branch: refs/heads/master
Commit: 84316704c63c9246834f786546dcb73f1c41b8b1
Parents: d51bc04
Author: Andrew Gaul <[email protected]>
Authored: Thu Apr 9 21:25:21 2015 -0700
Committer: Andrew Gaul <[email protected]>
Committed: Thu Apr 9 21:27:05 2015 -0700

----------------------------------------------------------------------
 .../blobstore/GoogleCloudStorageBlobStore.java  | 57 +++++++++++++++-----
 1 file changed, 44 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/84316704/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobStore.java
----------------------------------------------------------------------
diff --git 
a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobStore.java
 
b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobStore.java
index 7ef2daf..dcc1d5a 100644
--- 
a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobStore.java
+++ 
b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobStore.java
@@ -23,7 +23,6 @@ import static 
org.jclouds.googlecloudstorage.domain.DomainResourceReferences.Obj
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.Set;
-import java.util.Map;
 
 import javax.inject.Inject;
 
@@ -66,6 +65,7 @@ import 
org.jclouds.googlecloudstorage.domain.templates.ObjectAccessControlsTempl
 import org.jclouds.googlecloudstorage.domain.templates.ObjectTemplate;
 import org.jclouds.googlecloudstorage.options.ListObjectOptions;
 import org.jclouds.http.HttpResponseException;
+import org.jclouds.io.ContentMetadata;
 import org.jclouds.io.Payload;
 
 import com.google.common.base.Charsets;
@@ -305,16 +305,47 @@ public final class GoogleCloudStorageBlobStore extends 
BaseBlobStore {
       return false;
    }
 
-    @Override
-    public String copyBlob(String fromContainer, String fromName, String 
toContainer, String toName, CopyOptions options) {
-
-        if (options == CopyOptions.NONE) {
-           return api.getObjectApi().copyObject(toContainer, toName, 
fromContainer, fromName).etag();
-        } else {
-            Map<String, String> map = options.getUserMetadata().get();
-            String contentType = api.getObjectApi().getObject(fromContainer, 
fromName).contentType();
-            ObjectTemplate template = new 
ObjectTemplate().customMetadata(map).contentType(contentType);
-            return api.getObjectApi().copyObject(toContainer, toName, 
fromContainer, fromName, template).etag();
-        }
-    }
+   @Override
+   public String copyBlob(String fromContainer, String fromName, String 
toContainer, String toName,
+         CopyOptions options) {
+      if (!options.getContentMetadata().isPresent() && 
!options.getUserMetadata().isPresent()) {
+         return api.getObjectApi().copyObject(toContainer, toName, 
fromContainer, fromName).etag();
+      }
+
+      ObjectTemplate template = new ObjectTemplate();
+
+      if (options.getContentMetadata().isPresent()) {
+         ContentMetadata contentMetadata = options.getContentMetadata().get();
+
+         String contentDisposition = contentMetadata.getContentDisposition();
+         if (contentDisposition != null) {
+            template.contentDisposition(contentDisposition);
+         }
+
+         // TODO: causes failures with subsequent GET operations:
+         // HTTP/1.1 failed with response: HTTP/1.1 503 Service Unavailable; 
content: [Service Unavailable]
+/*
+         String contentEncoding = contentMetadata.getContentEncoding();
+         if (contentEncoding != null) {
+            template.contentEncoding(contentEncoding);
+         }
+*/
+
+         String contentLanguage = contentMetadata.getContentLanguage();
+         if (contentLanguage != null) {
+            template.contentLanguage(contentLanguage);
+         }
+
+         String contentType = contentMetadata.getContentType();
+         if (contentType != null) {
+            template.contentType(contentType);
+         }
+      }
+
+      if (options.getUserMetadata().isPresent()) {
+         template.customMetadata(options.getUserMetadata().get());
+      }
+
+      return api.getObjectApi().copyObject(toContainer, toName, fromContainer, 
fromName, template).etag();
+   }
 }

Reply via email to