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/08/12 00:16:32 UTC

jclouds git commit: JCLOUDS-872: Swift copy object and append metadata

Repository: jclouds
Updated Branches:
  refs/heads/master 449eeec8e -> e2b695046


JCLOUDS-872: Swift copy object and append metadata

The existing method replaces metadata.


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

Branch: refs/heads/master
Commit: e2b6950462f58f4b3a2836be7fb5c366789b0130
Parents: 449eeec
Author: Andrew Gaul <ga...@apache.org>
Authored: Fri Aug 7 13:37:58 2015 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Tue Aug 11 13:26:56 2015 -0700

----------------------------------------------------------------------
 .../openstack/swift/v1/features/ObjectApi.java  | 34 +++++++++++++++++++-
 .../swift/v1/features/ObjectApiLiveTest.java    | 25 ++++++++++----
 2 files changed, 52 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/e2b69504/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java
----------------------------------------------------------------------
diff --git a/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java
index 3d41c4a..4063bfc 100644
--- a/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java
+++ b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java
@@ -287,7 +287,7 @@ public interface ObjectApi {
                 @PathParam("sourceObject") String sourceObject);
 
    /**
-    * Copies an object from one container to another.
+    * Copies an object from one container to another, replacing metadata.
     *
     * <h3>NOTE</h3>
     * This is a server side copy.
@@ -318,4 +318,36 @@ public interface ObjectApi {
          @BinderParam(BindObjectMetadataToHeaders.class) Map<String, String> userMetadata,
          @BinderParam(BindToHeaders.class) Map<String, String> objectMetadata);
 
+
+   /**
+    * Copies an object from one container to another, appending metadata.
+    *
+    * <h3>NOTE</h3>
+    * This is a server side copy.
+    *
+    * @param destinationObject
+    *           the destination object name.
+    * @param sourceContainer
+    *           the source container name.
+    * @param sourceObject
+    *           the source object name.
+    * @param userMetadata
+    *           Freeform metadata for the object, automatically prefixed/escaped
+    * @param objectMetadata
+    *           Unprefixed/unescaped metadata, such as Content-Disposition
+    *
+    * @return {@code true} if the object was successfully copied, {@code false} if not.
+    *
+    * @throws KeyNotFoundException if the source or destination container do not exist.
+    */
+   @Named("object:copy")
+   @PUT
+   @Path("/{destinationObject}")
+   @Headers(keys = OBJECT_COPY_FROM, values = "/{sourceContainer}/{sourceObject}")
+   @Fallback(FalseOnKeyNotFound.class)
+   boolean copyAppendMetadata(@PathParam("destinationObject") String destinationObject,
+         @PathParam("sourceContainer") String sourceContainer,
+         @PathParam("sourceObject") String sourceObject,
+         @BinderParam(BindObjectMetadataToHeaders.class) Map<String, String> userMetadata,
+         @BinderParam(BindToHeaders.class) Map<String, String> objectMetadata);
 }

http://git-wip-us.apache.org/repos/asf/jclouds/blob/e2b69504/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java
index bb0131d..6b7f2a5 100644
--- a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java
+++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java
@@ -16,6 +16,7 @@
  */
 package org.jclouds.openstack.swift.v1.features;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.jclouds.http.options.GetOptions.Builder.tail;
 import static org.jclouds.io.Payloads.newByteSourcePayload;
 import static org.jclouds.openstack.swift.v1.options.ListContainerOptions.Builder.marker;
@@ -189,11 +190,10 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
          SwiftObject object = destApi.get(destinationObject);
          checkObject(object);
 
-         // check the copy operation
-         assertTrue(destApi.copy(destinationObject, sourceContainer, sourceObjectName,
+         // check the copy append metadata operation
+         assertTrue(destApi.copyAppendMetadata(destinationObject, sourceContainer, sourceObjectName,
                ImmutableMap.<String, String>of("additionalUserMetakey", "additionalUserMetavalue"),
                ImmutableMap.of("Content-Disposition", "attachment; filename=\"updatedname.txt\"")));
-         assertNotNull(destApi.get(destinationObject));
 
          // now get a real SwiftObject
          SwiftObject destSwiftObject = destApi.get(destinationObject);
@@ -205,8 +205,8 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
           */
          Multimap<String, String> srcHeaders = null;
          Multimap<String, String> destHeaders = null;
-         srcHeaders = srcApi.get(sourceObjectName).getHeaders();
-         destHeaders = destApi.get(destinationObject).getHeaders();
+         srcHeaders = srcApi.getWithoutBody(sourceObjectName).getHeaders();
+         destHeaders = destSwiftObject.getHeaders();
          for (Entry<String, String> header : srcHeaders.entries()) {
             if (header.getKey().equals("Date"))continue;
             if (header.getKey().equals("Last-Modified"))continue;
@@ -214,7 +214,20 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
             if (header.getKey().equals("X-Timestamp"))continue;
             assertTrue(destHeaders.containsEntry(header.getKey(), header.getValue()), "Could not find: " + header);
          }
-         assertEquals(destApi.get(destinationObject).getPayload().getContentMetadata().getContentDisposition(), "attachment; filename=\"updatedname.txt\"");
+         assertEquals(destSwiftObject.getPayload().getContentMetadata().getContentDisposition(), "attachment; filename=\"updatedname.txt\"");
+
+         // check the copy replace metadata operation
+         assertTrue(destApi.copy(destinationObject, sourceContainer, sourceObjectName,
+               ImmutableMap.<String, String>of("key3", "value3"),
+               ImmutableMap.of("Content-Disposition", "attachment; filename=\"updatedname.txt\"")));
+
+         // now get a real SwiftObject
+         destSwiftObject = destApi.get(destinationObject);
+         assertEquals(toStringAndClose(destSwiftObject.getPayload().openStream()), "swifty");
+
+         destHeaders = destSwiftObject.getHeaders();
+         assertThat(destHeaders.get("X-Object-Meta-Key3")).containsExactly("value3");
+         assertEquals(destSwiftObject.getPayload().getContentMetadata().getContentDisposition(), "attachment; filename=\"updatedname.txt\"");
 
          // test exception thrown on bad source name
          try {