removed unnecessary wrapping of Task collections

This commit is contained in:
Adrian Cole 2012-03-11 17:43:02 -07:00
parent b309dd60df
commit 1f3971fae8
30 changed files with 347 additions and 394 deletions

View File

@ -19,8 +19,6 @@
package org.jclouds.vcloud.director.v1_5.domain; package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI; import java.net.URI;
import java.util.Set; import java.util.Set;
@ -28,8 +26,6 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import com.google.common.collect.Sets;
/** /**
* *
@ -69,7 +65,7 @@ public class AdminCatalog extends CatalogType<AdminCatalog> {
public static class Builder extends CatalogType.Builder<AdminCatalog> { public static class Builder extends CatalogType.Builder<AdminCatalog> {
public AdminCatalog build() { public AdminCatalog build() {
return new AdminCatalog(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, isPublished); return new AdminCatalog(href, type, links, description, tasks, id, name, owner, catalogItems, isPublished);
} }
/** /**
@ -132,14 +128,14 @@ public class AdminCatalog extends CatalogType<AdminCatalog> {
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) { public Builder tasks(Set<Task> tasks) {
this.tasksInProgress = tasksInProgress; super.tasks(tasks);
return this; return this;
} }
/** /**
* @see ReferenceType#getHref() * @see ReferenceType#getHref()
*/ */
@ -157,25 +153,24 @@ public class AdminCatalog extends CatalogType<AdminCatalog> {
this.type = type; this.type = type;
return this; return this;
} }
/** /**
* @see EntityType#getLinks() * @see ResourceType#getLinks()
*/ */
@Override @Override
public Builder links(Set<Link> links) { public Builder links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); return Builder.class.cast(super.links(links));
return this;
} }
/** /**
* @see EntityType#getLinks() * @see ResourceType#getLinks()
*/ */
@Override @Override
public Builder link(Link link) { public Builder link(Link link) {
this.links.add(checkNotNull(link, "link")); return Builder.class.cast(super.link(link));
return this;
} }
@Override @Override
public Builder fromCatalogType(CatalogType<AdminCatalog> in) { public Builder fromCatalogType(CatalogType<AdminCatalog> in) {
return Builder.class.cast(super.fromCatalogType(in)); return Builder.class.cast(super.fromCatalogType(in));
@ -190,8 +185,8 @@ public class AdminCatalog extends CatalogType<AdminCatalog> {
// For JAXB // For JAXB
} }
public AdminCatalog(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, String id, public AdminCatalog(URI href, String type, Set<Link> links, String description, Set<Task> tasks, String id,
String name, Owner owner, CatalogItems catalogItems, Boolean published) { String name, Owner owner, CatalogItems catalogItems, Boolean published) {
super(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, published); super(href, type, links, description, tasks, id, name, owner, catalogItems, published);
} }
} }

View File

@ -57,7 +57,7 @@ public class Catalog extends CatalogType<Catalog> {
@Override @Override
public Catalog build() { public Catalog build() {
return new Catalog(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, isPublished); return new Catalog(href, type, links, description, tasks, id, name, owner, catalogItems, isPublished);
} }
/** /**
@ -120,11 +120,11 @@ public class Catalog extends CatalogType<Catalog> {
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) { public Builder tasks(Set<Task> tasks) {
this.tasksInProgress = tasksInProgress; super.tasks(tasks);
return this; return this;
} }
@ -174,9 +174,9 @@ public class Catalog extends CatalogType<Catalog> {
} }
} }
public Catalog(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, String id, public Catalog(URI href, String type, Set<Link> links, String description, Set<Task> tasks, String id,
String name, Owner owner, CatalogItems catalogItems, Boolean published) { String name, Owner owner, CatalogItems catalogItems, Boolean published) {
super(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, published); super(href, type, links, description, tasks, id, name, owner, catalogItems, published);
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")

View File

@ -46,7 +46,6 @@ public class CatalogItem extends EntityType<CatalogItem> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.CATALOG_ITEM; public static final String MEDIA_TYPE = VCloudDirectorMediaType.CATALOG_ITEM;
@SuppressWarnings("unchecked")
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
@ -87,7 +86,7 @@ public class CatalogItem extends EntityType<CatalogItem> {
@Override @Override
public CatalogItem build() { public CatalogItem build() {
return new CatalogItem(href, type, links, description, tasksInProgress, id, name, entity, properties); return new CatalogItem(href, type, links, description, tasks, id, name, entity, properties);
} }
/** /**
@ -116,13 +115,13 @@ public class CatalogItem extends EntityType<CatalogItem> {
this.id = id; this.id = id;
return this; return this;
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) { public Builder tasks(Set<Task> tasks) {
this.tasksInProgress = tasksInProgress; super.tasks(tasks);
return this; return this;
} }
@ -145,21 +144,19 @@ public class CatalogItem extends EntityType<CatalogItem> {
} }
/** /**
* @see EntityType#getLinks() * @see ResourceType#getLinks()
*/ */
@Override @Override
public Builder links(Set<Link> links) { public Builder links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); return Builder.class.cast(super.links(links));
return this;
} }
/** /**
* @see EntityType#getLinks() * @see ResourceType#getLinks()
*/ */
@Override @Override
public Builder link(Link link) { public Builder link(Link link) {
this.links.add(checkNotNull(link, "link")); return Builder.class.cast(super.link(link));
return this;
} }
@Override @Override
@ -172,8 +169,8 @@ public class CatalogItem extends EntityType<CatalogItem> {
} }
} }
private CatalogItem(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, String id, String name, Reference entity, Set<Property> properties) { private CatalogItem(URI href, String type, Set<Link> links, String description, Set<Task> tasks, String id, String name, Reference entity, Set<Property> properties) {
super(href, type, links, description, tasksInProgress, id, name); super(href, type, links, description, tasks, id, name);
this.entity = entity; this.entity = entity;
this.properties = ImmutableSet.copyOf(properties); this.properties = ImmutableSet.copyOf(properties);
} }

View File

