Issue 695: Refactoring1: Pushed up links, actions to BaseResource as lots of duplication. Added some getAttributes overrides in builders

This commit is contained in:
Jason King 2011-11-25 15:39:31 +00:00
parent 115f93a7d7
commit 22a63f7177
20 changed files with 371 additions and 241 deletions

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.tmrk.enterprisecloud.domain; package org.jclouds.tmrk.enterprisecloud.domain;
import com.google.common.collect.Sets;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
@ -27,6 +28,7 @@ import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlEnumValue;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set;
import static com.google.common.base.CaseFormat.LOWER_CAMEL; import static com.google.common.base.CaseFormat.LOWER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
@ -155,6 +157,22 @@ public class Action extends BaseNamedResource<Action> {
return Builder.class.cast(super.type(type)); return Builder.class.cast(super.type(type));
} }
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
throw new UnsupportedOperationException("links is not valid for Action");
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
throw new UnsupportedOperationException("actions is not valid for Action");
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -171,14 +189,15 @@ public class Action extends BaseNamedResource<Action> {
@XmlAttribute @XmlAttribute
protected ActionDisabled actionDisabled; protected ActionDisabled actionDisabled;
public Action(URI href, String type, String name, @Nullable ActionDisabled actionDisabled) { private Action(URI href, String type, String name, @Nullable ActionDisabled actionDisabled) {
super(href, type, name); super(href, type, Sets.<Link>newLinkedHashSet(), Sets.<Action>newLinkedHashSet(), name);
this.actionDisabled = actionDisabled; this.actionDisabled = actionDisabled;
} }
protected Action() { private Action() {
//For JAXB //For JAXB
} }
/** /**
* The attribute actionDisabled appears only when the example has an action * The attribute actionDisabled appears only when the example has an action
* disabled for business rules. * disabled for business rules.

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.tmrk.enterprisecloud.domain; package org.jclouds.tmrk.enterprisecloud.domain;
import com.google.common.collect.Sets;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
@ -26,6 +27,7 @@ import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlEnumValue;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -170,6 +172,22 @@ public class Link extends BaseNamedResource<Link> {
return Builder.class.cast(super.type(type)); return Builder.class.cast(super.type(type));
} }
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
throw new UnsupportedOperationException("links is not valid for Link");
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
throw new UnsupportedOperationException("actions is not valid for Link");
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -185,12 +203,12 @@ public class Link extends BaseNamedResource<Link> {
@XmlAttribute @XmlAttribute
protected Relationship rel; protected Relationship rel;
public Link(URI href, String type, String name, Relationship rel) { private Link(URI href, String type, String name, Relationship rel) {
super(href, type, name); super(href, type, Sets.<Link>newLinkedHashSet(), Sets.<Action>newLinkedHashSet(), name);
this.rel = checkNotNull(rel, "rel"); this.rel = checkNotNull(rel, "rel");
} }
protected Link() { private Link() {
//For JAXB //For JAXB
} }

View File

@ -20,6 +20,7 @@ package org.jclouds.tmrk.enterprisecloud.domain;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
@ -51,7 +52,7 @@ public class NamedResource extends BaseNamedResource<NamedResource> {
*/ */
@Override @Override
public NamedResource build() { public NamedResource build() {
return new NamedResource(href, type, name); return new NamedResource(href, type, links, actions, name);
} }
/** /**
@ -94,6 +95,22 @@ public class NamedResource extends BaseNamedResource<NamedResource> {
return Builder.class.cast(super.type(type)); return Builder.class.cast(super.type(type));
} }
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -104,8 +121,8 @@ public class NamedResource extends BaseNamedResource<NamedResource> {
} }
public NamedResource(URI href, String type, String name) { private NamedResource(URI href, String type, Set<Link> links, Set<Action> actions, String name) {
super(href, type, name); super(href, type, links, actions, name);
} }
protected NamedResource() { protected NamedResource() {

View File

@ -25,6 +25,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI; import java.net.URI;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
@ -186,7 +187,7 @@ public class Task extends BaseResource<Task> {
@Override @Override
public Task build() { public Task build() {
return new Task(href, type, operation, status, impactedItem, startTime, completedTime, notes, errorMessage, return new Task(href, type, links, actions, operation, status, impactedItem, startTime, completedTime, notes, errorMessage,
initiatedBy); initiatedBy);
} }
@ -220,6 +221,22 @@ public class Task extends BaseResource<Task> {
return Builder.class.cast(super.href(href)); return Builder.class.cast(super.href(href));
} }
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -254,9 +271,9 @@ public class Task extends BaseResource<Task> {
@XmlElement(name = "InitiatedBy", required = true) @XmlElement(name = "InitiatedBy", required = true)
protected NamedResource initiatedBy; protected NamedResource initiatedBy;
public Task(URI href, String type, String operation, Status status, NamedResource impactedItem, Date startTime, private Task(URI href, String type, Set<Link> links, Set<Action> actions, String operation, Status status, NamedResource impactedItem, Date startTime,
@Nullable Date completedTime, @Nullable String notes, @Nullable String errorMessage, NamedResource initiatedBy) { @Nullable Date completedTime, @Nullable String notes, @Nullable String errorMessage, NamedResource initiatedBy) {
super(href, type); super(href, type, links, actions);
this.operation = checkNotNull(operation, "operation"); this.operation = checkNotNull(operation, "operation");
this.status = checkNotNull(status, "status"); this.status = checkNotNull(status, "status");
this.impactedItem = checkNotNull(impactedItem, "impactedItem"); this.impactedItem = checkNotNull(impactedItem, "impactedItem");
@ -267,7 +284,7 @@ public class Task extends BaseResource<Task> {
this.initiatedBy = checkNotNull(initiatedBy, "initiatedBy"); this.initiatedBy = checkNotNull(initiatedBy, "initiatedBy");
} }
protected Task() { private Task() {
//For JAXB //For JAXB
} }

View File

@ -22,7 +22,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.Action; import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Actions; import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity; import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.network.Nics; import org.jclouds.tmrk.enterprisecloud.domain.network.Nics;
@ -59,21 +59,11 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
public static class Builder extends BaseResource.Builder<HardwareConfiguration> { public static class Builder extends BaseResource.Builder<HardwareConfiguration> {
// TODO Links
private Set<Action> actions = Sets.newLinkedHashSet();
private int processorCount; private int processorCount;
private ResourceCapacity memory; private ResourceCapacity memory;
private Set<VirtualDisk> virtualDisks = Sets.newLinkedHashSet(); private Set<VirtualDisk> virtualDisks = Sets.newLinkedHashSet();
private Set<VirtualNic> virtualNics = Sets.newLinkedHashSet(); private Set<VirtualNic> virtualNics = Sets.newLinkedHashSet();
/**
* @see HardwareConfiguration#getActions
*/
public Builder actions(Set<Action> actions) {
this.actions = ImmutableSet.<Action> copyOf(checkNotNull(actions, "actions"));
return this;
}
/** /**
* @see HardwareConfiguration#getProcessorCount * @see HardwareConfiguration#getProcessorCount
*/ */
@ -109,7 +99,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
@Override @Override
public HardwareConfiguration build() { public HardwareConfiguration build() {
return new HardwareConfiguration(actions, processorCount, memory, virtualDisks, virtualNics); return new HardwareConfiguration(processorCount, memory, virtualDisks, virtualNics);
} }
/** /**
@ -136,6 +126,22 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
return Builder.class.cast(super.href(href)); return Builder.class.cast(super.href(href));
} }
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -145,17 +151,13 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
} }
public Builder fromHardwareConfiguration(HardwareConfiguration in) { public Builder fromHardwareConfiguration(HardwareConfiguration in) {
return fromResource(in).actions(in.getActions()) return fromResource(in).processorCount(in.getProcessorCount())
.processorCount(in.getProcessorCount())
.memory(in.getMemory()) .memory(in.getMemory())
.disks(in.getVirtualDisks()) .disks(in.getVirtualDisks())
.nics(in.getVirtualNics()); .nics(in.getVirtualNics());
} }
} }
@XmlElement(name = "Actions", required = false)
private Actions actions = Actions.builder().build();
@XmlElement(name = "ProcessorCount", required = true) @XmlElement(name = "ProcessorCount", required = true)
private int processorCount; private int processorCount;
@ -168,22 +170,17 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
@XmlElement(name = "Nics", required = false) @XmlElement(name = "Nics", required = false)
private Nics virtualNics = Nics.builder().build(); private Nics virtualNics = Nics.builder().build();
public HardwareConfiguration(Set<Action> actions, int processorCount, @Nullable ResourceCapacity memory, Set<VirtualDisk> virtualDisks, Set<VirtualNic> virtualNics) { private HardwareConfiguration(int processorCount, @Nullable ResourceCapacity memory, Set<VirtualDisk> virtualDisks, Set<VirtualNic> virtualNics) {
this.actions = Actions.builder().actions(checkNotNull(actions, "actions")).build();
this.virtualDisks = Disks.builder().disks(checkNotNull(virtualDisks,"virtualDisks")).build(); this.virtualDisks = Disks.builder().disks(checkNotNull(virtualDisks,"virtualDisks")).build();
this.virtualNics = Nics.builder().nics(checkNotNull(virtualNics, "virtualNics")).build(); this.virtualNics = Nics.builder().nics(checkNotNull(virtualNics, "virtualNics")).build();
this.processorCount = processorCount; this.processorCount = processorCount;
this.memory = memory; this.memory = memory;
} }
protected HardwareConfiguration() { private HardwareConfiguration() {
//For JAXB //For JAXB
} }
public Set<Action> getActions() {
return Collections.unmodifiableSet(actions.getActions());
}
public int getProcessorCount() { public int getProcessorCount() {
return processorCount; return processorCount;
} }
@ -209,7 +206,6 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
HardwareConfiguration that = (HardwareConfiguration) o; HardwareConfiguration that = (HardwareConfiguration) o;
if (processorCount != that.processorCount) return false; if (processorCount != that.processorCount) return false;
if (!actions.equals(that.actions)) return false;
if (!virtualDisks.equals(that.virtualDisks)) return false; if (!virtualDisks.equals(that.virtualDisks)) return false;
if (memory != null ? !memory.equals(that.memory) : that.memory != null) if (memory != null ? !memory.equals(that.memory) : that.memory != null)
return false; return false;
@ -221,7 +217,6 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
@Override @Override
public int hashCode() { public int hashCode() {
int result = super.hashCode(); int result = super.hashCode();
result = 31 * result + actions.hashCode();
result = 31 * result + processorCount; result = 31 * result + processorCount;
result = 31 * result + (memory != null ? memory.hashCode() : 0); result = 31 * result + (memory != null ? memory.hashCode() : 0);
result = 31 * result + virtualDisks.hashCode(); result = 31 * result + virtualDisks.hashCode();
@ -231,7 +226,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
@Override @Override
public String string() { public String string() {
return super.string()+", actions="+actions+", processorCount="+processorCount+ return super.string()+", processorCount="+processorCount+
", memory="+memory+", disks="+ virtualDisks +", nics="+ virtualNics; ", memory="+memory+", disks="+ virtualDisks +", nics="+ virtualNics;
} }
} }

View File

@ -18,12 +18,16 @@
*/ */
package org.jclouds.tmrk.enterprisecloud.domain.internal; package org.jclouds.tmrk.enterprisecloud.domain.internal;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
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.Map; import java.util.Map;
import java.util.Set;
/** /**
* Location of a Rest resource * Location of a Rest resource
@ -54,7 +58,7 @@ public class BaseNamedResource<T extends BaseNamedResource<T>> extends BaseResou
} }
public BaseNamedResource<T> build() { public BaseNamedResource<T> build() {
return new BaseNamedResource<T>(href, type, name); return new BaseNamedResource<T>(href, type, links, actions, name);
} }
/** /**
@ -82,8 +86,8 @@ public class BaseNamedResource<T extends BaseNamedResource<T>> extends BaseResou
@XmlAttribute @XmlAttribute
protected String name; protected String name;
public BaseNamedResource(URI href, String type, String name) { protected BaseNamedResource(URI href, String type, Set<Link> links, Set<Action> actions, String name) {
super(href, type); super(href, type, links, actions);
this.name = checkNotNull(name, "name"); this.name = checkNotNull(name, "name");
} }

View File

@ -18,12 +18,21 @@
*/ */
package org.jclouds.tmrk.enterprisecloud.domain.internal; package org.jclouds.tmrk.enterprisecloud.domain.internal;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Actions;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.Links;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
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.Map; import java.util.Map;
import java.util.Set;
/** /**
* Location of a Rest resource * Location of a Rest resource
@ -45,6 +54,8 @@ public class BaseResource<T extends BaseResource<T>> {
protected String type; protected String type;
protected URI href; protected URI href;
protected Set<Link> links = Sets.newLinkedHashSet();
protected Set<Action> actions = Sets.newLinkedHashSet();
/** /**
* @see BaseResource#getType * @see BaseResource#getType
@ -62,12 +73,28 @@ public class BaseResource<T extends BaseResource<T>> {
return this; return this;
} }
/**
* @see BaseResource#getLinks
*/
public Builder links(Set<Link> links) {
this.links = ImmutableSet.<Link> copyOf(checkNotNull(links, "links"));
return this;
}
/**
* @see BaseResource#getActions
*/
public Builder actions(Set<Action> actions) {
this.actions = ImmutableSet.<Action> copyOf(checkNotNull(actions, "actions"));
return this;
}
public BaseResource<T> build() { public BaseResource<T> build() {
return new BaseResource<T>(href, type); return new BaseResource<T>(href, type, links, actions);
} }
public Builder<T> fromResource(BaseResource<T> in) { public Builder<T> fromResource(BaseResource<T> in) {
return type(in.getType()).href(in.getHref()); return type(in.getType()).href(in.getHref()).links(in.getLinks()).actions(in.getActions());
} }
public Builder<T> fromAttributes(Map<String, String> attributes) { public Builder<T> fromAttributes(Map<String, String> attributes) {
@ -82,9 +109,17 @@ public class BaseResource<T extends BaseResource<T>> {
@XmlAttribute @XmlAttribute
protected URI href; protected URI href;
public BaseResource(URI href, String type) { @XmlElement(name = "Links", required = false)
protected Links links = Links.builder().build();
@XmlElement(name = "Actions", required = false)
protected Actions actions = Actions.builder().build();
public BaseResource(URI href, String type, Set<Link> links, Set<Action> actions) {
this.type = checkNotNull(type, "type"); this.type = checkNotNull(type, "type");
this.href = checkNotNull(href, "href"); this.href = checkNotNull(href, "href");
this.links = Links.builder().links(checkNotNull(links,"links")).build();
this.actions = Actions.builder().actions(checkNotNull(actions, "actions")).build();
} }
protected BaseResource() { protected BaseResource() {
@ -107,43 +142,54 @@ public class BaseResource<T extends BaseResource<T>> {
return href; return href;
} }
@Override /**
public int hashCode() { * @return the links related to this object
final int prime = 31; */
int result = 1; public Set<Link> getLinks() {
result = prime * result + ((href == null) ? 0 : href.hashCode()); return links.getLinks();
result = prime * result + ((type == null) ? 0 : type.hashCode()); }
return result;
/**
* @return the actions available from this object
*/
public Set<Action> getActions() {
return actions.getActions();
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object o) {
if (this == obj) if (this == o) return true;
return true; if (o == null || getClass() != o.getClass()) return false;
if (obj == null)
BaseResource that = (BaseResource) o;
if (actions != null ? !actions.equals(that.actions) : that.actions != null)
return false; return false;
if (getClass() != obj.getClass()) if (href != null ? !href.equals(that.href) : that.href != null)
return false; return false;
BaseResource<?> other = (BaseResource<?>) obj; if (links != null ? !links.equals(that.links) : that.links != null)
if (href == null) {
if (other.href != null)
return false;
} else if (!href.equals(other.href))
return false; return false;
if (type == null) { if (type != null ? !type.equals(that.type) : that.type != null)
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false; return false;
return true; return true;
} }
@Override
public int hashCode() {
int result = type != null ? type.hashCode() : 0;
result = 31 * result + (href != null ? href.hashCode() : 0);
result = 31 * result + (links != null ? links.hashCode() : 0);
result = 31 * result + (actions != null ? actions.hashCode() : 0);
return result;
}
@Override @Override
public String toString() { public String toString() {
return String.format("[%s]",string()); return String.format("[%s]",string());
} }
protected String string() { protected String string() {
return "href="+href+", type="+type; return "href="+href+", type="+type+", links="+links+", actions="+actions;
} }
} }

View File

@ -18,7 +18,9 @@
*/ */
package org.jclouds.tmrk.enterprisecloud.domain.network; package org.jclouds.tmrk.enterprisecloud.domain.network;
import com.google.common.collect.Sets;
import org.jclouds.tmrk.enterprisecloud.domain.Actions; import org.jclouds.tmrk.enterprisecloud.domain.Actions;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
@ -34,17 +36,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
@XmlRootElement(name="AssignedIpAddresses") @XmlRootElement(name="AssignedIpAddresses")
public class AssignedIpAddresses extends BaseResource<AssignedIpAddresses> { public class AssignedIpAddresses extends BaseResource<AssignedIpAddresses> {
//TODO links
@XmlElement(name = "Actions", required = true)
private Actions actions = Actions.builder().build();
@XmlElement(name = "Networks", required = true) @XmlElement(name = "Networks", required = true)
private DeviceNetworks networks = new DeviceNetworks(); private DeviceNetworks networks = new DeviceNetworks();
public AssignedIpAddresses(URI href, String type, Actions actions, DeviceNetworks networks) { public AssignedIpAddresses(URI href, String type, Actions actions, DeviceNetworks networks) {
super(href, type); super(href, type, Sets.<Link>newIdentityHashSet(), actions.getActions());
checkNotNull(actions,"actions");
checkNotNull(networks,"networks"); checkNotNull(networks,"networks");
} }
@ -52,10 +48,6 @@ public class AssignedIpAddresses extends BaseResource<AssignedIpAddresses> {
//For JAXB //For JAXB
} }
public Actions getActions() {
return actions;
}
public DeviceNetworks getNetworks() { public DeviceNetworks getNetworks() {
return networks; return networks;
} }
@ -68,7 +60,6 @@ public class AssignedIpAddresses extends BaseResource<AssignedIpAddresses> {
AssignedIpAddresses that = (AssignedIpAddresses) o; AssignedIpAddresses that = (AssignedIpAddresses) o;
if (!actions.equals(that.actions)) return false;
if (!networks.equals(that.networks)) return false; if (!networks.equals(that.networks)) return false;
return true; return true;
@ -77,14 +68,13 @@ public class AssignedIpAddresses extends BaseResource<AssignedIpAddresses> {
@Override @Override
public int hashCode() { public int hashCode() {
int result = super.hashCode(); int result = super.hashCode();
result = 31 * result + actions.hashCode();
result = 31 * result + networks.hashCode(); result = 31 * result + networks.hashCode();
return result; return result;
} }
@Override @Override
public String string() { public String string() {
return super.string()+", actions="+actions+", networks="+networks; return super.string()+", networks="+networks;
} }
} }

View File

@ -32,7 +32,7 @@ public class DeviceNetwork extends BaseNamedResource<DeviceNetwork> {
@XmlElement(name = "IpAddresses") @XmlElement(name = "IpAddresses")
private DeviceIps ipAddresses = new DeviceIps(); private DeviceIps ipAddresses = new DeviceIps();
protected DeviceNetwork() { private DeviceNetwork() {
//For JAXB //For JAXB
} }

View File

@ -19,6 +19,8 @@
package org.jclouds.tmrk.enterprisecloud.domain.network; package org.jclouds.tmrk.enterprisecloud.domain.network;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
@ -26,6 +28,8 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlEnumValue;
import java.net.URI; import java.net.URI;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.CaseFormat.LOWER_CAMEL; import static com.google.common.base.CaseFormat.LOWER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
@ -82,7 +86,7 @@ public class NetworkReference extends BaseNamedResource<NetworkReference> {
@Override @Override
public NetworkReference build() { public NetworkReference build() {
return new NetworkReference(href, type, name, networkType); return new NetworkReference(href, type, links, actions, name, networkType);
} }
public Builder fromNetworkReference(NetworkReference in) { public Builder fromNetworkReference(NetworkReference in) {
@ -128,17 +132,41 @@ public class NetworkReference extends BaseNamedResource<NetworkReference> {
public Builder type(String type) { public Builder type(String type) {
return Builder.class.cast(super.type(type)); return Builder.class.cast(super.type(type));
} }
/**
* {@inheritDoc}
*/
@Override
public Builder fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
} }
@XmlElement(name = "NetworkType") @XmlElement(name = "NetworkType")
private NetworkType networkType; private NetworkType networkType;
public NetworkReference(URI href, String type, String name,@Nullable NetworkType networkType) { private NetworkReference(URI href, String type, Set<Link> links, Set<Action> actions, String name,@Nullable NetworkType networkType) {
super(href, type, name); super(href, type, links, actions, name);
this.networkType = networkType; this.networkType = networkType;
} }
protected NetworkReference() { private NetworkReference() {
//For JAXB //For JAXB
} }

View File

@ -18,11 +18,14 @@
*/ */
package org.jclouds.tmrk.enterprisecloud.domain.software; package org.jclouds.tmrk.enterprisecloud.domain.software;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* <xs:complexType name="OperatingSystem"> * <xs:complexType name="OperatingSystem">
@ -53,7 +56,7 @@ public class OperatingSystem extends BaseNamedResource<OperatingSystem> {
*/ */
@Override @Override
public OperatingSystem build() { public OperatingSystem build() {
return new OperatingSystem(href, type, name); return new OperatingSystem(href, type, links, actions, name);
} }
/** /**
@ -96,6 +99,22 @@ public class OperatingSystem extends BaseNamedResource<OperatingSystem> {
return Builder.class.cast(super.type(type)); return Builder.class.cast(super.type(type));
} }
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -106,11 +125,11 @@ public class OperatingSystem extends BaseNamedResource<OperatingSystem> {
} }
public OperatingSystem(URI href, String type, String name) { private OperatingSystem(URI href, String type, Set<Link> links, Set<Action> actions, String name) {
super(href, type, name); super(href, type, links, actions, name);
} }
protected OperatingSystem() { private OperatingSystem() {
//For JAXB //For JAXB
} }
} }

View File

@ -19,10 +19,7 @@
package org.jclouds.tmrk.enterprisecloud.domain.template; package org.jclouds.tmrk.enterprisecloud.domain.template;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.ConfigurationOptionRange; import org.jclouds.tmrk.enterprisecloud.domain.*;
import org.jclouds.tmrk.enterprisecloud.domain.CustomizationOption;
import org.jclouds.tmrk.enterprisecloud.domain.Links;
import org.jclouds.tmrk.enterprisecloud.domain.ResourceCapacityRange;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem; import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem;
@ -30,6 +27,8 @@ import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem;
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 java.net.URI; import java.net.URI;
import java.util.Map;
import java.util.Set;
/** /**
* <xs:complexType name="Template"> * <xs:complexType name="Template">
@ -54,7 +53,6 @@ public class Template extends BaseNamedResource<Template> {
public static class Builder extends BaseNamedResource.Builder<Template> { public static class Builder extends BaseNamedResource.Builder<Template> {
//TODO There are additional fields //TODO There are additional fields
protected Links links;
protected OperatingSystem operatingSystem; protected OperatingSystem operatingSystem;
protected String description; protected String description;
//protected ComputeMatrix computeMatrix; //protected ComputeMatrix computeMatrix;
@ -65,14 +63,6 @@ public class Template extends BaseNamedResource<Template> {
protected CustomizationOption customization; protected CustomizationOption customization;
//protected DeviceLicensedSoftware licensedSoftware; //protected DeviceLicensedSoftware licensedSoftware;
/**
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getLinks
*/
public Builder links(Links links) {
this.links = links;
return this;
}
/** /**
* @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getOperatingSystem * @see org.jclouds.tmrk.enterprisecloud.domain.template.Template#getOperatingSystem
*/ */
@ -131,7 +121,7 @@ public class Template extends BaseNamedResource<Template> {
@Override @Override
public Template build() { public Template build() {
return new Template(href, type, name, links, operatingSystem, description, processor, memory, storage, networkAdapters, customization); return new Template(href, type, links, actions, name, operatingSystem, description, processor, memory, storage, networkAdapters, customization);
} }
public Builder fromTask(Template in) { public Builder fromTask(Template in) {
@ -162,6 +152,22 @@ public class Template extends BaseNamedResource<Template> {
return Builder.class.cast(super.type(type)); return Builder.class.cast(super.type(type));
} }
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -169,10 +175,15 @@ public class Template extends BaseNamedResource<Template> {
public Builder href(URI href) { public Builder href(URI href) {
return Builder.class.cast(super.href(href)); return Builder.class.cast(super.href(href));
} }
}
@XmlElement(name = "Links", required = false) /**
protected Links links; * {@inheritDoc}
*/
@Override
public Builder fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
}
@XmlElement(name = "OperatingSystem", required = false) @XmlElement(name = "OperatingSystem", required = false)
protected OperatingSystem operatingSystem; protected OperatingSystem operatingSystem;
@ -199,11 +210,10 @@ public class Template extends BaseNamedResource<Template> {
//protected DeviceLicensedSoftware licensedSoftware; //protected DeviceLicensedSoftware licensedSoftware;
private Template(URI href, String type, String name, @Nullable Links links, @Nullable OperatingSystem operatingSystem, @Nullable String description, private Template(URI href, String type, Set<Link> links, Set<Action> actions, String name, @Nullable OperatingSystem operatingSystem, @Nullable String description,
@Nullable ConfigurationOptionRange processor, @Nullable ResourceCapacityRange memory, @Nullable ConfigurationOptionRange processor, @Nullable ResourceCapacityRange memory,
@Nullable TemplateStorage storage, @Nullable int networkAdapters, @Nullable CustomizationOption customization) { @Nullable TemplateStorage storage, @Nullable int networkAdapters, @Nullable CustomizationOption customization) {
super(href, type, name); super(href, type, links, actions, name);
this.links = links;
this.operatingSystem = operatingSystem; this.operatingSystem = operatingSystem;
this.description = description; this.description = description;
this.processor = processor; this.processor = processor;
@ -217,10 +227,6 @@ public class Template extends BaseNamedResource<Template> {
//For JAXB //For JAXB
} }
public Links getLinks() {
return links;
}
public String getDescription() { public String getDescription() {
return description; return description;
} }
@ -262,8 +268,6 @@ public class Template extends BaseNamedResource<Template> {
return false; return false;
if (description != null ? !description.equals(template.description) : template.description != null) if (description != null ? !description.equals(template.description) : template.description != null)
return false; return false;
if (links != null ? !links.equals(template.links) : template.links != null)
return false;
if (memory != null ? !memory.equals(template.memory) : template.memory != null) if (memory != null ? !memory.equals(template.memory) : template.memory != null)
return false; return false;
if (operatingSystem != null ? !operatingSystem.equals(template.operatingSystem) : template.operatingSystem != null) if (operatingSystem != null ? !operatingSystem.equals(template.operatingSystem) : template.operatingSystem != null)
@ -279,7 +283,6 @@ public class Template extends BaseNamedResource<Template> {
@Override @Override
public int hashCode() { public int hashCode() {
int result = super.hashCode(); int result = super.hashCode();
result = 31 * result + (links != null ? links.hashCode() : 0);
result = 31 * result + (operatingSystem != null ? operatingSystem.hashCode() : 0); result = 31 * result + (operatingSystem != null ? operatingSystem.hashCode() : 0);
result = 31 * result + (description != null ? description.hashCode() : 0); result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + (processor != null ? processor.hashCode() : 0); result = 31 * result + (processor != null ? processor.hashCode() : 0);
@ -292,7 +295,7 @@ public class Template extends BaseNamedResource<Template> {
@Override @Override
public String string() { public String string() {
return super.string()+", links="+ links+", operatingSystem="+ operatingSystem+ return super.string()+", operatingSystem="+ operatingSystem+
", description="+ description+", processor="+ processor+ ", description="+ description+", processor="+ processor+
", memory="+ memory+", storage="+ storage+ ", memory="+ memory+", storage="+ storage+
", networkAdapters="+ networkAdapters+", customization="+ customization; ", networkAdapters="+ networkAdapters+", customization="+ customization;

View File

@ -20,6 +20,7 @@ package org.jclouds.tmrk.enterprisecloud.domain.template;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import java.util.Set; import java.util.Set;
@ -44,12 +45,12 @@ public class TemplateOperatingSystem {
public static class Builder { public static class Builder {
private String name; private String name;
private Set<TemplateReference> templates = Sets.newLinkedHashSet(); private Set<NamedResource> templates = Sets.newLinkedHashSet();
/** /**
* @see TemplateOperatingSystem#getTemplates * @see TemplateOperatingSystem#getTemplates
*/ */
public Builder templates(Set<TemplateReference> templates) { public Builder templates(Set<NamedResource> templates) {
this.templates = Sets.newLinkedHashSet(checkNotNull(templates, "templates")); this.templates = Sets.newLinkedHashSet(checkNotNull(templates, "templates"));
return this; return this;
} }
@ -77,7 +78,7 @@ public class TemplateOperatingSystem {
@XmlElement(name = "Templates", required = false) @XmlElement(name = "Templates", required = false)
private TemplateReferences templates = TemplateReferences.builder().build(); private TemplateReferences templates = TemplateReferences.builder().build();
private TemplateOperatingSystem(@Nullable String name, Set<TemplateReference> templates) { private TemplateOperatingSystem(@Nullable String name, Set<NamedResource> templates) {
this.name = name; this.name = name;
this.templates = TemplateReferences.builder().templateReferences(checkNotNull(templates,"templates")).build(); this.templates = TemplateReferences.builder().templateReferences(checkNotNull(templates,"templates")).build();
} }
@ -91,7 +92,7 @@ public class TemplateOperatingSystem {
return name; return name;
} }
public Set<TemplateReference> getTemplates() { public Set<NamedResource> getTemplates() {
return templates.getTemplateReferences(); return templates.getTemplateReferences();
} }

View File

@ -1,30 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.tmrk.enterprisecloud.domain.template;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
/**
* @author Jason King
*/
public class TemplateReference extends BaseNamedResource<TemplateReference> {
public TemplateReference() {
//For JAXB
}
}

View File

@ -19,6 +19,7 @@
package org.jclouds.tmrk.enterprisecloud.domain.template; package org.jclouds.tmrk.enterprisecloud.domain.template;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import java.util.Collections; import java.util.Collections;
@ -45,17 +46,17 @@ public class TemplateReferences {
public static class Builder { public static class Builder {
private Set<TemplateReference> templateReferences = Sets.newLinkedHashSet(); private Set<NamedResource> templateReferences = Sets.newLinkedHashSet();
/** /**
* @see org.jclouds.tmrk.enterprisecloud.domain.template.TemplateReferences#getTemplateReferences() * @see org.jclouds.tmrk.enterprisecloud.domain.template.TemplateReferences#getTemplateReferences()
*/ */
public Builder templateReferences(Set<TemplateReference> templateReferences) { public Builder templateReferences(Set<NamedResource> templateReferences) {
this.templateReferences = Sets.newLinkedHashSet(checkNotNull(templateReferences, "templateReferences")); this.templateReferences = Sets.newLinkedHashSet(checkNotNull(templateReferences, "templateReferences"));
return this; return this;
} }
public Builder addTemplateReference(TemplateReference templateReference) { public Builder addTemplateReference(NamedResource templateReference) {
templateReferences.add(checkNotNull(templateReference,"templateReference")); templateReferences.add(checkNotNull(templateReference,"templateReference"));
return this; return this;
} }
@ -73,14 +74,14 @@ public class TemplateReferences {
//For JAXB and builder use //For JAXB and builder use
} }
private TemplateReferences(Set<TemplateReference> templateReferences) { private TemplateReferences(Set<NamedResource> templateReferences) {
this.templateReferences = Sets.newLinkedHashSet(templateReferences); this.templateReferences = Sets.newLinkedHashSet(templateReferences);
} }
@XmlElement(name = "Template") @XmlElement(name = "Template")
private Set<TemplateReference> templateReferences = Sets.newLinkedHashSet(); private Set<NamedResource> templateReferences = Sets.newLinkedHashSet();
public Set<TemplateReference> getTemplateReferences() { public Set<NamedResource> getTemplateReferences() {
return Collections.unmodifiableSet(templateReferences); return Collections.unmodifiableSet(templateReferences);
} }

View File

@ -19,8 +19,8 @@
package org.jclouds.tmrk.enterprisecloud.domain.template; package org.jclouds.tmrk.enterprisecloud.domain.template;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.jclouds.tmrk.enterprisecloud.domain.Action;
import org.jclouds.tmrk.enterprisecloud.domain.Link; import org.jclouds.tmrk.enterprisecloud.domain.Link;
import org.jclouds.tmrk.enterprisecloud.domain.Links;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
@ -56,17 +56,8 @@ public class Templates extends BaseResource<Templates> {
} }
public static class Builder extends BaseResource.Builder<Templates> { public static class Builder extends BaseResource.Builder<Templates> {
private Links links = Links.builder().build();
private Set<TemplateFamily> families = Sets.newLinkedHashSet(); private Set<TemplateFamily> families = Sets.newLinkedHashSet();
/**
* @see Templates#getLinks
*/
public Builder links(Set<Link> links) {
this.links = Links.builder().links(checkNotNull(links,"links")).build();
return this;
}
/** /**
* @see Templates#getTemplateFamilies * @see Templates#getTemplateFamilies
*/ */
@ -77,11 +68,11 @@ public class Templates extends BaseResource<Templates> {
@Override @Override
public Templates build() { public Templates build() {
return new Templates(href, type, links, families); return new Templates(href, type, links, actions, families);
} }
public Builder fromTemplates(Templates in) { public Builder fromTemplates(Templates in) {
return fromResource(in).links(in.getLinks()).families(in.getTemplateFamilies()); return fromResource(in).families(in.getTemplateFamilies());
} }
/** /**
@ -108,6 +99,22 @@ public class Templates extends BaseResource<Templates> {
return Builder.class.cast(super.href(href)); return Builder.class.cast(super.href(href));
} }
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -118,15 +125,11 @@ public class Templates extends BaseResource<Templates> {
} }
@XmlElement(name = "Links", required = false)
private Links links = Links.builder().build();
@XmlElement(name = "Families", required = false) @XmlElement(name = "Families", required = false)
private TemplateFamilies families; private TemplateFamilies families;
private Templates(URI href, String type, Links links, Set<TemplateFamily> families) { private Templates(URI href, String type, Set<Link> links, Set<Action> actions, Set<TemplateFamily> families) {
super(href, type); super(href, type, links, actions);
this.links = checkNotNull(links, "links");
this.families = TemplateFamilies.builder().families(families).build(); this.families = TemplateFamilies.builder().families(families).build();
} }
@ -152,8 +155,6 @@ public class Templates extends BaseResource<Templates> {
if (families != null ? !families.equals(templates.families) : templates.families != null) if (families != null ? !families.equals(templates.families) : templates.families != null)
return false; return false;
if (links != null ? !links.equals(templates.links) : templates.links != null)
return false;
return true; return true;
} }
@ -161,13 +162,12 @@ public class Templates extends BaseResource<Templates> {
@Override @Override
public int hashCode() { public int hashCode() {
int result = super.hashCode(); int result = super.hashCode();
result = 31 * result + (links != null ? links.hashCode() : 0);
result = 31 * result + (families != null ? families.hashCode() : 0); result = 31 * result + (families != null ? families.hashCode() : 0);
return result; return result;
} }
@Override @Override
public String string() { public String string() {
return super.string()+", links="+links+", families="+families; return super.string()+", families="+families;
} }
} }

View File

@ -62,8 +62,6 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
public static class Builder extends BaseNamedResource.Builder<VirtualMachine> { public static class Builder extends BaseNamedResource.Builder<VirtualMachine> {
//TODO There are some more fields //TODO There are some more fields
private Links links = Links.builder().build();
private Actions actions = Actions.builder().build();
private Tasks tasks = Tasks.builder().build(); private Tasks tasks = Tasks.builder().build();
private String description; private String description;
private VirtualMachineStatus status; private VirtualMachineStatus status;
@ -77,23 +75,6 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
private HardwareConfiguration hardwareConfiguration; private HardwareConfiguration hardwareConfiguration;
private VirtualMachineIpAddresses ipAddresses = new VirtualMachineIpAddresses(); private VirtualMachineIpAddresses ipAddresses = new VirtualMachineIpAddresses();
/**
* @see VirtualMachine#getLinks
*/
public Builder links(Set<Link> links) {
this.links = Links.builder().links(checkNotNull(links,"links")).build();
return this;
}
/**
* @see VirtualMachine#getActions
*/
public Builder actions(Set<Action> actions) {
checkNotNull(actions,"actions");
this.actions = Actions.builder().actions(actions).build();
return this;
}
/** /**
* @see VirtualMachine#getTasks * @see VirtualMachine#getTasks
*/ */
@ -199,9 +180,7 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
public Builder fromVirtualMachine(VirtualMachine in) { public Builder fromVirtualMachine(VirtualMachine in) {
return fromNamedResource(in) return fromNamedResource(in)
.links(in.getLinks())
.tasks(in.getTasks()) .tasks(in.getTasks())
.actions(in.getActions())
.description(in.getDescription()) .description(in.getDescription())
.layout(in.getLayout()) .layout(in.getLayout())
.status(in.getStatus()) .status(in.getStatus())
@ -246,6 +225,22 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
return Builder.class.cast(super.href(href)); return Builder.class.cast(super.href(href));
} }
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -259,21 +254,17 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
*/ */
@Override @Override
public Builder fromAttributes(Map<String, String> attributes) { public Builder fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes)); super.fromAttributes(attributes);
// TODO Other fields? if (attributes.containsKey("description"))
description(attributes.get("description"));
return this;
} }
} }
@XmlElement(name = "Links", required = true)
private Links links = Links.builder().build();
@XmlElement(name = "Tasks", required = true) @XmlElement(name = "Tasks", required = true)
private Tasks tasks = Tasks.builder().build(); private Tasks tasks = Tasks.builder().build();
@XmlElement(name = "Actions", required = true)
private Actions actions = Actions.builder().build();
@XmlElement(name = "Description", required = true) @XmlElement(name = "Description", required = true)
private String description; private String description;
@ -304,14 +295,12 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
@XmlElement(name = "IpAddresses", required = false) @XmlElement(name = "IpAddresses", required = false)
private VirtualMachineIpAddresses ipAddresses = new VirtualMachineIpAddresses(); private VirtualMachineIpAddresses ipAddresses = new VirtualMachineIpAddresses();
public VirtualMachine(URI href, String type, String name, Tasks tasks, Actions actions, Links links, String description, @Nullable Layout layout, private VirtualMachine(URI href, String type, String name, Tasks tasks, Set<Action> actions, Set<Link> links, String description, @Nullable Layout layout,
VirtualMachineStatus status, boolean poweredOn, @Nullable ToolsStatus toolsStatus, @Nullable VirtualMachineMediaStatus mediaStatus, boolean customizationPending, VirtualMachineStatus status, boolean poweredOn, @Nullable ToolsStatus toolsStatus, @Nullable VirtualMachineMediaStatus mediaStatus, boolean customizationPending,
@Nullable OperatingSystem operatingSystem, @Nullable HardwareConfiguration hardwareConfiguration, @Nullable VirtualMachineIpAddresses ipAddresses) { @Nullable OperatingSystem operatingSystem, @Nullable HardwareConfiguration hardwareConfiguration, @Nullable VirtualMachineIpAddresses ipAddresses) {
super(href, type, name); super(href, type, links, actions, name);
this.description = checkNotNull(description, "description"); this.description = checkNotNull(description, "description");
this.links = checkNotNull(links, "links");
this.tasks = checkNotNull(tasks, "tasks"); this.tasks = checkNotNull(tasks, "tasks");
this.actions = checkNotNull(actions, "actions");
this.status = checkNotNull(status, "status"); this.status = checkNotNull(status, "status");
this.ipAddresses = checkNotNull(ipAddresses, "ipAddresses"); this.ipAddresses = checkNotNull(ipAddresses, "ipAddresses");
@ -324,29 +313,20 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
this.hardwareConfiguation = hardwareConfiguration; this.hardwareConfiguation = hardwareConfiguration;
} }
protected VirtualMachine() { private VirtualMachine() {
//For JAXB //For JAXB
} }
/**
public Set<Link> getLinks() { * refers to tasks regarding the virtual machine.
return Collections.unmodifiableSet(links.getLinks()); * Only the most recent tasks, up to twenty, are returned.
} * Use the href to retrieve the complete list of tasks.
* @return most recent tasks
/** */
* refers to tasks regarding the virtual machine.
* Only the most recent tasks, up to twenty, are returned.
* Use the href to retrieve the complete list of tasks.
* @return most recent tasks
*/
public Set<Task> getTasks() { public Set<Task> getTasks() {
return Collections.unmodifiableSet(tasks.getTasks()); return Collections.unmodifiableSet(tasks.getTasks());
} }
public Set<Action> getActions() {
return Collections.unmodifiableSet(actions.getActions());
}
public String getDescription() { public String getDescription() {
return description; return description;
} }
@ -409,7 +389,6 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
if (customizationPending != that.customizationPending) return false; if (customizationPending != that.customizationPending) return false;
if (poweredOn != that.poweredOn) return false; if (poweredOn != that.poweredOn) return false;
if (!actions.equals(that.actions)) return false;
if (description != null ? !description.equals(that.description) : that.description != null) if (description != null ? !description.equals(that.description) : that.description != null)
return false; return false;
if (hardwareConfiguation != null ? !hardwareConfiguation.equals(that.hardwareConfiguation) : that.hardwareConfiguation != null) if (hardwareConfiguation != null ? !hardwareConfiguation.equals(that.hardwareConfiguation) : that.hardwareConfiguation != null)
@ -417,7 +396,6 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
if (!ipAddresses.equals(that.ipAddresses)) return false; if (!ipAddresses.equals(that.ipAddresses)) return false;
if (layout != null ? !layout.equals(that.layout) : that.layout != null) if (layout != null ? !layout.equals(that.layout) : that.layout != null)
return false; return false;
if (!links.equals(that.links)) return false;
if (mediaStatus != that.mediaStatus) return false; if (mediaStatus != that.mediaStatus) return false;
if (operatingSystem != null ? !operatingSystem.equals(that.operatingSystem) : that.operatingSystem != null) if (operatingSystem != null ? !operatingSystem.equals(that.operatingSystem) : that.operatingSystem != null)
return false; return false;
@ -431,9 +409,7 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
@Override @Override
public int hashCode() { public int hashCode() {
int result = super.hashCode(); int result = super.hashCode();
result = 31 * result + links.hashCode();
result = 31 * result + tasks.hashCode(); result = 31 * result + tasks.hashCode();
result = 31 * result + actions.hashCode();
result = 31 * result + (description != null ? description.hashCode() : 0); result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + (layout != null ? layout.hashCode() : 0); result = 31 * result + (layout != null ? layout.hashCode() : 0);
result = 31 * result + (status != null ? status.hashCode() : 0); result = 31 * result + (status != null ? status.hashCode() : 0);
@ -449,7 +425,7 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
@Override @Override
public String string() { public String string() {
return super.string()+", links="+links+", tasks="+tasks+", actions="+actions+", description="+description+", layout="+layout+ return super.string()+", tasks="+tasks+", description="+description+", layout="+layout+
", status="+status+", poweredOn="+poweredOn+", toolsStatus="+toolsStatus+", mediaStatus="+mediaStatus+ ", status="+status+", poweredOn="+poweredOn+", toolsStatus="+toolsStatus+", mediaStatus="+mediaStatus+
", customizationPending="+customizationPending+", operatingSystem="+operatingSystem+", hardwareConfiguration="+hardwareConfiguation+ ", customizationPending="+customizationPending+", operatingSystem="+operatingSystem+", hardwareConfiguration="+hardwareConfiguation+
", ipAddresses="+ipAddresses; ", ipAddresses="+ipAddresses;

View File

@ -26,6 +26,8 @@ import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
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 java.net.URI; import java.net.URI;
import java.util.Map;
import java.util.Set;
/** /**
* <xs:complexType name="VirtualMachineConfigurationOptions"> * <xs:complexType name="VirtualMachineConfigurationOptions">
@ -99,7 +101,7 @@ public class VirtualMachineConfigurationOptions extends BaseResource<VirtualMach
@Override @Override
public VirtualMachineConfigurationOptions build() { public VirtualMachineConfigurationOptions build() {
return new VirtualMachineConfigurationOptions(href, type, processor, memory, disk, networkAdapter, customization); return new VirtualMachineConfigurationOptions(href, type, links, actions, processor, memory, disk, networkAdapter, customization);
} }
public Builder fromVirtualMachineConfigurationOptions(VirtualMachineConfigurationOptions in) { public Builder fromVirtualMachineConfigurationOptions(VirtualMachineConfigurationOptions in) {
@ -134,6 +136,29 @@ public class VirtualMachineConfigurationOptions extends BaseResource<VirtualMach
return Builder.class.cast(super.href(href)); return Builder.class.cast(super.href(href));
} }
/**
* {@inheritDoc}
*/
@Override
public Builder fromAttributes(Map<String, String> attributes) {
return Builder.class.cast(super.fromAttributes(attributes));
}
/**
* {@inheritDoc}
*/
@Override
public Builder links(Set<Link> links) {
return Builder.class.cast(super.links(links));
}
/**
* {@inheritDoc}
*/
@Override
public Builder actions(Set<Action> actions) {
return Builder.class.cast(super.actions(actions));
}
} }
@XmlElement(name = "Processor", required = false) @XmlElement(name = "Processor", required = false)
@ -151,9 +176,9 @@ public class VirtualMachineConfigurationOptions extends BaseResource<VirtualMach
@XmlElement(name = "Customization", required = false) @XmlElement(name = "Customization", required = false)
private CustomizationOption customization; private CustomizationOption customization;
private VirtualMachineConfigurationOptions(URI href, String type, @Nullable ConfigurationOptionRange processor, @Nullable ResourceCapacityRange memory, private VirtualMachineConfigurationOptions(URI href, String type, Set<Link> links, Set<Action> actions, @Nullable ConfigurationOptionRange processor, @Nullable ResourceCapacityRange memory,
@Nullable DiskConfigurationOption disk, @Nullable ConfigurationOptionRange networkAdapter, @Nullable CustomizationOption customization) { @Nullable DiskConfigurationOption disk, @Nullable ConfigurationOptionRange networkAdapter, @Nullable CustomizationOption customization) {
super(href, type); super(href, type, links, actions);
this.processor = processor; this.processor = processor;
this.memory = memory; this.memory = memory;
this.disk = disk; this.disk = disk;

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.tmrk.enterprisecloud.features; package org.jclouds.tmrk.enterprisecloud.features;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.template.*; import org.jclouds.tmrk.enterprisecloud.domain.template.*;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -46,7 +47,7 @@ public class TemplateClientLiveTest extends BaseTerremarkEnterpriseCloudClientLi
for(TemplateFamily family: templates.getTemplateFamilies()) { for(TemplateFamily family: templates.getTemplateFamilies()) {
for(TemplateCategory category: family.getTemplateCategories()) { for(TemplateCategory category: family.getTemplateCategories()) {
for(TemplateOperatingSystem os: category.getTemplateOperatingSystems()) { for(TemplateOperatingSystem os: category.getTemplateOperatingSystems()) {
for(TemplateReference templateReference: os.getTemplates()) { for(NamedResource templateReference: os.getTemplates()) {
testTemplate(templateReference); testTemplate(templateReference);
} }
} }
@ -54,7 +55,7 @@ public class TemplateClientLiveTest extends BaseTerremarkEnterpriseCloudClientLi
} }
} }
private void testTemplate(TemplateReference templateReference) { private void testTemplate(NamedResource templateReference) {
Template template = client.getTemplate(templateReference.getHref()); Template template = client.getTemplate(templateReference.getHref());
assertNotNull(template); assertNotNull(template);
assertNotNull(template.getDescription()); assertNotNull(template.getDescription());

View File

@ -101,7 +101,7 @@ public class TemplateJAXBParsingTest extends BaseRestClientTest {
InputStream is = getClass().getResourceAsStream("/template.xml"); InputStream is = getClass().getResourceAsStream("/template.xml");
Template template = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is))); Template template = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
assertLinks(template.getLinks().getLinks()); assertLinks(template.getLinks());
assertOperatingSystem(template.getOperatingSystem()); assertOperatingSystem(template.getOperatingSystem());
assertEquals(template.getDescription(),""); assertEquals(template.getDescription(),"");
assertProcessor(template.getProcessor()); assertProcessor(template.getProcessor());