From 50c7cf62b2200e932cc54c183bdd246a28201e8c Mon Sep 17 00:00:00 2001 From: Aled Sage Date: Thu, 15 Mar 2012 12:13:13 +0000 Subject: [PATCH] Issue #830: deleted FilesList, to instead use Set instead --- .../director/v1_5/domain/FilesList.java | 147 ------------------ .../v1_5/domain/ResourceEntityType.java | 15 +- .../vcloud/director/v1_5/domain/Checks.java | 6 +- .../v1_5/features/MediaClientExpectTest.java | 7 +- .../v1_5/features/MediaClientLiveTest.java | 8 +- 5 files changed, 18 insertions(+), 165 deletions(-) delete mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/FilesList.java diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/FilesList.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/FilesList.java deleted file mode 100644 index edc56d3ee6..0000000000 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/FilesList.java +++ /dev/null @@ -1,147 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.jclouds.vcloud.director.v1_5.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Collections; -import java.util.Set; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlType; - -import com.google.common.base.Objects; -import com.google.common.collect.ForwardingSet; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; - - -/** - * Represents a list of files to be transferred (uploaded - * or downloaded). - *

- *

- *

Java class for FilesList complex type. - *

- *

The following schema fragment specifies the expected content contained within this class. - *

- *

- * <complexType name="FilesList">
- *   <complexContent>
- *     <extension base="{http://www.vmware.com/vcloud/v1.5}VCloudExtensibleType">
- *       <sequence>
- *         <element name="File" type="{http://www.vmware.com/vcloud/v1.5}FileType" maxOccurs="unbounded"/>
- *       </sequence>
- *       <anyAttribute processContents='lax' namespace='##other'/>
- *     </extension>
- *   </complexContent>
- * </complexType>
- * 
- */ -@XmlType(name = "FilesList", propOrder = { - "files" -}) -public class FilesList extends ForwardingSet { - - // TODO Investigate using the same wrapper (e.g. see Tasks); can we eliminate this class? - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder().fromFilesList(this); - } - - public static class Builder { - - private Set files = Sets.newLinkedHashSet(); - - /** - * @see FilesList#getFiles() - */ - public Builder files(Iterable files) { - this.files = Sets.newLinkedHashSet(checkNotNull(files, "files")); - return this; - } - - /** - * @see FilesList#getFiles() - */ - public Builder file(File file) { - files.add(checkNotNull(file, "file")); - return this; - } - - public FilesList build() { - FilesList filesList = new FilesList(files); - return filesList; - } - - public Builder fromFilesList(FilesList in) { - return files(in.getFiles()); - } - } - - @XmlElement(name = "File", required = true) - private Set files = Sets.newLinkedHashSet(); - - private FilesList() { - // for JAXB - } - - private FilesList(Iterable files) { - this.files = ImmutableSet.copyOf(files); - } - - /** - * Gets the value of the file property. - */ - public Set getFiles() { - return Collections.unmodifiableSet(this.files); - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - FilesList that = FilesList.class.cast(o); - return equal(files, that.files); - } - - @Override - public int hashCode() { - return Objects.hashCode(files); - } - - @Override - public String toString() { - return Objects.toStringHelper("") - .add("file", files).toString(); - } - - @Override - protected Set delegate() { - return getFiles(); - } -} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java index 2730ce9671..8923b1e38b 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/ResourceEntityType.java @@ -22,9 +22,11 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; import java.util.Arrays; +import java.util.Set; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlType; import com.google.common.base.Objects; @@ -132,13 +134,13 @@ public abstract class ResourceEntityType extends EntityType { } public static abstract class Builder> extends EntityType.Builder { - private FilesList files; + private Set files; private Integer status; /** * @see ResourceEntityType#getFiles() */ - public B files(FilesList files) { + public B files(Set files) { this.files = files; return self(); } @@ -156,8 +158,10 @@ public abstract class ResourceEntityType extends EntityType { } } - @XmlElement(name = "Files") - private FilesList files; + @XmlElementWrapper(name = "Files") + @XmlElement(name = "File") + private Set files; + @XmlAttribute private Integer status; @@ -171,11 +175,10 @@ public abstract class ResourceEntityType extends EntityType { // for JAXB } - /** * Gets the value of the files property. */ - public FilesList getFiles() { + public Set getFiles() { return files; } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java index 0503220834..529c678b88 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/domain/Checks.java @@ -71,9 +71,9 @@ public class Checks { public static void checkResourceEntityType(ResourceEntityType resourceEntity) { // Check optional fields // NOTE status cannot be checked (TODO: doesn't status have a range of valid values?) - FilesList files = resourceEntity.getFiles(); - if (files != null && files.getFiles() != null && !files.getFiles().isEmpty()) { - for (File file : files.getFiles()) checkFile(file); + Set files = resourceEntity.getFiles(); + if (files != null && !files.isEmpty()) { + for (File file : files) checkFile(file); } // Check parent type diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java index 5df76ae595..5ca868dff7 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientExpectTest.java @@ -29,7 +29,6 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.domain.CloneMediaParams; import org.jclouds.vcloud.director.v1_5.domain.Error; import org.jclouds.vcloud.director.v1_5.domain.File; -import org.jclouds.vcloud.director.v1_5.domain.FilesList; import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Metadata; @@ -388,8 +387,7 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .href(URI.create("https://mycloud.greenhousedata.com/api/media/d51b0b9d-099c-499f-97f8-4fbe40ba06d7")) .build()) .description("Test media generated by testCreateMedia()") - .files(FilesList.builder() - .file(File.builder() + .files(ImmutableSet.of(File.builder() .size(0l) .bytesTransferred(0l) .name("file") @@ -397,8 +395,7 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes .rel("upload:default") .href(URI.create("https://mycloud.greenhousedata.com:443/transfer/b1fdf2d0-feff-4414-a8d1-3a8d86c4ccc5/file")) .build()) - .build()) - .build()) + .build())) .owner(owner()) .build(); } diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java index 44beae7b6f..5c9a2c24ca 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/MediaClientLiveTest.java @@ -125,9 +125,9 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { Checks.checkMediaFor(MEDIA, media); assertNotNull(media.getFiles(), String.format(OBJ_FIELD_REQ, MEDIA, "files")); - assertTrue(media.getFiles().getFiles().size() == 1, String.format(OBJ_FIELD_EQ, MEDIA, "files.size()", "1", - media.getFiles().getFiles().size())); - File uploadFile = getFirst(media.getFiles().getFiles(), null); + assertTrue(media.getFiles().size() == 1, String.format(OBJ_FIELD_EQ, MEDIA, "files.size()", "1", + media.getFiles().size())); + File uploadFile = getFirst(media.getFiles(), null); assertNotNull(uploadFile, String.format(OBJ_FIELD_REQ, MEDIA, "files.first")); assertTrue(equal(uploadFile.getSize(), sourceMedia.getSize()), String.format(OBJ_FIELD_EQ, MEDIA, "uploadFile.size()", sourceMedia.getSize(), uploadFile.getSize())); @@ -147,7 +147,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest { assertEquals(task.getStatus(), "running"); - File file = Iterables.getOnlyElement(media.getFiles().getFiles()); + File file = Iterables.getOnlyElement(media.getFiles()); assertEquals(file.getSize(), new Long(iso.length)); assertEquals(file.getBytesTransferred(), new Long(iso.length));