@ -90,7 +90,7 @@ public class CatalogType<T extends CatalogType<T>> extends EntityType<T> {
@Override @Override
public CatalogType<T> build() { public CatalogType<T> build() {
return new CatalogType<T>(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, isPublished); return new CatalogType<T>(href, type, links, description, tasks, id, name, owner, catalogItems, isPublished);
} }
/** /**
@ -121,11 +121,11 @@ public class CatalogType<T extends CatalogType<T>> extends EntityType<T> {
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder<T> tasksInProgress(TasksInProgress tasksInProgress) { public Builder<T> tasks(Set<Task> tasks) {
super.tasksInProgress(tasksInProgress); super.tasks(tasks);
return this; return this;
} }
@ -176,9 +176,9 @@ public class CatalogType<T extends CatalogType<T>> extends EntityType<T> {
} }
} }
public CatalogType(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, String id, public CatalogType(URI href, String type, Set<Link> links, String description, Set<Task> tasks, String id,
String name, Owner owner, CatalogItems catalogItems, Boolean published) { String name, Owner owner, CatalogItems catalogItems, Boolean published) {
super(href, type, links, description, tasksInProgress, id, name); super(href, type, links, description, tasks, id, name);
this.owner = owner; this.owner = owner;
this.catalogItems = catalogItems; this.catalogItems = catalogItems;
this.isPublished = published; this.isPublished = published;

View File

@ -46,7 +46,7 @@ public class Entity extends EntityType<Entity> {
@Override @Override
public Entity build() { public Entity build() {
return new Entity(href, type, links, description, tasksInProgress, id, name); return new Entity(href, type, links, description, tasks, id, name);
} }
/** /**
@ -77,11 +77,11 @@ public class Entity extends EntityType<Entity> {
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) { public Builder tasks(Set<Task> tasks) {
this.tasksInProgress = tasksInProgress; super.tasks(tasks);
return this; return this;
} }
@ -131,8 +131,8 @@ public class Entity extends EntityType<Entity> {
} }
} }
private Entity(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, String id, String name) { private Entity(URI href, String type, Set<Link> links, String description, Set<Task> tasks, String id, String name) {
super(href, type, links, description, tasksInProgress, id, name); super(href, type, links, description, tasks, id, name);
} }
private Entity() { private Entity() {

View File

@ -22,13 +22,18 @@ import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI; import java.net.URI;
import java.util.Collections;
import java.util.Set; import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
@ -48,7 +53,7 @@ public abstract class EntityType<T extends EntityType<T>> extends ResourceType<T
public static abstract class NewBuilder<T extends NewBuilder<T>> extends ResourceType.NewBuilder<T> { public static abstract class NewBuilder<T extends NewBuilder<T>> extends ResourceType.NewBuilder<T> {
protected String description; protected String description;
protected TasksInProgress tasksInProgress; protected Set<Task> tasks;
protected String name; protected String name;
protected String id; protected String id;
@ -77,16 +82,16 @@ public abstract class EntityType<T extends EntityType<T>> extends ResourceType<T
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
public T tasksInProgress(TasksInProgress tasksInProgress) { public T tasks(Set<Task> tasks) {
this.tasksInProgress = tasksInProgress; this.tasks = tasks;
return self(); return self();
} }
public T fromEntityType(EntityType<?> in) { public T fromEntityType(EntityType<?> in) {
return fromResourceType(in) return fromResourceType(in)
.description(in.getDescription()).tasksInProgress(in.getTasksInProgress()) .description(in.getDescription()).tasks(in.getTasks())
.id(in.getId()).name(in.getName()); .id(in.getId()).name(in.getName());
} }
} }
@ -94,7 +99,7 @@ public abstract class EntityType<T extends EntityType<T>> extends ResourceType<T
public static abstract class Builder<T extends EntityType<T>> extends ResourceType.Builder<T> { public static abstract class Builder<T extends EntityType<T>> extends ResourceType.Builder<T> {
protected String description; protected String description;
protected TasksInProgress tasksInProgress; protected Set<Task> tasks;
protected String name; protected String name;
protected String id; protected String id;
@ -121,12 +126,23 @@ public abstract class EntityType<T extends EntityType<T>> extends ResourceType<T
this.id = id; this.id = id;
return this; return this;
} }
/**
* @see EntityType#getTasks()
*/
public Builder<T> tasks(Set<Task> tasks) {
if (checkNotNull(tasks, "tasks").size() > 0)
this.tasks = Sets.newLinkedHashSet(tasks);
return this;
}
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
public Builder<T> tasksInProgress(TasksInProgress tasksInProgress) { public Builder<T> task(Task task) {
this.tasksInProgress = tasksInProgress; if (tasks == null)
tasks = Sets.newLinkedHashSet();
this.tasks.add(checkNotNull(task, "task"));
return this; return this;
} }
@ -151,19 +167,19 @@ public abstract class EntityType<T extends EntityType<T>> extends ResourceType<T
/** /**
* @see ResourceType#getLinks() * @see ResourceType#getLinks()
*/ */
@SuppressWarnings("unchecked")
@Override @Override
public Builder<T> links(Set<Link> links) { public Builder<T> links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); return Builder.class.cast(super.links(links));
return this;
} }
/** /**
* @see ResourceType#getLinks() * @see ResourceType#getLinks()
*/ */
@SuppressWarnings("unchecked")
@Override @Override
public Builder<T> link(Link link) { public Builder<T> link(Link link) {
this.links.add(checkNotNull(link, "link")); return Builder.class.cast(super.link(link));
return this;
} }
/** /**
@ -177,24 +193,26 @@ public abstract class EntityType<T extends EntityType<T>> extends ResourceType<T
public Builder<T> fromEntityType(EntityType<T> in) { public Builder<T> fromEntityType(EntityType<T> in) {
return fromResourceType(in) return fromResourceType(in)
.description(in.getDescription()).tasksInProgress(in.getTasksInProgress()) .description(in.getDescription()).tasks(in.getTasks())
.id(in.getId()).name(in.getName()); .id(in.getId()).name(in.getName());
} }
} }
@XmlElement(name = "Description") @XmlElement(name = "Description")
private String description; private String description;
@XmlElement(name = "Tasks") @XmlElementWrapper(name = "Tasks")
private TasksInProgress tasksInProgress; @XmlElement(name = "Task")
private Set<Task> tasks;
@XmlAttribute @XmlAttribute
private String id; private String id;
@XmlAttribute(required = true) @XmlAttribute(required = true)
private String name; private String name;
public EntityType(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, String id, String name) { public EntityType(URI href, String type, @Nullable Set<Link> links, String description, @Nullable Set<Task> tasks, String id, String name) {
super(href, type, links); super(href, type, links);
this.description = description; this.description = description;
this.tasksInProgress = tasksInProgress; // nullable so that jaxb wont persist empty collections
this.tasks = tasks != null && tasks.size() == 0 ? null : tasks;
this.id = id; this.id = id;
this.name = name; this.name = name;
} }
@ -213,8 +231,8 @@ public abstract class EntityType<T extends EntityType<T>> extends ResourceType<T
/** /**
* A list of queued, running, or recently completed tasks associated with this entity. * A list of queued, running, or recently completed tasks associated with this entity.
*/ */
public TasksInProgress getTasksInProgress() { public Set<Task> getTasks() {
return tasksInProgress; return tasks == null ? ImmutableSet.<Task>of() : Collections.unmodifiableSet(tasks);
} }
/** /**
@ -243,7 +261,7 @@ public abstract class EntityType<T extends EntityType<T>> extends ResourceType<T
EntityType<?> that = EntityType.class.cast(o); EntityType<?> that = EntityType.class.cast(o);
return super.equals(that) && return super.equals(that) &&
equal(this.id, that.id) && equal(this.description, that.description) && equal(this.id, that.id) && equal(this.description, that.description) &&
equal(this.tasksInProgress, that.tasksInProgress) && equal(this.name, that.name); equal(this.tasks, that.tasks) && equal(this.name, that.name);
} }
@Override @Override
@ -258,11 +276,11 @@ public abstract class EntityType<T extends EntityType<T>> extends ResourceType<T
@Override @Override
public int hashCode() { public int hashCode() {
return super.hashCode() + Objects.hashCode(description, tasksInProgress, id, name); return super.hashCode() + Objects.hashCode(description, tasks, id, name);
} }
@Override @Override
public ToStringHelper string() { public ToStringHelper string() {
return super.string().add("description", description).add("tasksInProgress", tasksInProgress).add("id", id).add("name", name); return super.string().add("description", description).add("tasks", tasks).add("id", id).add("name", name);
} }
} }

View File

@ -20,7 +20,6 @@
package org.jclouds.vcloud.director.v1_5.domain; package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI; import java.net.URI;
import java.util.Set; import java.util.Set;
@ -33,7 +32,6 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Sets;
/** /**
@ -99,7 +97,7 @@ public class File extends EntityType<File> {
} }
public File build() { public File build() {
return new File(href, type, links, description, tasksInProgress, id, name, size, bytesTransferred, checksum); return new File(href, type, links, description, tasks, id, name, size, bytesTransferred, checksum);
} }
@ -128,11 +126,11 @@ public class File extends EntityType<File> {
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) { public Builder tasks(Set<Task> tasks) {
super.tasksInProgress (tasksInProgress); super.tasks (tasks);
return this; return this;
} }
@ -159,7 +157,7 @@ public class File extends EntityType<File> {
*/ */
@Override @Override
public Builder links(Set<Link> links) { public Builder links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); super.links(links);
return this; return this;
} }
@ -168,7 +166,7 @@ public class File extends EntityType<File> {
*/ */
@Override @Override
public Builder link(Link link) { public Builder link(Link link) {
this.links.add(checkNotNull(link, "link")); super.link(link);
return this; return this;
} }
@ -186,9 +184,9 @@ public class File extends EntityType<File> {
} }
} }
public File(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, String id, public File(URI href, String type, Set<Link> links, String description, Set<Task> tasks, String id,
String name, Long size, Long bytesTransferred, String checksum) { String name, Long size, Long bytesTransferred, String checksum) {
super(href, type, links, description, tasksInProgress, id, name); super(href, type, links, description, tasks, id, name);
this.size = size; this.size = size;
this.bytesTransferred = bytesTransferred; this.bytesTransferred = bytesTransferred;
this.checksum = checksum; this.checksum = checksum;

View File

@ -106,7 +106,7 @@ public class Group extends EntityType<Group> {
} }
public Group build() { public Group build() {
return new Group(href, type, links, description, tasksInProgress, id, name, return new Group(href, type, links, description, tasks, id, name,
nameInSource, usersList, role); nameInSource, usersList, role);
} }
@ -138,11 +138,11 @@ public class Group extends EntityType<Group> {
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) { public Builder tasks(Set<Task> tasks) {
super.tasksInProgress(tasksInProgress); super.tasks(tasks);
return this; return this;
} }
@ -200,9 +200,9 @@ public class Group extends EntityType<Group> {
} }
public Group(URI href, String type, Set<Link> links, String description, public Group(URI href, String type, Set<Link> links, String description,
TasksInProgress tasksInProgress, String id, String name, String nameInSource, Set<Task> tasks, String id, String name, String nameInSource,
UsersList usersList, Reference role) { UsersList usersList, Reference role) {
super(href, type, links, description, tasksInProgress, id, name); super(href, type, links, description, tasks, id, name);
this.nameInSource = nameInSource; this.nameInSource = nameInSource;
this.usersList = usersList; this.usersList = usersList;
this.role = role; this.role = role;

View File

@ -90,7 +90,7 @@ public class Media extends ResourceEntityType<Media> {
@Override @Override
public Media build() { public Media build() {
return new Media(href, type, links, description, tasksInProgress, id, name, files, status, owner, imageType, size); return new Media(href, type, links, description, tasks, id, name, files, status, owner, imageType, size);
} }
/** /**
@ -139,11 +139,11 @@ public class Media extends ResourceEntityType<Media> {
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) { public Builder tasks(Set<Task> tasks) {
super.tasksInProgress(tasksInProgress); super.tasks(tasks);
return this; return this;
} }
@ -194,9 +194,9 @@ public class Media extends ResourceEntityType<Media> {
} }
public Media(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, String id, public Media(URI href, String type, Set<Link> links, String description, Set<Task> tasks, String id,
String name, FilesList files, Integer status, Owner owner, String imageType, long size) { String name, FilesList files, Integer status, Owner owner, String imageType, long size) {
super(href, type, links, description, tasksInProgress, id, name, files, status); super(href, type, links, description, tasks, id, name, files, status);
this.owner = owner; this.owner = owner;
this.imageType = imageType; this.imageType = imageType;
this.size = size; this.size = size;

View File

@ -19,7 +19,6 @@
package org.jclouds.vcloud.director.v1_5.domain; package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI; import java.net.URI;
import java.util.Set; import java.util.Set;
@ -29,7 +28,6 @@ import javax.xml.bind.annotation.XmlRootElement;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Sets;
@XmlRootElement(name = "NetworkType") @XmlRootElement(name = "NetworkType")
public class NetworkType<T extends NetworkType<T>> extends EntityType<T> { public class NetworkType<T extends NetworkType<T>> extends EntityType<T> {
@ -57,7 +55,7 @@ public class NetworkType<T extends NetworkType<T>> extends EntityType<T> {
@Override @Override
public NetworkType<T> build() { public NetworkType<T> build() {
return new NetworkType<T>(href, type, links, description, tasksInProgress, id, name, networkConfiguration); return new NetworkType<T>(href, type, links, description, tasks, id, name, networkConfiguration);
} }
/** /**
@ -86,13 +84,13 @@ public class NetworkType<T extends NetworkType<T>> extends EntityType<T> {
this.id = id; this.id = id;
return this; return this;
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder<T> tasksInProgress(TasksInProgress tasksInProgress) { public Builder<T> tasks(Set<Task> tasks) {
this.tasksInProgress = tasksInProgress; super.tasks(tasks);
return this; return this;
} }
@ -119,7 +117,7 @@ public class NetworkType<T extends NetworkType<T>> extends EntityType<T> {
*/ */
@Override @Override
public Builder<T> links(Set<Link> links) { public Builder<T> links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); super.links(links);
return this; return this;
} }
@ -128,7 +126,7 @@ public class NetworkType<T extends NetworkType<T>> extends EntityType<T> {
*/ */
@Override @Override
public Builder<T> link(Link link) { public Builder<T> link(Link link) {
this.links.add(checkNotNull(link, "link")); super.link(link);
return this; return this;
} }
@ -146,9 +144,9 @@ public class NetworkType<T extends NetworkType<T>> extends EntityType<T> {
} }
} }
public NetworkType(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, public NetworkType(URI href, String type, Set<Link> links, String description, Set<Task> tasks,
String id, String name, NetworkConfiguration networkConfiguration) { String id, String name, NetworkConfiguration networkConfiguration) {
super(href, type, links, description, tasksInProgress, id, name); super(href, type, links, description, tasks, id, name);
this.networkConfiguration = networkConfiguration; this.networkConfiguration = networkConfiguration;
} }

