From aa80bfbff1464881899f0f797f5ee2fb6bd77d58 Mon Sep 17 00:00:00 2001 From: danikov Date: Mon, 5 Mar 2012 18:52:29 +0000 Subject: [PATCH] refractor catalog domain objects to allow inheritance, add adminCatalog + checks --- .../director/v1_5/domain/AdminCatalog.java | 192 ++++++++++++++ .../vcloud/director/v1_5/domain/Catalog.java | 71 ++--- .../director/v1_5/domain/CatalogType.java | 244 ++++++++++++++++++ .../vcloud/director/v1_5/domain/Checks.java | 11 +- 4 files changed, 462 insertions(+), 56 deletions(-) create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AdminCatalog.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogType.java diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AdminCatalog.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AdminCatalog.java new file mode 100644 index 0000000000..af42723b72 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AdminCatalog.java @@ -0,0 +1,192 @@ +/** + * 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.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + +import com.google.common.collect.Sets; + + +/** + * + * Admin representation of the container for meta data (key-value pair) associated to different + * entities in the system. + * + * + *

Java class for AdminCatalog complex type. + * + *

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

+ * <complexType name="AdminCatalog">
+ *   <complexContent>
+ *     <extension base="{http://www.vmware.com/vcloud/v1.5}CatalogType">
+ *       <anyAttribute processContents='lax' namespace='##other'/>
+ *     </extension>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "AdminCatalog") +public class AdminCatalog extends CatalogType { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromAdminCatalog(this); + } + + public static class Builder extends CatalogType.Builder { + + public AdminCatalog build() { + AdminCatalog adminCatalog = new AdminCatalog(); + return adminCatalog; + } + + /** + * @see CatalogType#getOwner() + */ + public Builder owner(Entity owner) { + super.owner(owner); + return this; + } + + /** + * @see CatalogType#getCatalogItems() + */ + public Builder catalogItems(CatalogItems catalogItems) { + super.catalogItems(catalogItems); + return this; + } + + /** + * @see CatalogType#isPublished() + */ + public Builder isPublished(Boolean isPublished) { + super.isPublished(isPublished); + return this; + } + + /** + * @see CatalogType#isPublished() + */ + public Builder published() { + super.published(); + return this; + } + + /** + * @see EntityType#getName() + */ + @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 + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see ReferenceType#getType() + */ + @Override + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see EntityType#getLinks() + */ + @Override + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } + + /** + * @see EntityType#getLinks() + */ + @Override + public Builder link(Link link) { + this.links.add(checkNotNull(link, "link")); + return this; + } + + @Override + public Builder fromCatalogType(CatalogType in) { + return Builder.class.cast(super.fromCatalogType(in)); + } + public Builder fromAdminCatalog(AdminCatalog in) { + return fromCatalogType(in); + } + } + + private AdminCatalog() { + // For JAXB + } +} diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Catalog.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Catalog.java index 4495669a1d..ba5ec47507 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Catalog.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Catalog.java @@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; import java.util.Set; -import javax.xml.bind.annotation.XmlElement; + import javax.xml.bind.annotation.XmlRootElement; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; @@ -39,7 +39,7 @@ import com.google.common.collect.Sets; * @author grkvlt@apache.org */ @XmlRootElement(name = "Catalog") -public class Catalog extends EntityType { +public class Catalog extends CatalogType { public static final String MEDIA_TYPE = VCloudDirectorMediaType.CATALOG; @@ -53,17 +53,18 @@ public class Catalog extends EntityType { return new Builder().fromCatalog(this); } - public static class Builder extends EntityType.Builder { - - private Entity owner; - private CatalogItems catalogItems; - private Boolean isPublished; + public static class Builder extends CatalogType.Builder { + @Override + public Catalog build() { + return new Catalog(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, isPublished); + } + /** * @see Catalog#getOwner() */ public Builder owner(Entity owner) { - this.owner = owner; + super.owner(owner); return this; } @@ -71,7 +72,7 @@ public class Catalog extends EntityType { * @see Catalog#getCatalogItems() */ public Builder catalogItems(CatalogItems catalogItems) { - this.catalogItems = catalogItems; + super.catalogItems(catalogItems); return this; } @@ -79,7 +80,7 @@ public class Catalog extends EntityType { * @see Catalog#isPublished() */ public Builder isPublished(Boolean isPublished) { - this.isPublished = isPublished; + super.isPublished(isPublished); return this; } @@ -87,15 +88,10 @@ public class Catalog extends EntityType { * @see Catalog#isPublished() */ public Builder published() { - this.isPublished = Boolean.TRUE; + super.isPublished(isPublished); return this; } - @Override - public Catalog build() { - return new Catalog(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, isPublished); - } - /** * @see EntityType#getName() */ @@ -169,53 +165,22 @@ public class Catalog extends EntityType { } @Override - public Builder fromEntityType(EntityType in) { - return Builder.class.cast(super.fromEntityType(in)); + public Builder fromCatalogType(CatalogType in) { + return Builder.class.cast(super.fromCatalogType(in)); } public Builder fromCatalog(Catalog in) { - return fromEntityType(in).owner(in.getOwner()).catalogItems(in.getCatalogItems()).isPublished(in.isPublished()); + return fromCatalogType(in).owner(in.getOwner()).catalogItems(in.getCatalogItems()).isPublished(in.isPublished()); } } public Catalog(URI href, String type, Set links, String description, TasksInProgress tasksInProgress, String id, String name, Entity owner, CatalogItems catalogItems, Boolean published) { - super(href, type, links, description, tasksInProgress, id, name); - this.owner = owner; - this.catalogItems = catalogItems; - this.isPublished = published; + super(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, published); } + @SuppressWarnings("unused") private Catalog() { - // For JAXB and builder use + // for JAXB } - - @XmlElement(name = "Owner") - private Entity owner; - @XmlElement(name = "CatalogItems") - private CatalogItems catalogItems; - @XmlElement(name = "IsPublished") - private Boolean isPublished; - - /** - * Gets the value of the owner property. - */ - public Entity getOwner() { - return owner; - } - - /** - * Gets the value of the catalogItems property. - */ - public CatalogItems getCatalogItems() { - return catalogItems; - } - - /** - * Gets the value of the isPublished property. - */ - public Boolean isPublished() { - return isPublished; - } - } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogType.java new file mode 100644 index 0000000000..5fa21d5872 --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CatalogType.java @@ -0,0 +1,244 @@ +/* + * 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 java.net.URI; +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.base.Objects.ToStringHelper; + +/** + * Container for references to VappTemplate and Media objects. + *

