Added initial Task and associated domain objects

This commit is contained in:
Andrew Donald Kennedy 2012-02-07 11:08:04 +00:00 committed by danikov
parent 4e01fa3369
commit 8828daf89b
3 changed files with 603 additions and 0 deletions

View File

@ -0,0 +1,370 @@
/**
* 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.*;
import static com.google.common.base.Preconditions.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*;
import java.net.URI;
import java.util.Date;
import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute;
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;
import com.google.common.collect.Sets;
/**
* Represents an asynchronous or long-running task in the vCloud environment.
*
* <pre>
* &lt;xs:complexType name="TaskType"&gt;
* </pre>
*
* @author grkvlt@apache.org
*/
@XmlRootElement(namespace = NS, name = "Task")
public class Task extends EntityType<Task> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
@Override
public Builder toBuilder() {
return new Builder().fromTask(this);
}
public static class Builder extends EntityType.Builder<Task> {
private Error error;
private Org org;
private Integer progress;
private String status;
private String operation;
private String operationName;
private Date startTime;
private Date endTime;
private Date expiryTime;
/**
* @see Task#getError()
*/
public Builder error(Error error) {
this.error = error;
return this;
}
/**
* @see Task#getOrg()
*/
public Builder org(Org org) {
this.org = org;
return this;
}
/**
* @see Task#getProgress()
*/
public Builder progress(Integer progress) {
this.progress = progress;
return this;
}
/**
* @see Task#getStatus()
*/
public Builder status(String status) {
this.status = status;
return this;
}
/**
* @see Task#getOperation()
*/
public Builder operation(String operation) {
this.operation = operation;
return this;
}
/**
* @see Task#getOperationName()
*/
public Builder operationName(String operationName) {
this.operationName = operationName;
return this;
}
/**
* @see Task#getStartTime()
*/
public Builder startTime(Date startTime) {
this.startTime = startTime;
return this;
}
/**
* @see Task#getEndTime()
*/
public Builder endTime(Date endTime) {
this.endTime = endTime;
return this;
}
/**
* @see Task#getExpiryTime()
*/
public Builder expiryTime(Date expiryTime) {
this.expiryTime = expiryTime;
return this;
}
@Override
public Task build() {
Task task = new Task(href, name);
task.setError(error);
task.setOrg(org);
task.setProgress(progress);
task.setStatus(status);
task.setOperation(operation);
task.setOperationName(operationName);
task.setStartTime(startTime);
task.setEndTime(endTime);
task.setExpiryTime(expiryTime);
return task;
}
/**
* @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#getTasks()
*/
@Override
public Builder tasks(TaskList tasks) {
this.tasks = tasks;
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 ReferenceType#getLinks()
*/
@Override
public Builder links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links"));
return this;
}
/**
* @see ReferenceType#getLinks()
*/
@Override
public Builder link(Link link) {
this.links.add(checkNotNull(link, "link"));
return this;
}
@Override
public Builder fromEntity(EntityType<Task> in) {
return Builder.class.cast(super.fromEntity(in));
}
public Builder fromTask(Task in) {
return fromEntity(in).error(in.getError()).org(in.getOrg()).progress(in.getProgress()).status(in.getStatus())
.operation(in.getOperation()).operationName(in.getOperationName());
}
}
private Task() {
// For JAXB and builder use
}
private Task(URI href, String name) {
super(href, name);
}
@XmlElement(namespace = NS, name = "Error")
private Error error;
@XmlElement(namespace = NS, name = "Organization")
private Org org;
@XmlElement(namespace = NS, name = "Progress")
private Integer progress;
@XmlElement(namespace = NS, name = "Owner")
private Entity owner;
@XmlElement(namespace = NS, name = "User")
private Entity user;
@XmlElement(namespace = NS, name = "Params")
private Object params;
@XmlAttribute(namespace = NS, name = "status")
private String status;
@XmlAttribute(namespace = NS, name = "operation")
private String operation;
@XmlAttribute(namespace = NS, name = "operationName")
private String operationName;
@XmlAttribute(namespace = NS, name = "startTime")
private Date startTime;
@XmlAttribute(namespace = NS, name = "endTime")
private Date endTime;
@XmlAttribute(namespace = NS, name = "expiryTime")
private Date expiryTime;
public Error getError() {
return error;
}
public void setError(Error error) {
this.error = error;
}
public Org getOrg() {
return org;
}
public void setOrg(Org org) {
this.org = org;
}
public Integer getProgress() {
return progress;
}
public void setProgress(Integer progress) {
this.progress = progress;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
public String getOperationName() {
return operationName;
}
public void setOperationName(String operationName) {
this.operationName = operationName;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public Date getExpiryTime() {
return expiryTime;
}
public void setExpiryTime(Date expiryTime) {
this.expiryTime = expiryTime;
}
@Override
public boolean equals(Object o) {
if (!super.equals(o))
return false;
Task that = Task.class.cast(o);
return super.equals(that) && equal(this.error, that.error) && equal(this.org, that.org) &&
equal(this.progress, that.progress) && equal(this.status, that.status) &&
equal(this.operation, that.operation) && equal(this.operationName, that.operationName) &&
equal(this.startTime, that.startTime) && equal(this.endTime, that.endTime) &&
equal(this.expiryTime, that.expiryTime);
}
@Override
public int hashCode() {
return super.hashCode() + Objects.hashCode(error, org, progress, status, operation, operationName,
startTime, endTime, expiryTime);
}
@Override
public ToStringHelper string() {
return super.string().add("error", error).add("org", org).add("progress", progress).add("status", status)
.add("operation", operation).add("operationName", operationName).add("startTime", startTime)
.add("endTime", endTime).add("expiryTime", expiryTime);
}
}

View File

@ -0,0 +1,117 @@
/**
* 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.task/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.*;
import static com.google.common.base.Preconditions.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*;
import java.util.Collection;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* A list of tasks.
*
* @author Adrian Cole
*/
@XmlRootElement(namespace = NS, name = "TaskList")
@XmlAccessorType(XmlAccessType.FIELD)
public class TaskList {
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder();
}
public static class Builder {
protected Set<Task> tasks = Sets.newLinkedHashSet();
/**
* @see TaskList#getTasks()
*/
public Builder tasks(Collection<Task> tasks) {
this.tasks = Sets.newLinkedHashSet(checkNotNull(tasks, "tasks"));
return this;
}
/**
* @see TaskList#getTasks()
*/
public Builder task(Task task) {
this.tasks.add(checkNotNull(task, "task"));
return this;
}
public TaskList build() {
return new TaskList(tasks);
}
public Builder fromTaskList(TaskList in) {
return tasks(in.getTasks());
}
}
protected TaskList() {
// For JAXB and builder use
}
protected TaskList(Set<Task> tasks) {
this.tasks = ImmutableSet.copyOf(tasks);
}
@XmlElement(namespace = NS, name = "Task")
private Set<Task> tasks = Sets.newLinkedHashSet();
public Set<Task> getTasks() {
return ImmutableSet.copyOf(tasks);
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
TaskList that = TaskList.class.cast(o);
return equal(this.tasks, that.tasks);
}
@Override
public int hashCode() {
return Objects.hashCode(tasks);
}
@Override
public String toString() {
return Objects.toStringHelper("").add("tasks", tasks).toString();
}
}