View File

@ -80,7 +80,7 @@ public class Org extends EntityType<Org> {
@Override @Override
public Org build() { public Org build() {
return new Org(href, type, links, description, tasksInProgress, id, name, fullName, isEnabled); return new Org(href, type, links, description, tasks, id, name, fullName, isEnabled);
} }
public T fromOrg(Org in) { public T fromOrg(Org in) {
@ -143,7 +143,7 @@ public class Org extends EntityType<Org> {
@Override @Override
public Org build() { public Org build() {
return new Org(href, type, links, description, tasksInProgress, id, name, fullName, isEnabled); return new Org(href, type, links, description, tasks, id, name, fullName, isEnabled);
} }
/** /**
@ -174,11 +174,11 @@ public class Org extends EntityType<Org> {
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) { public Builder tasks(Set<Task> tasks) {
this.tasksInProgress = tasksInProgress; super.tasks(tasks);
return this; return this;
} }
@ -232,8 +232,8 @@ public class Org extends EntityType<Org> {
// for JAXB // for JAXB
} }
public Org(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, String id, String name, String fullName, Boolean enabled) { public Org(URI href, String type, Set<Link> links, String description, Set<Task> tasks, String id, String name, String fullName, Boolean enabled) {
super(href, type, links, description, tasksInProgress, id, name); super(href, type, links, description, tasks, id, name);
this.fullName = fullName; this.fullName = fullName;
isEnabled = enabled; isEnabled = enabled;
} }

View File

@ -19,7 +19,6 @@
package org.jclouds.vcloud.director.v1_5.domain; package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI; import java.net.URI;
import java.util.Set; import java.util.Set;
@ -29,7 +28,6 @@ import javax.xml.bind.annotation.XmlRootElement;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Sets;
@XmlRootElement(name = "OrgNetwork") @XmlRootElement(name = "OrgNetwork")
public class OrgNetwork extends NetworkType<OrgNetwork> { public class OrgNetwork extends NetworkType<OrgNetwork> {
@ -67,7 +65,7 @@ public class OrgNetwork extends NetworkType<OrgNetwork> {
@Override @Override
public OrgNetwork build() { public OrgNetwork build() {
return new OrgNetwork(href, type, links, description, tasksInProgress, id, name, networkConfiguration, return new OrgNetwork(href, type, links, description, tasks, id, name, networkConfiguration,
networkPool, allowedExternalIpAddresses); networkPool, allowedExternalIpAddresses);
} }
@ -105,13 +103,13 @@ public class OrgNetwork extends NetworkType<OrgNetwork> {
this.id = id; this.id = id;
return this; return this;
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) { public Builder tasks(Set<Task> tasks) {
this.tasksInProgress = tasksInProgress; super.tasks(tasks);
return this; return this;
} }
@ -138,7 +136,7 @@ public class OrgNetwork extends NetworkType<OrgNetwork> {
*/ */
@Override @Override
public Builder links(Set<Link> links) { public Builder links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); super.links(links);
return this; return this;
} }
@ -147,7 +145,7 @@ public class OrgNetwork extends NetworkType<OrgNetwork> {
*/ */
@Override @Override
public Builder link(Link link) { public Builder link(Link link) {
this.links.add(checkNotNull(link, "link")); super.link(link);
return this; return this;
} }
@ -167,9 +165,9 @@ public class OrgNetwork extends NetworkType<OrgNetwork> {
// For JAXB // For JAXB
} }
private OrgNetwork(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, private OrgNetwork(URI href, String type, Set<Link> links, String description, Set<Task> tasks,
String id, String name, NetworkConfiguration networkConfiguration, ReferenceType<?> networkPool, IpAddresses allowedExternalIpAddresses) { String id, String name, NetworkConfiguration networkConfiguration, ReferenceType<?> networkPool, IpAddresses allowedExternalIpAddresses) {
super(href, type, links, description, tasksInProgress, id, name, networkConfiguration); super(href, type, links, description, tasks, id, name, networkConfiguration);
this.networkPool = networkPool; this.networkPool = networkPool;
this.allowedExternalIpAddresses = allowedExternalIpAddresses; this.allowedExternalIpAddresses = allowedExternalIpAddresses;
} }

View File

@ -20,7 +20,6 @@
package org.jclouds.vcloud.director.v1_5.domain; package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI; import java.net.URI;
import java.util.Set; import java.util.Set;
@ -30,7 +29,6 @@ import javax.xml.bind.annotation.XmlElement;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Sets;
/** /**
* Base type that represents a resource entity such as a vApp template or virtual media. * Base type that represents a resource entity such as a vApp template or virtual media.
@ -72,13 +70,13 @@ public abstract class ResourceEntityType<T extends ResourceEntityType<T>> extend
this.id = id; this.id = id;
return this; return this;
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder<T> tasksInProgress(TasksInProgress tasksInProgress) { public Builder<T> tasks(Set<Task> tasks) {
this.tasksInProgress = tasksInProgress; super.tasks(tasks);
return this; return this;
} }
@ -101,20 +99,18 @@ public abstract class ResourceEntityType<T extends ResourceEntityType<T>> extend
} }
/** /**
* @see EntityType#getLinks() * @see ResourceEntityType#getLinks()
*/ */
@Override
public Builder<T> links(Set<Link> links) { public Builder<T> links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); super.links(links);
return this; return this;
} }
/** /**
* @see EntityType#getLinks() * @see ResourceEntityType#getLinks()
*/ */
@Override
public Builder<T> link(Link link) { public Builder<T> link(Link link) {
this.links.add(checkNotNull(link, "link")); super.link(link);
return this; return this;
} }
@ -134,8 +130,8 @@ public abstract class ResourceEntityType<T extends ResourceEntityType<T>> extend
@XmlAttribute @XmlAttribute
protected Integer status; protected Integer status;
public ResourceEntityType(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, String id, String name, FilesList files, Integer status) { public ResourceEntityType(URI href, String type, Set<Link> links, String description, Set<Task> tasks, String id, String name, FilesList files, Integer status) {
super(href, type, links, description, tasksInProgress, id, name); super(href, type, links, description, tasks, id, name);
this.files = files; this.files = files;
this.status = status; this.status = status;
} }

