6e3c263289a346d7f47e024bc8e360f9f751c7a8
[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-2019 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     private String serializationProvider;
76
77     public static TopicParamsBuilder builder() {
78         return new TopicParamsBuilder();
79     }
80
81     public String getPartitionId() {
82         return partitionId;
83     }
84
85     public String getUserName() {
86         return userName;
87     }
88
89     public String getPassword() {
90         return password;
91     }
92
93     public String getEnvironment() {
94         return environment;
95     }
96
97     public String getAftEnvironment() {
98         return aftEnvironment;
99     }
100
101     public String getPartner() {
102         return partner;
103     }
104
105     public String getLatitude() {
106         return latitude;
107     }
108
109     public String getLongitude() {
110         return longitude;
111     }
112
113     public Map<String, String> getAdditionalProps() {
114         return additionalProps;
115     }
116
117     public List<String> getServers() {
118         return servers;
119     }
120
121     public String getTopic() {
122         return topic;
123     }
124
125     public String getApiKey() {
126         return apiKey;
127     }
128
129     public String getApiSecret() {
130         return apiSecret;
131     }
132
133     public String getConsumerGroup() {
134         return consumerGroup;
135     }
136
137     public String getConsumerInstance() {
138         return consumerInstance;
139     }
140
141     public int getFetchTimeout() {
142         return fetchTimeout;
143     }
144
145     public int getFetchLimit() {
146         return fetchLimit;
147     }
148
149     public String getClientName() {
150         return clientName;
151     }
152
153     public String getHostname() {
154         return hostname;
155     }
156
157     public int getPort() {
158         return port;
159     }
160
161     public String getBasePath() {
162         return basePath;
163     }
164
165     public boolean isManaged() {
166         return managed;
167     }
168
169     public boolean isUseHttps() {
170         return useHttps;
171     }
172
173     public boolean isAllowSelfSignedCerts() {
174         return allowSelfSignedCerts;
175     }
176
177     /**
178      * Methods to Check if the property is INVALID.
179      */
180
181     boolean isEnvironmentInvalid() {
182         return StringUtils.isBlank(environment);
183     }
184
185     boolean isAftEnvironmentInvalid() {
186         return StringUtils.isBlank(aftEnvironment);
187     }
188
189     boolean isLatitudeInvalid() {
190         return StringUtils.isBlank(latitude);
191     }
192
193     boolean isLongitudeInvalid() {
194         return StringUtils.isBlank(longitude);
195     }
196
197     boolean isConsumerInstanceInvalid() {
198         return StringUtils.isBlank(consumerInstance);
199     }
200
201     boolean isConsumerGroupInvalid() {
202         return StringUtils.isBlank(consumerGroup);
203     }
204
205     public boolean isClientNameInvalid() {
206         return StringUtils.isBlank(clientName);
207     }
208
209     boolean isPartnerInvalid() {
210         return StringUtils.isBlank(partner);
211     }
212
213     boolean isServersInvalid() {
214         return (servers == null || servers.isEmpty()
215                 || (servers.size() == 1 && ("".equals(servers.get(0)))));
216     }
217
218     boolean isTopicInvalid() {
219         return StringUtils.isBlank(topic);
220     }
221
222     boolean isPartitionIdInvalid() {
223         return StringUtils.isBlank(partitionId);
224     }
225
226     public boolean isHostnameInvalid() {
227         return StringUtils.isBlank(hostname);
228     }
229
230     public boolean isPortInvalid() {
231         return  (getPort() <= 0 || getPort() >= 65535);
232     }
233
234     /**
235      * Methods to Check if the property is Valid.
236      */
237
238     boolean isApiKeyValid() {
239         return StringUtils.isNotBlank(apiKey);
240     }
241
242     boolean isApiSecretValid() {
243         return StringUtils.isNotBlank(apiSecret);
244     }
245
246     boolean isUserNameValid() {
247         return StringUtils.isNotBlank(userName);
248     }
249
250     boolean isPasswordValid() {
251         return StringUtils.isNotBlank(password);
252     }
253
254     boolean isAdditionalPropsValid() {
255         return additionalProps != null;
256     }
257
258     public String getSerializationProvider() {
259         return serializationProvider;
260     }
261
262     public static class TopicParamsBuilder {
263
264         final BusTopicParams params = new BusTopicParams();
265
266         private TopicParamsBuilder() {
267         }
268
269         public TopicParamsBuilder servers(List<String> servers) {
270             this.params.servers = servers;
271             return this;
272         }
273
274         public TopicParamsBuilder topic(String topic) {
275             this.params.topic = topic;
276             return this;
277         }
278
279         public TopicParamsBuilder apiKey(String apiKey) {
280             this.params.apiKey = apiKey;
281             return this;
282         }
283
284         public TopicParamsBuilder apiSecret(String apiSecret) {
285             this.params.apiSecret = apiSecret;
286             return this;
287         }
288
289         public TopicParamsBuilder consumerGroup(String consumerGroup) {
290             this.params.consumerGroup = consumerGroup;
291             return this;
292         }
293
294         public TopicParamsBuilder consumerInstance(String consumerInstance) {
295             this.params.consumerInstance = consumerInstance;
296             return this;
297         }
298
299         public TopicParamsBuilder fetchTimeout(int fetchTimeout) {
300             this.params.fetchTimeout = fetchTimeout;
301             return this;
302         }
303
304         public TopicParamsBuilder fetchLimit(int fetchLimit) {
305             this.params.fetchLimit = fetchLimit;
306             return this;
307         }
308
309         public TopicParamsBuilder useHttps(boolean useHttps) {
310             this.params.useHttps = useHttps;
311             return this;
312         }
313
314         public TopicParamsBuilder allowSelfSignedCerts(boolean allowSelfSignedCerts) {
315             this.params.allowSelfSignedCerts = allowSelfSignedCerts;
316             return this;
317         }
318
319         public TopicParamsBuilder userName(String userName) {
320             this.params.userName = userName;
321             return this;
322         }
323
324         public TopicParamsBuilder password(String password) {
325             this.params.password = password;
326             return this;
327         }
328
329         public TopicParamsBuilder environment(String environment) {
330             this.params.environment = environment;
331             return this;
332         }
333
334         public TopicParamsBuilder aftEnvironment(String aftEnvironment) {
335             this.params.aftEnvironment = aftEnvironment;
336             return this;
337         }
338
339         public TopicParamsBuilder partner(String partner) {
340             this.params.partner = partner;
341             return this;
342         }
343
344         public TopicParamsBuilder latitude(String latitude) {
345             this.params.latitude = latitude;
346             return this;
347         }
348
349         public TopicParamsBuilder longitude(String longitude) {
350             this.params.longitude = longitude;
351             return this;
352         }
353
354         public TopicParamsBuilder additionalProps(Map<String, String> additionalProps) {
355             this.params.additionalProps = additionalProps;
356             return this;
357         }
358
359         public TopicParamsBuilder partitionId(String partitionId) {
360             this.params.partitionId = partitionId;
361             return this;
362         }
363
364         public BusTopicParams build() {
365             return params;
366         }
367
368         public TopicParamsBuilder managed(boolean managed) {
369             this.params.managed = managed;
370             return this;
371         }
372
373         public TopicParamsBuilder hostname(String hostname) {
374             this.params.hostname = hostname;
375             return this;
376         }
377
378         public TopicParamsBuilder clientName(String clientName) {
379             this.params.clientName = clientName;
380             return this;
381         }
382
383         public TopicParamsBuilder port(int port) {
384             this.params.port = port;
385             return this;
386         }
387
388         public TopicParamsBuilder basePath(String basePath) {
389             this.params.basePath = basePath;
390             return this;
391         }
392
393         public TopicParamsBuilder serializationProvider(String serializationProvider) {
394             this.params.serializationProvider = serializationProvider;
395             return this;
396         }
397
398     }
399 }
400