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