View File

@ -28,6 +28,8 @@ import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -55,7 +57,7 @@ public abstract class ResourceType<T extends ResourceType<T>> {
protected URI href; protected URI href;
protected String type; protected String type;
protected Set<Link> links = Sets.newLinkedHashSet(); protected Set<Link> links;
/** /**
* @see ResourceType#getHref() * @see ResourceType#getHref()
@ -85,6 +87,8 @@ public abstract class ResourceType<T extends ResourceType<T>> {
* @see ResourceType#getLinks() * @see ResourceType#getLinks()
*/ */
public T link(Link link) { public T link(Link link) {
if (links == null)
links = Sets.newLinkedHashSet();
this.links.add(checkNotNull(link, "link")); this.links.add(checkNotNull(link, "link"));
return self(); return self();
} }
@ -102,7 +106,7 @@ public abstract class ResourceType<T extends ResourceType<T>> {
protected URI href; protected URI href;
protected String type; protected String type;
protected Set<Link> links = Sets.newLinkedHashSet(); protected Set<Link> links;
/** /**
* @see ResourceType#getHref() * @see ResourceType#getHref()
@ -132,6 +136,8 @@ public abstract class ResourceType<T extends ResourceType<T>> {
* @see ResourceType#getLinks() * @see ResourceType#getLinks()
*/ */
public Builder<T> link(Link link) { public Builder<T> link(Link link) {
if (links == null)
links = Sets.newLinkedHashSet();
this.links.add(checkNotNull(link, "link")); this.links.add(checkNotNull(link, "link"));
return this; return this;
} }
@ -148,12 +154,13 @@ public abstract class ResourceType<T extends ResourceType<T>> {
@XmlAttribute @XmlAttribute
private String type; private String type;
@XmlElement(name = "Link") @XmlElement(name = "Link")
private Set<Link> links = Sets.newLinkedHashSet(); private Set<Link> links;
protected ResourceType(URI href, String type, Set<Link> links) { protected ResourceType(URI href, String type, @Nullable Set<Link> links) {
this.href = href; this.href = href;
this.type = type; this.type = type;
this.links = ImmutableSet.copyOf(links); // nullable so that jaxb wont persist empty collections
this.links = links != null && links.size() == 0 ? null : links;
} }
protected ResourceType() { protected ResourceType() {
@ -193,7 +200,7 @@ public abstract class ResourceType<T extends ResourceType<T>> {
* Set of optional links to an entity or operation associated with this object. * Set of optional links to an entity or operation associated with this object.
*/ */
public Set<Link> getLinks() { public Set<Link> getLinks() {
return Collections.unmodifiableSet(links); return links == null ? ImmutableSet.<Link>of() : Collections.unmodifiableSet(links);
} }
@Override @Override

View File

@ -19,7 +19,6 @@
package org.jclouds.vcloud.director.v1_5.domain; package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI; import java.net.URI;
import java.util.Arrays; import java.util.Arrays;
@ -35,7 +34,6 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Sets;
/** /**
* Represents an asynchronous or long-running task in the vCloud environment. * Represents an asynchronous or long-running task in the vCloud environment.
@ -44,6 +42,8 @@ import com.google.common.collect.Sets;
* &lt;xs:complexType name="TaskType"&gt; * &lt;xs:complexType name="TaskType"&gt;
* </pre> * </pre>
* *
* TODO: this object and the hierarchy is wrong. it is literally a Task with a Task container. please review class diagram
*
* @author grkvlt@apache.org * @author grkvlt@apache.org
*/ */
@XmlRootElement(name = "Task") @XmlRootElement(name = "Task")
@ -188,7 +188,7 @@ public class Task extends EntityType<Task> {
@Override @Override
public Task build() { public Task build() {
return new Task(href, type, links, description, tasksInProgress, id, name, return new Task(href, type, links, description, tasks, id, name,
error, org, progress, owner, user, params, status, operation, operationName, startTime, endTime, expiryTime); error, org, progress, owner, user, params, status, operation, operationName, startTime, endTime, expiryTime);
} }
@ -218,13 +218,13 @@ public class Task extends EntityType<Task> {
this.id = id; this.id = id;
return this; return this;
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) { public Builder tasks(Set<Task> tasks) {
this.tasksInProgress = tasksInProgress; super.tasks(tasks);
return this; return this;
} }
@ -247,23 +247,22 @@ public class Task extends EntityType<Task> {
} }
/** /**
* @see EntityType#getLinks() * @see ResourceType#getLinks()
*/ */
@Override @Override
public Builder links(Set<Link> links) { public Builder links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); return Builder.class.cast(super.links(links));
return this;
} }
/** /**
* @see EntityType#getLinks() * @see ResourceType#getLinks()
*/ */
@Override @Override
public Builder link(Link link) { public Builder link(Link link) {
this.links.add(checkNotNull(link, "link")); return Builder.class.cast(super.link(link));
return this;
} }
@Override @Override
public Builder fromEntityType(EntityType<Task> in) { public Builder fromEntityType(EntityType<Task> in) {
return Builder.class.cast(super.fromEntityType(in)); return Builder.class.cast(super.fromEntityType(in));
@ -276,11 +275,11 @@ public class Task extends EntityType<Task> {
} }
} }
public Task(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, public Task(URI href, String type, Set<Link> links, String description, Set<Task> tasks,
String id, String name, Error error, Reference org, Integer progress, Reference owner, String id, String name, Error error, Reference org, Integer progress, Reference owner,
Reference user, Object params, String status, String operation, String operationName, Reference user, Object params, String status, String operation, String operationName,
Date startTime, Date endTime, Date expiryTime) { Date startTime, Date endTime, Date expiryTime) {
super(href, type, links, description, tasksInProgress, id, name); super(href, type, links, description, tasks, id, name);
this.error = error; this.error = error;
this.org = org; this.org = org;
this.progress = progress; this.progress = progress;

View File

@ -1,113 +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 CONDITIOXMLNS 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.Collection;
import java.util.Collections;
import java.util.Set;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* @author grkvlt@apache.org
*/
@XmlRootElement(name = "TasksInProgress")
public class TasksInProgress {
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder();
}
public static class Builder {
protected Set<Task> tasks = Sets.newLinkedHashSet();
/**
* @see TasksInProgress#getTasks()
*/
public Builder tasks(Set<Task> tasks) {
this.tasks = ImmutableSet.copyOf(checkNotNull(tasks, "tasks"));
return this;
}
/**
* @see TasksInProgress#getTasks()
*/
public Builder task(Task task) {
this.tasks.add(checkNotNull(task, "task"));
return this;
}
public TasksInProgress build() {
return new TasksInProgress(tasks);
}
public Builder fromTasksInProgress(TasksInProgress in) {
return tasks(in.getTasks());
}
}
private TasksInProgress() {
// for JAXB
}
private TasksInProgress(Collection<Task> tasks) {
this.tasks = ImmutableSet.copyOf(tasks);
}
@XmlElement(name = "Task")
private Set<Task> tasks = Sets.newLinkedHashSet();
public Set<Task> getTasks() {
return Collections.unmodifiableSet(tasks);
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
TasksInProgress that = TasksInProgress.class.cast(o);
return equal(this.tasks, that.tasks);
}
@Override
public int hashCode() {
return Objects.hashCode(tasks);
}
@Override
public String toString() {
return Objects.toStringHelper("").add("tasks", tasks).toString();
}
}

View File

@ -22,13 +22,16 @@ import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI; import java.net.URI;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.Set; import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
@ -36,33 +39,36 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
* A list of tasks. * Task List
* *
*
* @author Adrian Cole * @author Adrian Cole
*/ */
@XmlRootElement(name = "TasksList") @XmlRootElement(name = "TasksList")
public class TasksList extends EntityType<TasksList> { public class TasksList extends ResourceType<TasksList> implements Set<Task> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.TASKS_LIST;
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
@Override public static class Builder extends ResourceType.Builder<TasksList> {
public Builder toBuilder() { protected String name;
return new Builder();
}
public static class Builder extends EntityType.Builder<TasksList> { private Set<Task> tasks;
protected Set<Task> tasks = Sets.newLinkedHashSet(); /**
* @see TasksList#getName()
*/
public Builder name(String name) {
this.name = name;
return this;
}
/** /**
* @see TasksList#getTasks() * @see TasksList#getTasks()
*/ */
public Builder tasks(Set<Task> tasks) { public Builder tasks(Set<Task> tasks) {
this.tasks = Sets.newLinkedHashSet(checkNotNull(tasks, "tasks")); if (checkNotNull(tasks, "tasks").size() > 0)
this.tasks = Sets.newLinkedHashSet(tasks);
return this; return this;
} }
@ -70,111 +76,86 @@ public class TasksList extends EntityType<TasksList> {
* @see TasksList#getTasks() * @see TasksList#getTasks()
*/ */
public Builder task(Task task) { public Builder task(Task task) {
if (tasks == null)
tasks = Sets.newLinkedHashSet();
this.tasks.add(checkNotNull(task, "task")); this.tasks.add(checkNotNull(task, "task"));
return this; return this;
} }
@Override @Override
public TasksList build() { public TasksList build() {
return new TasksList(href, type, links, description, tasksInProgress, id, name, tasks); return new TasksList(href, type, links, name, tasks);
} }
/** /**
* @see EntityType#getName() * @see ResourceType#getHref()
*/
@Override
public Builder name(String name) {
this.name = name;
return this;
}
/**
* @see EntityType#getDescription()
*/
@Override
public Builder description(String description) {
this.description = description;
return this;
}
/**
* @see EntityType#getId()
*/
@Override
public Builder id(String id) {
this.id = id;
return this;
}
/**
* @see EntityType#getTasksInProgress()
*/
@Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) {
this.tasksInProgress = tasksInProgress;
return this;
}
/**
* @see ReferenceType#getHref()
*/ */
@Override @Override
public Builder href(URI href) { public Builder href(URI href) {
this.href = href; super.href(href);
return this; return this;
} }
/** /**
* @see ReferenceType#getType() * @see ResourceType#getType()
*/ */
@Override @Override
public Builder type(String type) { public Builder type(String type) {
this.type = type; super.type(type);
return this; return this;
} }
/** /**
* @see EntityType#getLinks() * @see ResourceType#getLinks()
*/ */
@Override @Override
public Builder links(Set<Link> links) { public Builder links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); return Builder.class.cast(super.links(links));
return this;
} }
/** /**
* @see EntityType#getLinks() * @see ResourceType#getLinks()
*/ */
@Override @Override
public Builder link(Link link) { public Builder link(Link link) {
this.links.add(checkNotNull(link, "link")); super.link(link);
return this; return this;
} }
@Override public Builder fromTasksList(TasksList in) {
public Builder fromEntityType(EntityType<TasksList> in) { return fromResourceType(in).tasks(in);
return Builder.class.cast(super.fromEntityType(in));
} }
public Builder fromTasksList(TasksList in) { /**
return fromEntityType(in).tasks(in.getTasks()); * {@inheritDoc}
*/
@Override
public Builder fromResourceType(ResourceType<TasksList> in) {
return Builder.class.cast(super.fromResourceType(in));
} }
} }
@XmlAttribute(required = true)
private String name;
@XmlElement(name = "Task")
private Set<Task> tasks;
public TasksList(URI href, String type, @Nullable Set<Link> links, String name, @Nullable Set<Task> tasks) {
super(href, type, links);
this.tasks = tasks;
this.name = name;
}
protected TasksList() { protected TasksList() {
// for JAXB // For JAXB
} }
public TasksList(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, String id, String name, Set<Task> tasks) {
super(href, type, links, description, tasksInProgress, id, name);
this.tasks = ImmutableSet.copyOf(tasks);
}
@XmlElement(name = "Task") /**
private Set<Task> tasks = Sets.newLinkedHashSet(); * Contains the name of the the entity.
*/
public Set<Task> getTasks() { public String getName() {
return Collections.unmodifiableSet(tasks); return name;
} }
@Override @Override
@ -184,16 +165,91 @@ public class TasksList extends EntityType<TasksList> {
if (o == null || getClass() != o.getClass()) if (o == null || getClass() != o.getClass())
return false; return false;
TasksList that = TasksList.class.cast(o); TasksList that = TasksList.class.cast(o);
return super.equals(that) && equal(this.tasks, that.tasks); return super.equals(that) && equal(this.delegate(), that.delegate()) && equal(this.name, that.name);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return super.hashCode() + Objects.hashCode(tasks); return super.hashCode() + Objects.hashCode(delegate(), name);
}
private Set<Task> delegate() {
return tasks == null ? ImmutableSet.<Task>of() : Collections.unmodifiableSet(tasks);
} }
@Override @Override
public ToStringHelper string() { public ToStringHelper string() {
return super.string().add("tasks", tasks); return super.string().add("name", name).add("tasks", delegate());
} }
}
@Override
public Builder toBuilder() {
return new Builder().fromTasksList(this);
}
@Override
public Iterator<Task> iterator() {
return delegate().iterator();
}
@Override
public int size() {
return delegate().size();
}
@Override
public boolean removeAll(Collection<?> collection) {
return delegate().removeAll(collection);
}
@Override
public boolean isEmpty() {
return delegate().isEmpty();
}
@Override
public boolean contains(Object object) {
return delegate().contains(object);
}
@Override
public boolean add(Task element) {
return delegate().add(element);
}
@Override
public boolean remove(Object object) {
return delegate().remove(object);
}
@Override
public boolean containsAll(Collection<?> collection) {
return delegate().containsAll(collection);
}
@Override
public boolean addAll(Collection<? extends Task> collection) {
return delegate().addAll(collection);
}
@Override
public boolean retainAll(Collection<?> collection) {
return delegate().retainAll(collection);
}
@Override
public void clear() {
delegate().clear();
}
@Override
public Object[] toArray() {
return delegate().toArray();
}
@Override
public <T> T[] toArray(T[] array) {
return delegate().toArray(array);
}
}

