1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
3 | * contributor license agreements. See the NOTICE file distributed with |
4 | * this work for additional information regarding copyright ownership. |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
6 | * (the "License"); you may not use this file except in compliance with |
7 | * the License. You may obtain a copy of the License at |
8 | * |
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | * |
11 | * Unless required by applicable law or agreed to in writing, software |
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | * See the License for the specific language governing permissions and |
15 | * limitations under the License. |
16 | */ |
17 | package org.jclouds.glesys.domain; |
18 | |
19 | import static com.google.common.base.Preconditions.checkNotNull; |
20 | |
21 | import java.beans.ConstructorProperties; |
22 | import java.util.Date; |
23 | |
24 | import org.jclouds.javax.annotation.Nullable; |
25 | |
26 | import com.google.common.base.Objects; |
27 | import com.google.common.base.Objects.ToStringHelper; |
28 | |
29 | /** |
30 | * Domain data for a Glesys account. |
31 | * |
32 | * @author Adam Lowe |
33 | * @see <a href= "https://customer.glesys.com/api.php?a=doc#domain_list" /> |
34 | */ |
35 | public class Domain { |
36 | |
37 | public static Builder<?> builder() { |
38 | return new ConcreteBuilder(); |
39 | } |
40 | |
41 | public Builder<?> toBuilder() { |
42 | return new ConcreteBuilder().fromDomain(this); |
43 | } |
44 | |
45 | public abstract static class Builder<T extends Builder<T>> { |
46 | protected abstract T self(); |
47 | |
48 | protected String domainName; |
49 | protected Date createTime; |
50 | protected int recordCount; |
51 | protected boolean useGlesysNameServer; |
52 | protected String primaryNameServer; |
53 | protected String responsiblePerson; |
54 | protected int ttl; |
55 | protected int refresh; |
56 | protected int retry; |
57 | protected int expire; |
58 | protected int minimum; |
59 | |
60 | /** |
61 | * @see Domain#getName() |
62 | */ |
63 | public T domainName(String domainName) { |
64 | this.domainName = checkNotNull(domainName, "domainName"); |
65 | return self(); |
66 | } |
67 | |
68 | /** |
69 | * @see Domain#getCreateTime() |
70 | */ |
71 | public T createTime(Date createTime) { |
72 | this.createTime = createTime; |
73 | return self(); |
74 | } |
75 | |
76 | /** |
77 | * @see Domain#getRecordCount() |
78 | */ |
79 | public T recordCount(int recordCount) { |
80 | this.recordCount = recordCount; |
81 | return self(); |
82 | } |
83 | |
84 | /** |
85 | * @see Domain#isUseGlesysNameServer() |
86 | */ |
87 | public T useGlesysNameServer(boolean useGlesysNameServer) { |
88 | this.useGlesysNameServer = useGlesysNameServer; |
89 | return self(); |
90 | } |
91 | |
92 | /** |
93 | * @see Domain#getPrimaryNameServer() |
94 | */ |
95 | public T primaryNameServer(String primaryNameServer) { |
96 | this.primaryNameServer = primaryNameServer; |
97 | return self(); |
98 | } |
99 | |
100 | /** |
101 | * @see Domain#getResponsiblePerson() |
102 | */ |
103 | public T responsiblePerson(String responsiblePerson) { |
104 | this.responsiblePerson = responsiblePerson; |
105 | return self(); |
106 | } |
107 | |
108 | /** |
109 | * @see Domain#getTtl() |
110 | */ |
111 | public T ttl(int ttl) { |
112 | this.ttl = ttl; |
113 | return self(); |
114 | } |
115 | |
116 | /** |
117 | * @see Domain#getRefresh() |
118 | */ |
119 | public T refresh(int refresh) { |
120 | this.refresh = refresh; |
121 | return self(); |
122 | } |
123 | |
124 | /** |
125 | * @see Domain#getRetry() |
126 | */ |
127 | public T retry(int retry) { |
128 | this.retry = retry; |
129 | return self(); |
130 | } |
131 | |
132 | /** |
133 | * @see Domain#getExpire() |
134 | */ |
135 | public T expire(int expire) { |
136 | this.expire = expire; |
137 | return self(); |
138 | } |
139 | |
140 | /** |
141 | * @see Domain#getMinimum() |
142 | */ |
143 | public T minimum(int minimum) { |
144 | this.minimum = minimum; |
145 | return self(); |
146 | } |
147 | |
148 | public Domain build() { |
149 | return new Domain(domainName, createTime, recordCount, new GleSYSBoolean(useGlesysNameServer), primaryNameServer, responsiblePerson, ttl, refresh, retry, expire, minimum); |
150 | } |
151 | |
152 | public T fromDomain(Domain in) { |
153 | return this.domainName(in.getName()) |
154 | .createTime(in.getCreateTime()) |
155 | .recordCount(in.getRecordCount()) |
156 | .useGlesysNameServer(in.isUseGlesysNameServer()) |
157 | .primaryNameServer(in.getPrimaryNameServer()) |
158 | .responsiblePerson(in.getResponsiblePerson()) |
159 | .ttl(in.getTtl()) |
160 | .refresh(in.getRefresh()) |
161 | .retry(in.getRetry()) |
162 | .expire(in.getExpire()); |
163 | } |
164 | } |
165 | |
166 | private static class ConcreteBuilder extends Builder<ConcreteBuilder> { |
167 | @Override |
168 | protected ConcreteBuilder self() { |
169 | return this; |
170 | } |
171 | } |
172 | |
173 | private final String domainName; |
174 | private final Date createTime; |
175 | private final int recordCount; |
176 | private final boolean useGlesysNameServer; |
177 | private final String primaryNameServer; |
178 | private final String responsiblePerson; |
179 | private final int ttl; |
180 | private final int refresh; |
181 | private final int retry; |
182 | private final int expire; |
183 | private final int minimum; |
184 | |
185 | @ConstructorProperties({ |
186 | "domainname", "createtime", "recordcount", "usingglesysnameserver", "primarynameserver", "responsibleperson", |
187 | "ttl", "refresh", "retry", "expire", "minimum" |
188 | }) |
189 | protected Domain(String domainName, @Nullable Date createTime, int recordCount, GleSYSBoolean useGlesysNameServer, |
190 | @Nullable String primaryNameServer, @Nullable String responsiblePerson, |
191 | int ttl, int refresh, int retry, int expire, int minimum) { |
192 | this.domainName = checkNotNull(domainName, "domainName"); |
193 | this.createTime = createTime; |
194 | this.recordCount = recordCount; |
195 | this.useGlesysNameServer = checkNotNull(useGlesysNameServer, "useGlesysNameServer").getValue(); |
196 | this.primaryNameServer = primaryNameServer; |
197 | this.responsiblePerson = responsiblePerson; |
198 | this.ttl = ttl; |
199 | this.refresh = refresh; |
200 | this.retry = retry; |
201 | this.expire = expire; |
202 | this.minimum = minimum; |
203 | } |
204 | |
205 | /** |
206 | * @return the domain name, ex. "jclouds.org" |
207 | */ |
208 | public String getName() { |
209 | return this.domainName; |
210 | } |
211 | |
212 | /** |
213 | * @return the date the domain was registered with GleSYS |
214 | */ |
215 | public Date getCreateTime() { |
216 | return this.createTime; |
217 | } |
218 | |
219 | /** |
220 | * @return the number of DNS records for this domain |
221 | */ |
222 | public int getRecordCount() { |
223 | return this.recordCount; |
224 | } |
225 | |
226 | /** |
227 | * @return true if a GleSYS nameserver holds the records |
228 | */ |
229 | public boolean isUseGlesysNameServer() { |
230 | return this.useGlesysNameServer; |
231 | } |
232 | |
233 | @Nullable |
234 | public String getPrimaryNameServer() { |
235 | return primaryNameServer; |
236 | } |
237 | |
238 | /** |
239 | * The E-mail address of the person responsible for this domain (reformatted with '.' at end). |
240 | */ |
241 | @Nullable |
242 | public String getResponsiblePerson() { |
243 | return responsiblePerson; |
244 | } |
245 | |
246 | /** |
247 | * TTL (time to live). The number of seconds a domain name is cached locally before expiration and return to authoritative nameServers for updates |
248 | */ |
249 | public int getTtl() { |
250 | return ttl; |
251 | } |
252 | |
253 | /** |
254 | * The number of seconds between update requests from secondary and slave name servers |
255 | */ |
256 | public int getRefresh() { |
257 | return refresh; |
258 | } |
259 | |
260 | |
261 | /** |
262 | * The number of seconds the secondary/slave will wait before retrying when the last attempt failed |
263 | */ |
264 | public int getRetry() { |
265 | return retry; |
266 | } |
267 | |
268 | /** |
269 | * The number of seconds a master or slave will wait before considering the data stale if it cannot reach the primary name server |
270 | */ |
271 | public int getExpire() { |
272 | return expire; |
273 | } |
274 | |
275 | /** |
276 | * The minimum/default TTL if the domain does not specify ttl |
277 | * |
278 | * @see #getTtl() |
279 | */ |
280 | public int getMinimum() { |
281 | return minimum; |
282 | } |
283 | |
284 | @Override |
285 | public int hashCode() { |
286 | return Objects.hashCode(domainName); |
287 | } |
288 | |
289 | @Override |
290 | public boolean equals(Object obj) { |
291 | if (this == obj) return true; |
292 | if (obj == null || getClass() != obj.getClass()) return false; |
293 | Domain that = Domain.class.cast(obj); |
294 | return Objects.equal(this.domainName, that.domainName); |
295 | } |
296 | |
297 | protected ToStringHelper string() { |
298 | return Objects.toStringHelper("") |
299 | .add("domainName", domainName).add("createTime", createTime).add("recordCount", recordCount).add("useGlesysNameServer", useGlesysNameServer); |
300 | } |
301 | |
302 | @Override |
303 | public String toString() { |
304 | return string().toString(); |
305 | } |
306 | |
307 | } |