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 | * Detailed information on an Email Account |
31 | * |
32 | * @author Adam Lowe |
33 | * @see <a href="https://customer.glesys.com/api.php?a=doc#email_list" /> |
34 | */ |
35 | public class EmailAccount { |
36 | |
37 | public static Builder<?> builder() { |
38 | return new ConcreteBuilder(); |
39 | } |
40 | |
41 | public Builder<?> toBuilder() { |
42 | return new ConcreteBuilder().fromEmailAccount(this); |
43 | } |
44 | |
45 | public abstract static class Builder<T extends Builder<T>> { |
46 | protected abstract T self(); |
47 | |
48 | protected String account; |
49 | protected EmailQuota quota; |
50 | protected int antispamLevel; |
51 | protected boolean antiVirus; |
52 | protected boolean autoRespond; |
53 | protected String autoRespondMessage; |
54 | protected boolean autoRespondSaveEmail; |
55 | protected Date created; |
56 | protected Date modified; |
57 | |
58 | /** |
59 | * @see EmailAccount#getAccount() |
60 | */ |
61 | public T account(String account) { |
62 | this.account = checkNotNull(account, "account"); |
63 | return self(); |
64 | } |
65 | |
66 | /** |
67 | * @see EmailAccount#getQuota() |
68 | */ |
69 | public T quota(EmailQuota quota) { |
70 | this.quota = checkNotNull(quota, "quota"); |
71 | return self(); |
72 | } |
73 | |
74 | /** |
75 | * @see EmailAccount#getAntispamLevel() |
76 | */ |
77 | public T antispamLevel(int antispamLevel) { |
78 | this.antispamLevel = antispamLevel; |
79 | return self(); |
80 | } |
81 | |
82 | /** |
83 | * @see EmailAccount#isAntiVirus() |
84 | */ |
85 | public T antiVirus(boolean antiVirus) { |
86 | this.antiVirus = antiVirus; |
87 | return self(); |
88 | } |
89 | |
90 | /** |
91 | * @see EmailAccount#isAutoRespond() |
92 | */ |
93 | public T autoRespond(boolean autoRespond) { |
94 | this.autoRespond = autoRespond; |
95 | return self(); |
96 | } |
97 | |
98 | /** |
99 | * @see EmailAccount#getAutoRespondMessage() |
100 | */ |
101 | public T autoRespondMessage(String autoRespondMessage) { |
102 | this.autoRespondMessage = checkNotNull(autoRespondMessage, "autoRespondMessage"); |
103 | return self(); |
104 | } |
105 | |
106 | /** |
107 | * @see EmailAccount#isAutoRespondSaveEmail() |
108 | */ |
109 | public T autoRespondSaveEmail(boolean autoRespondSaveEmail) { |
110 | this.autoRespondSaveEmail = autoRespondSaveEmail; |
111 | return self(); |
112 | } |
113 | |
114 | /** |
115 | * @see EmailAccount#getCreated() |
116 | */ |
117 | public T created(Date created) { |
118 | this.created = checkNotNull(created, "created"); |
119 | return self(); |
120 | } |
121 | |
122 | /** |
123 | * @see EmailAccount#getModified() |
124 | */ |
125 | public T modified(Date modified) { |
126 | this.modified = checkNotNull(modified, "modified"); |
127 | return self(); |
128 | } |
129 | |
130 | public EmailAccount build() { |
131 | return new EmailAccount(account, quota, antispamLevel, new GleSYSBoolean(antiVirus), new GleSYSBoolean(autoRespond), autoRespondMessage, new GleSYSBoolean(autoRespondSaveEmail), created, modified); |
132 | } |
133 | |
134 | public T fromEmailAccount(EmailAccount in) { |
135 | return this.account(in.getAccount()) |
136 | .quota(in.getQuota()) |
137 | .antispamLevel(in.getAntispamLevel()) |
138 | .antiVirus(in.isAntiVirus()) |
139 | .autoRespond(in.isAutoRespond()) |
140 | .autoRespondMessage(in.getAutoRespondMessage()) |
141 | .autoRespondSaveEmail(in.isAutoRespondSaveEmail()) |
142 | .created(in.getCreated()) |
143 | .modified(in.getModified()); |
144 | } |
145 | } |
146 | |
147 | private static class ConcreteBuilder extends Builder<ConcreteBuilder> { |
148 | @Override |
149 | protected ConcreteBuilder self() { |
150 | return this; |
151 | } |
152 | } |
153 | |
154 | private final String account; |
155 | private final EmailQuota quota; |
156 | private final int antispamLevel; |
157 | private final boolean antiVirus; |
158 | private final boolean autoRespond; |
159 | private final String autoRespondMessage; |
160 | private final boolean autoRespondSaveEmail; |
161 | private final Date created; |
162 | private final Date modified; |
163 | |
164 | @ConstructorProperties({ |
165 | "emailaccount", "quota", "antispamlevel", "antivirus", "autorespond", "autorespondmessage", "autorespondsaveemail", "created", "modified" |
166 | }) |
167 | protected EmailAccount(String account, EmailQuota quota, int antispamLevel, |
168 | GleSYSBoolean antiVirus, GleSYSBoolean autoRespond, @Nullable String autoRespondMessage, |
169 | GleSYSBoolean autoRespondSaveEmail, Date created, @Nullable Date modified) { |
170 | this.account = checkNotNull(account, "account"); |
171 | this.quota = checkNotNull(quota, "quota"); |
172 | this.antispamLevel = antispamLevel; |
173 | this.antiVirus = checkNotNull(antiVirus, "antiVirus").getValue(); |
174 | this.autoRespond = checkNotNull(autoRespond, "autoRespond").getValue(); |
175 | this.autoRespondMessage = autoRespondMessage; |
176 | this.autoRespondSaveEmail = checkNotNull(autoRespondSaveEmail, "autoRespondSaveEmail").getValue(); |
177 | this.created = checkNotNull(created, "created"); |
178 | this.modified = modified; |
179 | } |
180 | |
181 | /** |
182 | * @return the e-mail address for this e-mail account |
183 | */ |
184 | public String getAccount() { |
185 | return this.account; |
186 | } |
187 | |
188 | /** |
189 | * @return the quota for this e-mail account |
190 | */ |
191 | public EmailQuota getQuota() { |
192 | return this.quota; |
193 | } |
194 | |
195 | /** |
196 | * @return the antispam level of the e-mail account |
197 | */ |
198 | public int getAntispamLevel() { |
199 | return this.antispamLevel; |
200 | } |
201 | |
202 | /** |
203 | * @return true if antivirus is enabled for this e-mail account |
204 | */ |
205 | public boolean isAntiVirus() { |
206 | return this.antiVirus; |
207 | } |
208 | |
209 | /** |
210 | * @return true if auto-respond is enabled for this e-mail account |
211 | */ |
212 | public boolean isAutoRespond() { |
213 | return this.autoRespond; |
214 | } |
215 | /** |
216 | * @return the auto-respond message for this e-mail account |
217 | */ |
218 | @Nullable |
219 | public String getAutoRespondMessage() { |
220 | return this.autoRespondMessage; |
221 | } |
222 | |
223 | /** |
224 | * @return true if saving is enabled for auto-respond e-mails |
225 | */ |
226 | public boolean isAutoRespondSaveEmail() { |
227 | return this.autoRespondSaveEmail; |
228 | } |
229 | |
230 | /** |
231 | * @return when this account was created |
232 | */ |
233 | public Date getCreated() { |
234 | return this.created; |
235 | } |
236 | |
237 | /** |
238 | * @return when this account was last modified |
239 | */ |
240 | @Nullable |
241 | public Date getModified() { |
242 | return this.modified; |
243 | } |
244 | |
245 | @Override |
246 | public int hashCode() { |
247 | return Objects.hashCode(account); |
248 | } |
249 | |
250 | @Override |
251 | public boolean equals(Object obj) { |
252 | if (this == obj) return true; |
253 | if (obj == null || getClass() != obj.getClass()) return false; |
254 | EmailAccount that = EmailAccount.class.cast(obj); |
255 | return Objects.equal(this.account, that.account); |
256 | } |
257 | |
258 | protected ToStringHelper string() { |
259 | return Objects.toStringHelper("") |
260 | .add("account", account).add("quota", quota).add("antispamLevel", antispamLevel).add("antiVirus", antiVirus).add("autoRespond", autoRespond).add("autoRespondMessage", autoRespondMessage).add("autoRespondSaveEmail", autoRespondSaveEmail).add("created", created).add("modified", modified); |
261 | } |
262 | |
263 | @Override |
264 | public String toString() { |
265 | return string().toString(); |
266 | } |
267 | |
268 | } |