mirror of https://github.com/apache/jclouds.git
refractor catalog domain objects to allow inheritance, add adminCatalog + checks
This commit is contained in:
parent
def07846c8
commit
aa80bfbff1
|
@ -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.
|
||||
*
|
||||
*
|
||||
* <p>Java class for AdminCatalog complex type.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType name="AdminCatalog">
|
||||
* <complexContent>
|
||||
* <extension base="{http://www.vmware.com/vcloud/v1.5}CatalogType">
|
||||
* <anyAttribute processContents='lax' namespace='##other'/>
|
||||
* </extension>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "AdminCatalog")
|
||||
public class AdminCatalog extends CatalogType<AdminCatalog> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromAdminCatalog(this);
|
||||
}
|
||||
|
||||
public static class Builder extends CatalogType.Builder<AdminCatalog> {
|
||||
|
||||
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<Link> 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<AdminCatalog> in) {
|
||||
return Builder.class.cast(super.fromCatalogType(in));
|
||||
}
|
||||
public Builder fromAdminCatalog(AdminCatalog in) {
|
||||
return fromCatalogType(in);
|
||||
}
|
||||
}
|
||||
|
||||
private AdminCatalog() {
|
||||
// For JAXB
|
||||
}
|
||||
}
|
|
@ -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<Catalog> {
|
||||
public class Catalog extends CatalogType<Catalog> {
|
||||
|
||||
public static final String MEDIA_TYPE = VCloudDirectorMediaType.CATALOG;
|
||||
|
||||
|
@ -53,17 +53,18 @@ public class Catalog extends EntityType<Catalog> {
|
|||
return new Builder().fromCatalog(this);
|
||||
}
|
||||
|
||||
public static class Builder extends EntityType.Builder<Catalog> {
|
||||
|
||||
private Entity owner;
|
||||
private CatalogItems catalogItems;
|
||||
private Boolean isPublished;
|
||||
public static class Builder extends CatalogType.Builder<Catalog> {
|
||||
|
||||
@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<Catalog> {
|
|||
* @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<Catalog> {
|
|||
* @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<Catalog> {
|
|||
* @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<Catalog> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Builder fromEntityType(EntityType<Catalog> in) {
|
||||
return Builder.class.cast(super.fromEntityType(in));
|
||||
public Builder fromCatalogType(CatalogType<Catalog> 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<Link> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
* <p/>
|
||||
* <pre>
|
||||
* <complexType name="CatalogType" />
|
||||
* </pre>
|
||||
*
|
||||
* @author danikov
|
||||
*/
|
||||
@XmlRootElement(name = "Catalog")
|
||||
public class CatalogType<T extends CatalogType<T>> extends EntityType<T> {
|
||||
|
||||
public static <T extends CatalogType<T>> Builder<T> builder() {
|
||||
return new Builder<T>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder<T> toBuilder() {
|
||||
return new Builder<T>().fromCatalogType(this);
|
||||
}
|
||||
|
||||
public static class Builder<T extends CatalogType<T>> extends EntityType.Builder<T> {
|
||||
|
||||
protected Entity owner;
|
||||
protected CatalogItems catalogItems;
|
||||
protected Boolean isPublished;
|
||||
|
||||
/**
|
||||
* @see CatalogType#getOwner()
|
||||
*/
|
||||
public Builder<T> owner(Entity owner) {
|
||||
this.owner = owner;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CatalogType#getCatalogItems()
|
||||
*/
|
||||
public Builder<T> catalogItems(CatalogItems catalogItems) {
|
||||
this.catalogItems = catalogItems;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CatalogType#isPublished()
|
||||
*/
|
||||
public Builder<T> isPublished(Boolean isPublished) {
|
||||
this.isPublished = isPublished;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CatalogType#isPublished()
|
||||
*/
|
||||
public Builder<T> published() {
|
||||
this.isPublished = Boolean.TRUE;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CatalogType<T> build() {
|
||||
return new CatalogType<T>(href, type, links, description, tasksInProgress, id, name, owner, catalogItems, isPublished);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityType#getName()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> name(String name) {
|
||||
super.name(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityType#getDescription()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> description(String description) {
|
||||
super.description(description);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityType#getId()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> id(String id) {
|
||||
super.id(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityType#getTasksInProgress()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> tasksInProgress(TasksInProgress tasksInProgress) {
|
||||
super.tasksInProgress(tasksInProgress);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ReferenceType#getHref()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> href(URI href) {
|
||||
super.href(href);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ReferenceType#getType()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> type(String type) {
|
||||
super.type(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityType#getLinks()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> links(Set<Link> links) {
|
||||
super.links(links);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see EntityType#getLinks()
|
||||
*/
|
||||
@Override
|
||||
public Builder<T> link(Link link) {
|
||||
super.link(link);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Builder<T> fromEntityType(EntityType<T> in) {
|
||||
return Builder.class.cast(super.fromEntityType(in));
|
||||
}
|
||||
|
||||
public Builder<T> fromCatalogType(CatalogType<T> in) {
|
||||
return fromEntityType(in).owner(in.getOwner()).catalogItems(in.getCatalogItems()).isPublished(in.isPublished());
|
||||
}
|
||||
}
|
||||
|
||||
public CatalogType(URI href, String type, Set<Link> 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue