diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/strategy/internal/SequentialMultipartUploadStrategy.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/strategy/internal/SequentialMultipartUploadStrategy.java index 065f002e4c..83b38233da 100644 --- a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/strategy/internal/SequentialMultipartUploadStrategy.java +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/strategy/internal/SequentialMultipartUploadStrategy.java @@ -87,7 +87,9 @@ public final class SequentialMultipartUploadStrategy extends MultipartUploadStra sourceList.add(object); } - ComposeObjectTemplate template = ComposeObjectTemplate.create(sourceList, destination); + ComposeObjectTemplate template = ComposeObjectTemplate.builder().fromGoogleCloudStorageObject(sourceList) + .destination(destination).build(); + return api.getObjectApi().composeObjects(container, key, template).etag(); } else { return api.getObjectApi() diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/templates/ComposeObjectTemplate.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/templates/ComposeObjectTemplate.java index 669a8f1f86..4ad8d5ec9c 100644 --- a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/templates/ComposeObjectTemplate.java +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/templates/ComposeObjectTemplate.java @@ -14,25 +14,110 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.jclouds.googlecloudstorage.domain.templates; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.ArrayList; +import java.util.Collection; import java.util.List; import org.jclouds.googlecloudstorage.domain.GoogleCloudStorageObject; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; import com.google.auto.value.AutoValue; +import com.google.common.collect.ImmutableList; @AutoValue public abstract class ComposeObjectTemplate { - private final String kind = "storage/composeRequest"; + @AutoValue + public abstract static class SourceObject { - public abstract List sourceObjects(); + @AutoValue + public abstract static class ObjectPreconditions { + @Nullable public abstract long ifGenerationMatch(); + @SerializedNames({"ifGenerationMatch"}) + public static ObjectPreconditions create(long ifGenerationMatch){ + return new AutoValue_ComposeObjectTemplate_SourceObject_ObjectPreconditions(ifGenerationMatch); + } + + ObjectPreconditions(){ + } + } + + public abstract String name(); + @Nullable public abstract Long generation(); + @Nullable public abstract ObjectPreconditions objectPreconditions(); + + public static SourceObject nameOnly(String name){ + return create(name, null, null); + } + + public static SourceObject createWithPrecondition(String name, Long generation, Long objectPreconditions){ + return create(name, generation, ObjectPreconditions.create(objectPreconditions)); + } + + @SerializedNames({ "name", "generation", "objectPreconditions"}) + public static SourceObject create(String name, @Nullable Long generation, + @Nullable ObjectPreconditions objectPreconditions) { + return new AutoValue_ComposeObjectTemplate_SourceObject(name, generation, objectPreconditions); + } + + SourceObject(){ + } + } + + public abstract List sourceObjects(); public abstract ObjectTemplate destination(); - public static ComposeObjectTemplate create(List sourceObjects, ObjectTemplate destination) { + @SerializedNames({"sourceObjects", "destination"}) + public static ComposeObjectTemplate create(List sourceObjects, ObjectTemplate destination) { return new AutoValue_ComposeObjectTemplate(sourceObjects, destination); } + + public static Builder builder(){ + return new Builder(); + } + + ComposeObjectTemplate() { + } + + public static class Builder { + private ImmutableList sourceObjects; + private ObjectTemplate destination; + + Builder() { + } + + public Builder fromGoogleCloudStorageObject(Collection objects) { + ImmutableList.Builder sourceObjects = new ImmutableList.Builder(); + for (GoogleCloudStorageObject obj : objects) { + sourceObjects.add(SourceObject.createWithPrecondition(obj.name(), obj.generation(), obj.generation())); + } + this.sourceObjects = sourceObjects.build(); + return this; + } + + public Builder fromNames(List SourceObjectNames) { + ArrayList sourceObjects = new ArrayList(); + for (String name : SourceObjectNames) { + sourceObjects.add(SourceObject.nameOnly(name)); + } + this.sourceObjects = ImmutableList.copyOf(sourceObjects); + return this; + } + + public Builder destination(ObjectTemplate destination) { + checkNotNull(destination, "destination"); + this.destination = destination; + return this; + } + + public ComposeObjectTemplate build() { + return ComposeObjectTemplate.create(sourceObjects, destination); + } + } } diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java index 3cef89387f..44232a11c1 100644 --- a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java @@ -255,7 +255,10 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest { sourceList.add(api().getObject(BUCKET_NAME2, UPLOAD_OBJECT_NAME)); sourceList.add(api().getObject(BUCKET_NAME2, COPIED_OBJECT_NAME)); - ComposeObjectTemplate requestTemplate = ComposeObjectTemplate.create(sourceList, destination); + ComposeObjectTemplate requestTemplate = ComposeObjectTemplate.builder() + .fromGoogleCloudStorageObject(sourceList) + .destination(destination) + .build(); GoogleCloudStorageObject gcsObject = api().composeObjects(BUCKET_NAME2, COMPOSED_OBJECT, requestTemplate); @@ -273,8 +276,10 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest { sourceList.add(api().getObject(BUCKET_NAME2, UPLOAD_OBJECT_NAME)); sourceList.add(api().getObject(BUCKET_NAME2, COPIED_OBJECT_NAME)); - ComposeObjectTemplate requestTemplate = ComposeObjectTemplate.create(sourceList, destination); - + ComposeObjectTemplate requestTemplate = ComposeObjectTemplate.builder() + .fromGoogleCloudStorageObject(sourceList) + .destination(destination) + .build(); ComposeObjectOptions options = new ComposeObjectOptions().destinationPredefinedAcl( DestinationPredefinedAcl.BUCKET_OWNER_READ).ifMetagenerationNotMatch(RANDOM_LONG); diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiMockTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiMockTest.java index af224d4ac8..d30deac381 100644 --- a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiMockTest.java +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiMockTest.java @@ -176,8 +176,9 @@ public class ObjectApiMockTest extends BaseGoogleCloudStorageApiMockTest { ObjectTemplate template = new ObjectTemplate().name("file_name").size((long) 1000).crc32c("crc32c"); - ComposeObjectTemplate composeTemplate = ComposeObjectTemplate.create( - new ParseGoogleCloudStorageObjectListTest().expected(), template); + ComposeObjectTemplate composeTemplate = ComposeObjectTemplate.builder() + .fromGoogleCloudStorageObject(new ParseGoogleCloudStorageObjectListTest().expected()) + .destination(template).build(); assertEquals(objectApi().composeObjects("destination_bucket", "destination_object", composeTemplate), new ParseGoogleCloudStorageObject().expected()); @@ -189,8 +190,9 @@ public class ObjectApiMockTest extends BaseGoogleCloudStorageApiMockTest { server.enqueue(jsonResponse("/object_get.json")); ObjectTemplate template = new ObjectTemplate().name("file_name").size((long) 1000).crc32c("crc32c"); - ComposeObjectTemplate composeTemplate = ComposeObjectTemplate.create( - new ParseGoogleCloudStorageObjectListTest().expected(), template); + ComposeObjectTemplate composeTemplate = ComposeObjectTemplate.builder() + .fromGoogleCloudStorageObject(new ParseGoogleCloudStorageObjectListTest().expected()) + .destination(template).build(); ComposeObjectOptions options = new ComposeObjectOptions() .destinationPredefinedAcl(DestinationPredefinedAcl.BUCKET_OWNER_FULLCONTROL) diff --git a/providers/google-cloud-storage/src/test/resources/object_compose_request.json b/providers/google-cloud-storage/src/test/resources/object_compose_request.json index 93cbfc7b2c..0ac480389f 100644 --- a/providers/google-cloud-storage/src/test/resources/object_compose_request.json +++ b/providers/google-cloud-storage/src/test/resources/object_compose_request.json @@ -1,54 +1,23 @@ { "sourceObjects": [ { - "id": "test/file_name/1000", - "selfLink": "https://www.googleapis.com/storage/v1/b/test/o/file_name", - "etag": "etag", "name": "file_name", - "bucket": "test", "generation": 1000, - "metageneration": 8, - "contentType": "application/x-tar", - "updated": "2014-09-27T00:01:44.819Z", - "storageClass": "STANDARD", - "size": 1000, - "md5Hash": "md5Hash", - "mediaLink": "https://www.googleapis.com/download/storage/v1/b/test/o/file_name?generation=1000&alt=media", - "metadata": {}, - "acl": [], - "owner": { - "entity": "entity", - "entityId": "entityId" - }, - "crc32c": "crc32c" + "objectPreconditions": { + "ifGenerationMatch": 1000 + } }, { - "id": "test/file_name2/1000", - "selfLink": "https://www.googleapis.com/storage/v1/b/test/o/file_name2", - "etag": "etag", "name": "file_name2", - "bucket": "test", "generation": 1001, - "metageneration": 9, - "contentType": "image/png", - "updated": "2014-09-27T00:01:44.819Z", - "storageClass": "STANDARD", - "size": 10, - "md5Hash": "md5Hash", - "mediaLink": "https://www.googleapis.com/download/storage/v1/b/test/o/file_name2?generation=1001&alt=media", - "metadata": {}, - "acl": [], - "owner": { - "entity": "entity", - "entityId": "entityId" - }, - "crc32c": "crc32c" + "objectPreconditions": { + "ifGenerationMatch": 1001 + } } ], "destination": { "name": "file_name", "size": 1000, "crc32c": "crc32c" - }, - "kind": "storage/composeRequest" + } } \ No newline at end of file