View File

@ -0,0 +1,116 @@
/**
* 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.*;
import static com.google.common.base.Preconditions.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*;
import java.util.Collection;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
* @author grkvlt@apache.org
*/
@XmlRootElement(namespace = NS, name = "TasksInProgress")
@XmlAccessorType(XmlAccessType.FIELD)
public class TasksInProgress {
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder();
}
public static class Builder {
protected Set<Task> tasks = Sets.newLinkedHashSet();
/**
* @see TasksInProgress#getTasks()
*/
public Builder tasks(Collection<Task> tasks) {
this.tasks = Sets.newLinkedHashSet(checkNotNull(tasks, "tasks"));
return this;
}
/**
* @see TasksInProgress#getTasks()
*/
public Builder task(Task task) {
this.tasks.add(checkNotNull(task, "task"));
return this;
}
public TaskList build() {
return new TaskList(tasks);
}
public Builder fromTaskList(TaskList in) {
return tasks(in.getTasks());
}
}
protected TasksInProgress() {
// For JAXB and builder use
}
protected TasksInProgress(Collection<Task> tasks) {
this.tasks = ImmutableSet.copyOf(tasks);
}
@XmlElement(namespace = NS, name = "Task")
private Set<Task> tasks = Sets.newLinkedHashSet();
public Set<Task> getTasks() {
return ImmutableSet.copyOf(tasks);
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
TasksInProgress that = TasksInProgress.class.cast(o);
return equal(this.tasks, that.tasks);
}
@Override
public int hashCode() {
return Objects.hashCode(tasks);
}
@Override
public String toString() {
return Objects.toStringHelper("").add("tasks", tasks).toString();
}
}