View Javadoc

1   /**
2    *
3    * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4    *
5    * ====================================================================
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   * ====================================================================
18   */
19  package org.jclouds.savvis.vpdc.domain;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  import java.net.URI;
24  import java.util.Set;
25  
26  import javax.annotation.Nullable;
27  
28  import com.google.common.collect.ImmutableSet;
29  import com.google.common.collect.Sets;
30  
31  /**
32   * A cloud can contain one or more Organizations. There are two types of Organizations, hard-walled
33   * and soft-walled.
34   * <ul>
35   * <li>A hard-walled Organization provides a secure environment for a single tenant of a
36   * multi-tenant cloud.All resources in a hard-walled Organization are isolated from other
37   * Organizations, hard- or soft-walled,in the cloud.</li>
38   * <li>A soft-walled Organization supports access, by users who have appropriate privileges, to
39   * other soft-walled Organizations in a cloud. Soft-walled Organizations have boundaries similar to
40   * those that separate departments of a corporate entity. In such environments, the Organization
41   * controls the resources owned by a single department. Most users are restricted to the resources
42   * available in a single Organization but a few might have privileges in other Organizations, if
43   * allowed by the administrators of those Organizations.</li>
44   * </ul>
45   * 
46   * @author Adrian Cole
47   */
48  public class Org extends ResourceImpl {
49     public static Builder builder() {
50        return new Builder();
51     }
52  
53     public static class Builder extends ResourceImpl.Builder {
54        private String description;
55        private Set<Link> vDCs = Sets.newLinkedHashSet();
56        private Set<Link> images = Sets.newLinkedHashSet();
57  
58        public Builder description(String description) {
59           this.description = description;
60           return this;
61        }
62  
63        public Builder vDC(Link vDC) {
64           this.vDCs.add(checkNotNull(vDC, "vDC"));
65           return this;
66        }
67  
68        public Builder vDCs(Set<Link> vDCs) {
69           this.vDCs.addAll(checkNotNull(vDCs, "vDCs"));
70           return this;
71        }
72  
73        public Builder image(Link image) {
74           this.images.add(checkNotNull(image, "image"));
75           return this;
76        }
77  
78        public Builder images(Set<Link> images) {
79           this.images.addAll(checkNotNull(images, "images"));
80           return this;
81        }
82  
83        @Override
84        public Org build() {
85           return new Org(id, name, type, href, description, vDCs, images);
86        }
87  
88        public static Builder fromOrg(Org in) {
89           return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref())
90                 .description(in.getDescription()).images(in.getImages()).vDCs(in.getVDCs());
91        }
92  
93        @Override
94        public Builder id(String id) {
95           return Builder.class.cast(super.id(id));
96        }
97  
98        @Override
99        public Builder name(String name) {
100          return Builder.class.cast(super.name(name));
101       }
102 
103       @Override
104       public Builder type(String type) {
105          return Builder.class.cast(super.type(type));
106       }
107 
108       @Override
109       public Builder href(URI href) {
110          return Builder.class.cast(super.href(href));
111       }
112 
113    }
114 
115    @Nullable
116    private final String description;
117    private final Set<Link> vDCs;
118    private final Set<Link> images;
119 
120    public Org(String id, String name, String type, URI href, @Nullable String description, Set<Link> vDCs,
121          Set<Link> images) {
122       super(id, name, type, href);
123       this.description = description;
124       this.vDCs = ImmutableSet.copyOf(checkNotNull(vDCs, "vDCs"));
125       this.images = ImmutableSet.copyOf(checkNotNull(images, "images"));
126    }
127 
128    /**
129     * {@inheritDoc}
130     */
131    public String getName() {
132       return name;
133    }
134 
135    /**
136     * {@inheritDoc}
137     */
138    public String getDescription() {
139       return description;
140    }
141 
142    /**
143     * {@inheritDoc}
144     */
145    public Set<Link> getVDCs() {
146       return vDCs;
147    }
148 
149    /**
150     * {@inheritDoc}
151     */
152    public Set<Link> getImages() {
153       return images;
154    }
155 
156    @Override
157    public Builder toBuilder() {
158       return Builder.fromOrg(this);
159    }
160 
161    @Override
162    public String toString() {
163       return "[id=" + id + ", href=" + href + ", name=" + name + ", type=" + type + ", description=" + description
164             + ", vDCs=" + vDCs + ", images=" + images + "]";
165    }
166 
167 }