View File

@ -270,7 +270,7 @@ public class User
public User build() { public User build() {
return new User(href, type, links, description, tasksInProgress, id, return new User(href, type, links, description, tasks, id,
name, fullName, emailAddress, telephone, isEnabled, isLocked, name, fullName, emailAddress, telephone, isEnabled, isLocked,
im, nameInSource, isAlertEnabled, alertEmailPrefix, alertEmail, im, nameInSource, isAlertEnabled, alertEmailPrefix, alertEmail,
isExternal, isDefaultCached, isGroupRole, storedVmQuota, deployedVmQuota, isExternal, isDefaultCached, isGroupRole, storedVmQuota, deployedVmQuota,
@ -286,13 +286,13 @@ public class User
this.id = id; this.id = id;
return this; return this;
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) { public Builder tasks(Set<Task> tasks) {
this.tasksInProgress = tasksInProgress; super.tasks(tasks);
return this; return this;
} }
@ -398,12 +398,12 @@ public class User
@XmlElement(name = "GroupReferences") @XmlElement(name = "GroupReferences")
protected Object /* GroupsList */ groupReferences; protected Object /* GroupsList */ groupReferences;
public User(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, String id, public User(URI href, String type, Set<Link> links, String description, Set<Task> tasks, String id,
String name, String fullName, String emailAddress, String telephone, Boolean enabled, Boolean locked, String name, String fullName, String emailAddress, String telephone, Boolean enabled, Boolean locked,
String im, String nameInSource, Boolean alertEnabled, String alertEmailPrefix, String alertEmail, String im, String nameInSource, Boolean alertEnabled, String alertEmailPrefix, String alertEmail,
Boolean external, Boolean defaultCached, Boolean groupRole, Integer storedVmQuota, Integer deployedVmQuota, Boolean external, Boolean defaultCached, Boolean groupRole, Integer storedVmQuota, Integer deployedVmQuota,
Reference role, String password, Object groupReferences) { Reference role, String password, Object groupReferences) {
super(href, type, links, description, tasksInProgress, id, name); super(href, type, links, description, tasks, id, name);
this.fullName = fullName; this.fullName = fullName;
this.emailAddress = emailAddress; this.emailAddress = emailAddress;
this.telephone = telephone; this.telephone = telephone;

View File

@ -145,7 +145,7 @@ public class VAppTemplate extends ResourceEntityType<VAppTemplate> {
@Override @Override
public VAppTemplate build() { public VAppTemplate build() {
return new VAppTemplate(href, type, links, description, tasksInProgress, id, name, files, status, owner, children, sections, vAppScopedLocalId, ovfDescriptorUploaded, goldMaster); return new VAppTemplate(href, type, links, description, tasks, id, name, files, status, owner, children, sections, vAppScopedLocalId, ovfDescriptorUploaded, goldMaster);
} }
@Override @Override
@ -210,11 +210,11 @@ public class VAppTemplate extends ResourceEntityType<VAppTemplate> {
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) { public Builder tasks(Set<Task> tasks) {
super.tasksInProgress(tasksInProgress); super.tasks(tasks);
return this; return this;
} }
@ -268,10 +268,10 @@ public class VAppTemplate extends ResourceEntityType<VAppTemplate> {
@XmlAttribute @XmlAttribute
protected Boolean goldMaster; protected Boolean goldMaster;
private VAppTemplate(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, private VAppTemplate(URI href, String type, Set<Link> links, String description, Set<Task> tasks,
String id, String name, FilesList files, Integer status, Owner owner, Set<VAppTemplate> children, String id, String name, FilesList files, Integer status, Owner owner, Set<VAppTemplate> children,
Set<? extends SectionType<?>> sections, String vAppScopedLocalId, Boolean ovfDescriptorUploaded, Boolean goldMaster) { Set<? extends SectionType<?>> sections, String vAppScopedLocalId, Boolean ovfDescriptorUploaded, Boolean goldMaster) {
super(href, type, links, description, tasksInProgress, id, name, files, status); super(href, type, links, description, tasks, id, name, files, status);
this.owner = owner; this.owner = owner;
this.children = VAppTemplateChildren.builder().vms(children).build(); this.children = VAppTemplateChildren.builder().vms(children).build();
this.sections = ImmutableSet.copyOf(sections); this.sections = ImmutableSet.copyOf(sections);

View File

@ -20,7 +20,6 @@
package org.jclouds.vcloud.director.v1_5.domain; package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI; import java.net.URI;
import java.util.Set; import java.util.Set;
@ -32,7 +31,6 @@ import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlType;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.Sets;
/** /**
@ -199,7 +197,7 @@ public class Vdc
public Vdc build() { public Vdc build() {
return new Vdc( return new Vdc(
href, type, links, description, tasksInProgress, id, name, allocationModel, storageCapacity, href, type, links, description, tasks, id, name, allocationModel, storageCapacity,
computeCapacity, resourceEntities, availableNetworks, capabilities, nicQuota, networkQuota, computeCapacity, resourceEntities, availableNetworks, capabilities, nicQuota, networkQuota,
vmQuota, isEnabled, status); vmQuota, isEnabled, status);
} }
@ -228,13 +226,13 @@ public class Vdc
this.id = id; this.id = id;
return this; return this;
} }
/** /**
* @see EntityType#getTasksInProgress() * @see EntityType#getTasks()
*/ */
@Override @Override
public Builder tasksInProgress(TasksInProgress tasksInProgress) { public Builder tasks(Set<Task> tasks) {
this.tasksInProgress = tasksInProgress; super.tasks(tasks);
return this; return this;
} }
@ -255,13 +253,13 @@ public class Vdc
this.type = type; this.type = type;
return this; return this;
} }
/** /**
* @see EntityType#getLinks() * @see EntityType#getLinks()
*/ */
@Override @Override
public Builder links(Set<Link> links) { public Builder links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); super.links(links);
return this; return this;
} }
@ -270,11 +268,10 @@ public class Vdc
*/ */
@Override @Override
public Builder link(Link link) { public Builder link(Link link) {
this.links.add(checkNotNull(link, "link")); super.link(link);
return this; return this;
} }
@Override @Override
public Builder fromEntityType(EntityType<Vdc> in) { public Builder fromEntityType(EntityType<Vdc> in) {
return Builder.class.cast(super.fromEntityType(in)); return Builder.class.cast(super.fromEntityType(in));
@ -296,8 +293,8 @@ public class Vdc
} }
} }
public Vdc(URI href, String type, Set<Link> links, String description, TasksInProgress tasksInProgress, String id, String name, String allocationModel, CapacityWithUsage storageCapacity, ComputeCapacity computeCapacity, ResourceEntities resourceEntities, AvailableNetworks availableNetworks, Capabilities capabilities, int nicQuota, int networkQuota, Integer vmQuota, Boolean enabled, Integer status) { public Vdc(URI href, String type, Set<Link> links, String description, Set<Task> tasks, String id, String name, String allocationModel, CapacityWithUsage storageCapacity, ComputeCapacity computeCapacity, ResourceEntities resourceEntities, AvailableNetworks availableNetworks, Capabilities capabilities, int nicQuota, int networkQuota, Integer vmQuota, Boolean enabled, Integer status) {
super(href, type, links, description, tasksInProgress, id, name); super(href, type, links, description, tasks, id, name);
this.allocationModel = allocationModel; this.allocationModel = allocationModel;
this.storageCapacity = storageCapacity; this.storageCapacity = storageCapacity;
this.computeCapacity = computeCapacity; this.computeCapacity = computeCapacity;

View File

@ -23,3 +23,4 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_CI
import javax.xml.bind.annotation.XmlNsForm; import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema; import javax.xml.bind.annotation.XmlSchema;

View File

@ -30,3 +30,4 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_OV
import javax.xml.bind.annotation.XmlNs; import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm; import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema; import javax.xml.bind.annotation.XmlSchema;

View File

@ -30,3 +30,4 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_OV
import javax.xml.bind.annotation.XmlNs; import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm; import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema; import javax.xml.bind.annotation.XmlSchema;

View File

@ -29,3 +29,4 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_CI
import javax.xml.bind.annotation.XmlNs; import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm; import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema; import javax.xml.bind.annotation.XmlSchema;

View File

@ -31,3 +31,4 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_OV
import javax.xml.bind.annotation.XmlNs; import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm; import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema; import javax.xml.bind.annotation.XmlSchema;

View File

@ -66,9 +66,9 @@ public class Checks {
// Check optional fields // Check optional fields
// NOTE description cannot be checked // NOTE description cannot be checked
TasksInProgress tasksInProgress = entity.getTasksInProgress(); Set<Task> tasks = entity.getTasks();
if (tasksInProgress != null && tasksInProgress.getTasks() != null && !tasksInProgress.getTasks().isEmpty()) { if (tasks != null && tasks != null && !tasks.isEmpty()) {
for (Task task : tasksInProgress.getTasks()) checkTask(task); for (Task task : tasks) checkTask(task);
} }
// Check parent type // Check parent type

View File

@ -38,10 +38,11 @@ import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.TasksInProgress;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest; import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/** /**
* Allows us to test a client via its side effects. * Allows us to test a client via its side effects.
* *
@ -415,8 +416,8 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes
.href(URI.create("https://mycloud.greenhousedata.com/api/media/a6b023f2-7f90-4e89-a24d-56e0eba83a5a")) .href(URI.create("https://mycloud.greenhousedata.com/api/media/a6b023f2-7f90-4e89-a24d-56e0eba83a5a"))
.build()) .build())
.description("copied by testCloneMedia()") .description("copied by testCloneMedia()")
.tasksInProgress(TasksInProgress.builder() .tasks(ImmutableSet.<Task>builder()
.task(Task.builder() .add(Task.builder()
.status("running") .status("running")
.startTime(dateService.iso8601DateParse("2012-03-02T04:58:48.754-07:00")) .startTime(dateService.iso8601DateParse("2012-03-02T04:58:48.754-07:00"))
.operationName("vdcCopyMedia") .operationName("vdcCopyMedia")

View File

@ -143,7 +143,7 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
media = mediaClient.getMedia(media.getHref()); media = mediaClient.getMedia(media.getHref());
Task task = Iterables.getOnlyElement(media.getTasksInProgress().getTasks()); Task task = Iterables.getOnlyElement(media.getTasks());
assertEquals(task.getStatus(), "running"); assertEquals(task.getStatus(), "running");
@ -192,8 +192,8 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Checks.checkMediaFor(VDC, media); Checks.checkMediaFor(VDC, media);
if (media.getTasksInProgress() != null) { if (media.getTasks() != null) {
Task copyTask = getFirst(media.getTasksInProgress().getTasks(), null); Task copyTask = getFirst(media.getTasks(), null);
if (copyTask != null) { if (copyTask != null) {
Checks.checkTask(copyTask); Checks.checkTask(copyTask);
assertTrue(retryTaskSuccess.apply(copyTask), String.format(TASK_COMPLETE_TIMELY, "copyTask")); assertTrue(retryTaskSuccess.apply(copyTask), String.format(TASK_COMPLETE_TIMELY, "copyTask"));
@ -216,8 +216,8 @@ public class MediaClientLiveTest extends BaseVCloudDirectorClientLiveTest {
Checks.checkMediaFor(VDC, media); Checks.checkMediaFor(VDC, media);
if (media.getTasksInProgress() != null) { if (media.getTasks() != null) {
Task copyTask = getFirst(media.getTasksInProgress().getTasks(), null); Task copyTask = getFirst(media.getTasks(), null);
if (copyTask != null) { if (copyTask != null) {
Checks.checkTask(copyTask); Checks.checkTask(copyTask);
assertTrue(retryTaskSuccess.apply(copyTask), String.format(TASK_COMPLETE_TIMELY, "copyTask")); assertTrue(retryTaskSuccess.apply(copyTask), String.format(TASK_COMPLETE_TIMELY, "copyTask"));

View File

@ -81,11 +81,11 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
.name("Tasks Lists") .name("Tasks Lists")
.type("application/vnd.vmware.vcloud.tasksList+xml") .type("application/vnd.vmware.vcloud.tasksList+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0")) .href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
.task(taskOne())
.task(taskTwo()) .task(taskTwo())
.task(taskOne())
.build(); .build();
assertEquals(client.getTaskClient().getTaskList(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")), expected); assertEquals(client.getTaskClient().getTaskList(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).toString(), expected.toString());
} }
@Test @Test
@ -198,6 +198,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
URI taskUri = URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b"); URI taskUri = URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b");
//TODO: incorrect relationship, as task should not have a nested task container!!
Task expected = taskOne(); Task expected = taskOne();
assertEquals(client.getTaskClient().getTask(taskUri), expected); assertEquals(client.getTaskClient().getTask(taskUri), expected);

View File

@ -80,9 +80,9 @@ public class TaskClientLiveTest extends BaseVCloudDirectorClientLiveTest {
// NOTE The environment MUST have ... // NOTE The environment MUST have ...
// Check required elements and attributes // Check required elements and attributes
assertFalse(Iterables.isEmpty(taskList.getTasks()), String.format(NOT_EMPTY_OBJECT_FMT, "Task", "TaskList")); assertFalse(Iterables.isEmpty(taskList), String.format(NOT_EMPTY_OBJECT_FMT, "Task", "TaskList"));
for (Task task : taskList.getTasks()) { for (Task task : taskList) {
checkTask(task); checkTask(task);
} }
} }
@ -91,7 +91,7 @@ public class TaskClientLiveTest extends BaseVCloudDirectorClientLiveTest {
public void testGetTask() { public void testGetTask() {
//TODO: upload media or something so you can get a fresh cancellable task? //TODO: upload media or something so you can get a fresh cancellable task?
Task taskRef = Iterables.getFirst(taskList.getTasks(), null); Task taskRef = Iterables.getFirst(taskList, null);
taskURI = taskRef.getHref(); taskURI = taskRef.getHref();
// Call the method being tested // Call the method being tested