+ *

+ * <complexType name="CatalogType" />
+ * 
+ * + * @author danikov + */ +@XmlRootElement(name = "Catalog") +public class CatalogType> extends EntityType { + + public static > Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromCatalogType(this); + } + + public static class Builder> extends EntityType.Builder { + + protected Entity owner; + protected CatalogItems catalogItems; + protected Boolean isPublished; + + /** + * @see CatalogType#getOwner() + */ + public Builder owner(Entity owner) { + this.owner = owner; + return this; + } + + /** + * @see CatalogType#getCatalogItems() + */ + public Builder catalogItems(CatalogItems catalogItems) { + this.catalogItems = catalogItems; + return this; + } + + /** + * @see CatalogType#isPublished() + */ + public Builder isPublished(Boolean isPublished) { + this.isPublished = isPublished; + return this; + } + + /** + * @see CatalogType#isPublished() + */ + public Builder published() { + this.isPublished = Boolean.TRUE; + return this; + } + + @Override + public CatalogType build() { + return new CatalogType(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, isPublished); + } + + /** + * @see EntityType#getName() + */ + @Override + public Builder name(String name) { + super.name(name); + return this; + } + + /** + * @see EntityType#getDescription() + */ + @Override + public Builder description(String description) { + super.description(description); + return this; + } + + /** + * @see EntityType#getId() + */ + @Override + public Builder id(String id) { + super.id(id); + return this; + } + + /** + * @see EntityType#getTasksInProgress() + */ + @Override + public Builder tasksInProgress(TasksInProgress tasksInProgress) { + super.tasksInProgress(tasksInProgress); + return this; + } + + /** + * @see ReferenceType#getHref() + */ + @Override + public Builder href(URI href) { + super.href(href); + return this; + } + + /** + * @see ReferenceType#getType() + */ + @Override + public Builder type(String type) { + super.type(type); + return this; + } + + /** + * @see EntityType#getLinks() + */ + @Override + public Builder links(Set links) { + super.links(links); + return this; + } + + /** + * @see EntityType#getLinks() + */ + @Override + public Builder link(Link link) { + super.link(link); + return this; + } + + @SuppressWarnings("unchecked") + @Override + public Builder fromEntityType(EntityType in) { + return Builder.class.cast(super.fromEntityType(in)); + } + + public Builder fromCatalogType(CatalogType in) { + return fromEntityType(in).owner(in.getOwner()).catalogItems(in.getCatalogItems()).isPublished(in.isPublished()); + } + } + + public CatalogType(URI href, String type, Set links, String description, TasksInProgress tasksInProgress, String id, + String name, Entity owner, CatalogItems catalogItems, Boolean published) { + super(href, type, links, description, tasksInProgress, id, name); + this.owner = owner; + this.catalogItems = catalogItems; + this.isPublished = published; + } + + protected CatalogType() { + // For JAXB + } + + @XmlElement(name = "Owner") + private Entity owner; + @XmlElement(name = "CatalogItems") + private CatalogItems catalogItems; + @XmlElement(name = "IsPublished") + private Boolean isPublished; + + /** + * Gets the value of the owner property. + */ + public Entity getOwner() { + return owner; + } + + /** + * Gets the value of the catalogItems property. + */ + public CatalogItems getCatalogItems() { + return catalogItems; + } + + /** + * Gets the value of the isPublished property. + */ + public Boolean isPublished() { + return isPublished; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + CatalogType that = CatalogType.class.cast(o); + return super.equals(that) && + equal(this.owner, that.owner) && + equal(this.catalogItems, that.catalogItems) && + equal(this.isPublished, that.isPublished); + } + + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), owner, catalogItems, catalogItems); + } + + @Override + public ToStringHelper string() { + return super.string().add("owner", owner) + .add("catalogItems", catalogItems) + .add("isPublished", isPublished); + } + +} 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 fcf5d55f3d..b8e0bafb61 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 @@ -20,10 +20,10 @@ package org.jclouds.vcloud.director.v1_5.domain; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CONDITION_FMT; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.MUST_BE_WELL_FORMED_FMT; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_ATTRB_REQ; -import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.MUST_CONTAIN_FMT; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.NOT_NULL_OBJECT_FMT; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_ATTRB_REQ; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_GTE_0; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_REQ; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REQUIRED_VALUE_FMT; @@ -228,8 +228,13 @@ public class Checks { // Check parent type checkEntityType(org); } + + public static void checkAdminCatalog(AdminCatalog catalog) { + // Check parent type + checkCatalogType(catalog); + } - public static void checkCatalog(Catalog catalog) { + public static void checkCatalogType(CatalogType catalog) { // Check optional elements/attributes Entity owner = catalog.getOwner(); if (owner != null) checkEntityType(owner);