b752d91c15beb91c757bbdbf4d25c5c4f5e8ccd6
[policy/common.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-endpoints
4  * ================================================================================
5  * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
6  * Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.common.endpoints.event.comm.bus.internal;
23
24 import java.util.List;
25 import java.util.Map;
26 import org.apache.commons.lang3.StringUtils;
27
28 /**
29  * Member variables of this Params class are as follows.
30  *
31  * <p>servers DMaaP servers
32  * topic DMaaP Topic to be monitored
33  * apiKey DMaaP API Key (optional)
34  * apiSecret DMaaP API Secret (optional)
35  * consumerGroup DMaaP Reader Consumer Group
36  * consumerInstance DMaaP Reader Instance
37  * fetchTimeout DMaaP fetch timeout
38  * fetchLimit DMaaP fetch limit
39  * environment DME2 Environment
40  * aftEnvironment DME2 AFT Environment
41  * partner DME2 Partner
42  * latitude DME2 Latitude
43  * longitude DME2 Longitude
44  * additionalProps Additional properties to pass to DME2
45  * useHttps does connection use HTTPS?
46  * allowSelfSignedCerts are self-signed certificates allow
47  */
48 public class BusTopicParams {
49
50     private int port;
51     private List<String> servers;
52     private Map<String, String> additionalProps;
53     private String topic;
54     private String apiKey;
55     private String apiSecret;
56     private String consumerGroup;
57     private String consumerInstance;
58     private int fetchTimeout;
59     private int fetchLimit;
60     private boolean useHttps;
61     private boolean allowSelfSignedCerts;
62     private boolean managed;
63
64     private String userName;
65     private String password;
66     private String environment;
67     private String aftEnvironment;
68     private String partner;
69     private String latitude;
70     private String longitude;
71     private String partitionId;
72     private String clientName;
73     private String hostname;
74     private String basePath;
75
76     public static TopicParamsBuilder builder() {
77         return new TopicParamsBuilder();
78     }
79
80     public String getPartitionId() {
81         return partitionId;
82     }
83
84     public String getUserName() {
85         return userName;
86     }
87
88     public String getPassword() {
89         return password;
90     }
91
92     public String getEnvironment() {
93         return environment;
94     }
95
96     public String getAftEnvironment() {
97         return aftEnvironment;
98     }
99
100     public String getPartner() {
101         return partner;
102     }
103
104     public String getLatitude() {
105         return latitude;
106     }
107
108     public String getLongitude() {
109         return longitude;
110     }
111
112     public Map<String, String> getAdditionalProps() {
113         return additionalProps;
114     }
115
116     public List<String> getServers() {
117         return servers;
118     }
119
120     public String getTopic() {
121         return topic;
122     }
123
124     public String getApiKey() {
125         return apiKey;
126     }
127
128     public String getApiSecret() {
129         return apiSecret;
130     }
131
132     public String getConsumerGroup() {
133         return consumerGroup;
134     }
135
136     public String getConsumerInstance() {
137         return consumerInstance;
138     }
139
140     public int getFetchTimeout() {
141         return fetchTimeout;
142     }
143
144     public int getFetchLimit() {
145         return fetchLimit;
146     }
147
148     public String getClientName() {
149         return clientName;
150     }
151
152     public String getHostname() {
153         return hostname;
154     }
155
156     public int getPort() {
157         return port;
158     }
159
160     public String getBasePath() {
161         return basePath;
162     }
163
164     public boolean isManaged() {
165         return managed;
166     }
167
168     public boolean isUseHttps() {
169         return useHttps;
170     }
171
172     public boolean isAllowSelfSignedCerts() {
173         return allowSelfSignedCerts;
174     }
175
176     /**
177      * Methods to Check if the property is INVALID.
178      */
179
180     boolean isEnvironmentInvalid() {
181         return StringUtils.isBlank(environment);
182     }
183
184     boolean isAftEnvironmentInvalid() {
185         return StringUtils.isBlank(aftEnvironment);
186     }
187
188     boolean isLatitudeInvalid() {
189         return StringUtils.isBlank(latitude);
190     }
191
192     boolean isLongitudeInvalid() {
193         return StringUtils.isBlank(longitude);
194     }
195
196     boolean isConsumerInstanceInvalid() {
197         return StringUtils.isBlank(consumerInstance);
198     }
199
200     boolean isConsumerGroupInvalid() {
201         return StringUtils.isBlank(consumerGroup);
202     }
203
204     public boolean isClientNameInvalid() {
205         return StringUtils.isBlank(clientName);
206     }
207
208     boolean isPartnerInvalid() {
209         return StringUtils.isBlank(partner);
210     }
211
212     boolean isServersInvalid() {
213         return (servers == null || servers.isEmpty()
214                 || (servers.size() == 1 && ("".equals(servers.get(0)))));
215     }
216
217     boolean isTopicInvalid() {
218         return StringUtils.isBlank(topic);
219     }
220
221     boolean isPartitionIdInvalid() {
222         return StringUtils.isBlank(partitionId);
223     }
224
225     public boolean isHostnameInvalid() {
226         return StringUtils.isBlank(hostname);
227     }
228
229     public boolean isPortInvalid() {
230         return  (getPort() <= 0 || getPort() >= 65535);
231     }
232
233     /**
234      * Methods to Check if the property is Valid.
235      */
236
237     boolean isApiKeyValid() {
238         return StringUtils.isNotBlank(apiKey);
239     }
240
241     boolean isApiSecretValid() {
242         return StringUtils.isNotBlank(apiSecret);
243     }
244
245     boolean isUserNameValid() {
246         return StringUtils.isNotBlank(userName);
247     }
248
249     boolean isPasswordValid() {
250         return StringUtils.isNotBlank(password);
251     }
252
253     boolean isAdditionalPropsValid() {
254         return additionalProps != null;
255     }
256
257     public static class TopicParamsBuilder {
258
259         final BusTopicParams params = new BusTopicParams();
260
261         private TopicParamsBuilder() {
262         }
263
264         public TopicParamsBuilder servers(List<String> servers) {
265             this.params.servers = servers;
266             return this;
267         }
268
269         public TopicParamsBuilder topic(String topic) {
270             this.params.topic = topic;
271             return this;
272         }
273
274         public TopicParamsBuilder apiKey(String apiKey) {
275             this.params.apiKey = apiKey;
276             return this;
277         }
278
279         public TopicParamsBuilder apiSecret(String apiSecret) {
280             this.params.apiSecret = apiSecret;
281             return this;
282         }
283
284         public TopicParamsBuilder consumerGroup(String consumerGroup) {
285             this.params.consumerGroup = consumerGroup;
286             return this;
287         }
288
289         public TopicParamsBuilder consumerInstance(String consumerInstance) {
290             this.params.consumerInstance = consumerInstance;
291             return this;
292         }
293
294         public TopicParamsBuilder fetchTimeout(int fetchTimeout) {
295             this.params.fetchTimeout = fetchTimeout;
296             return this;
297         }
298
299         public TopicParamsBuilder fetchLimit(int fetchLimit) {
300             this.params.fetchLimit = fetchLimit;
301             return this;
302         }
303
304         public TopicParamsBuilder useHttps(boolean useHttps) {
305             this.params.useHttps = useHttps;
306             return this;
307         }
308
309         public TopicParamsBuilder allowSelfSignedCerts(boolean allowSelfSignedCerts) {
310             this.params.allowSelfSignedCerts = allowSelfSignedCerts;
311             return this;
312         }
313
314         public TopicParamsBuilder userName(String userName) {
315             this.params.userName = userName;
316             return this;
317         }
318
319         public TopicParamsBuilder password(String password) {
320             this.params.password = password;
321             return this;
322         }
323
324         public TopicParamsBuilder environment(String environment) {
325             this.params.environment = environment;
326             return this;
327         }
328
329         public TopicParamsBuilder aftEnvironment(String aftEnvironment) {
330             this.params.aftEnvironment = aftEnvironment;
331             return this;
332         }
333
334         public TopicParamsBuilder partner(String partner) {
335             this.params.partner = partner;
336             return this;
337         }
338
339         public TopicParamsBuilder latitude(String latitude) {
340             this.params.latitude = latitude;
341             return this;
342         }
343
344         public TopicParamsBuilder longitude(String longitude) {
345             this.params.longitude = longitude;
346             return this;
347         }
348
349         public TopicParamsBuilder additionalProps(Map<String, String> additionalProps) {
350             this.params.additionalProps = additionalProps;
351             return this;
352         }
353
354         public TopicParamsBuilder partitionId(String partitionId) {
355             this.params.partitionId = partitionId;
356             return this;
357         }
358
359         public BusTopicParams build() {
360             return params;
361         }
362
363         public TopicParamsBuilder managed(boolean managed) {
364             this.params.managed = managed;
365             return this;
366         }
367
368         public TopicParamsBuilder hostname(String hostname) {
369             this.params.hostname = hostname;
370             return this;
371         }
372
373         public TopicParamsBuilder clientName(String clientName) {
374             this.params.clientName = clientName;
375             return this;
376         }
377
378         public TopicParamsBuilder port(int port) {
379             this.params.port = port;
380             return this;
381         }
382
383         public TopicParamsBuilder basePath(String basePath) {
384             this.params.basePath = basePath;
385             return this;
386         }
387
388     }
389 }
390