9df7221fe6cc532d08cf2af5c9fb2bf3e4e3dbb9
[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  * Modifications Copyright (C) 2019 Nordix Foundation.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.common.endpoints.event.comm.bus.internal;
24
25 import java.util.List;
26 import java.util.Map;
27 import lombok.Getter;
28 import lombok.Setter;
29 import org.apache.commons.lang3.StringUtils;
30
31 /**
32  * Member variables of this Params class are as follows.
33  *
34  * <p>servers DMaaP servers
35  * topic DMaaP Topic to be monitored
36  * apiKey DMaaP API Key (optional)
37  * apiSecret DMaaP API Secret (optional)
38  * consumerGroup DMaaP Reader Consumer Group
39  * consumerInstance DMaaP Reader Instance
40  * fetchTimeout DMaaP fetch timeout
41  * fetchLimit DMaaP fetch limit
42  * environment DME2 Environment
43  * aftEnvironment DME2 AFT Environment
44  * partner DME2 Partner
45  * latitude DME2 Latitude
46  * longitude DME2 Longitude
47  * additionalProps Additional properties to pass to DME2
48  * useHttps does connection use HTTPS?
49  * allowSelfSignedCerts are self-signed certificates allow
50  */
51 @Getter
52 @Setter
53 public class BusTopicParams {
54
55     private int port;
56     private List<String> servers;
57     private Map<String, String> additionalProps;
58     private String topic;
59     private String effectiveTopic;
60     private String apiKey;
61     private String apiSecret;
62     private String consumerGroup;
63     private String consumerInstance;
64     private int fetchTimeout;
65     private int fetchLimit;
66     private boolean useHttps;
67     private boolean allowSelfSignedCerts;
68     private boolean managed;
69
70     private String userName;
71     private String password;
72     private String environment;
73     private String aftEnvironment;
74     private String partner;
75     private String latitude;
76     private String longitude;
77     private String partitionId;
78     private String clientName;
79     private String hostname;
80     private String basePath;
81     private String serializationProvider;
82
83     public static TopicParamsBuilder builder() {
84         return new TopicParamsBuilder();
85     }
86
87     /**
88      * Methods to Check if the property is INVALID.
89      */
90
91     boolean isEnvironmentInvalid() {
92         return StringUtils.isBlank(environment);
93     }
94
95     boolean isAftEnvironmentInvalid() {
96         return StringUtils.isBlank(aftEnvironment);
97     }
98
99     boolean isLatitudeInvalid() {
100         return StringUtils.isBlank(latitude);
101     }
102
103     boolean isLongitudeInvalid() {
104         return StringUtils.isBlank(longitude);
105     }
106
107     boolean isConsumerInstanceInvalid() {
108         return StringUtils.isBlank(consumerInstance);
109     }
110
111     boolean isConsumerGroupInvalid() {
112         return StringUtils.isBlank(consumerGroup);
113     }
114
115     public boolean isClientNameInvalid() {
116         return StringUtils.isBlank(clientName);
117     }
118
119     boolean isPartnerInvalid() {
120         return StringUtils.isBlank(partner);
121     }
122
123     boolean isServersInvalid() {
124         return (servers == null || servers.isEmpty()
125                 || (servers.size() == 1 && ("".equals(servers.get(0)))));
126     }
127
128     boolean isTopicInvalid() {
129         return StringUtils.isBlank(topic);
130     }
131
132     boolean isPartitionIdInvalid() {
133         return StringUtils.isBlank(partitionId);
134     }
135
136     public boolean isHostnameInvalid() {
137         return StringUtils.isBlank(hostname);
138     }
139
140     public boolean isPortInvalid() {
141         return  (getPort() <= 0 || getPort() >= 65535);
142     }
143
144     /**
145      * Methods to Check if the property is Valid.
146      */
147
148     boolean isApiKeyValid() {
149         return StringUtils.isNotBlank(apiKey);
150     }
151
152     boolean isApiSecretValid() {
153         return StringUtils.isNotBlank(apiSecret);
154     }
155
156     boolean isUserNameValid() {
157         return StringUtils.isNotBlank(userName);
158     }
159
160     boolean isPasswordValid() {
161         return StringUtils.isNotBlank(password);
162     }
163
164     boolean isAdditionalPropsValid() {
165         return additionalProps != null;
166     }
167
168     public String getSerializationProvider() {
169         return serializationProvider;
170     }
171
172     public static class TopicParamsBuilder {
173
174         final BusTopicParams params = new BusTopicParams();
175
176         private TopicParamsBuilder() {
177         }
178
179         public TopicParamsBuilder servers(List<String> servers) {
180             this.params.servers = servers;
181             return this;
182         }
183
184         public TopicParamsBuilder topic(String topic) {
185             this.params.topic = topic;
186             return this;
187         }
188
189         public TopicParamsBuilder effectiveTopic(String effectiveTopic) {
190             this.params.effectiveTopic = effectiveTopic;
191             return this;
192         }
193
194         public TopicParamsBuilder apiKey(String apiKey) {
195             this.params.apiKey = apiKey;
196             return this;
197         }
198
199         public TopicParamsBuilder apiSecret(String apiSecret) {
200             this.params.apiSecret = apiSecret;
201             return this;
202         }
203
204         public TopicParamsBuilder consumerGroup(String consumerGroup) {
205             this.params.consumerGroup = consumerGroup;
206             return this;
207         }
208
209         public TopicParamsBuilder consumerInstance(String consumerInstance) {
210             this.params.consumerInstance = consumerInstance;
211             return this;
212         }
213
214         public TopicParamsBuilder fetchTimeout(int fetchTimeout) {
215             this.params.fetchTimeout = fetchTimeout;
216             return this;
217         }
218
219         public TopicParamsBuilder fetchLimit(int fetchLimit) {
220             this.params.fetchLimit = fetchLimit;
221             return this;
222         }
223
224         public TopicParamsBuilder useHttps(boolean useHttps) {
225             this.params.useHttps = useHttps;
226             return this;
227         }
228
229         public TopicParamsBuilder allowSelfSignedCerts(boolean allowSelfSignedCerts) {
230             this.params.allowSelfSignedCerts = allowSelfSignedCerts;
231             return this;
232         }
233
234         public TopicParamsBuilder userName(String userName) {
235             this.params.userName = userName;
236             return this;
237         }
238
239         public TopicParamsBuilder password(String password) {
240             this.params.password = password;
241             return this;
242         }
243
244         public TopicParamsBuilder environment(String environment) {
245             this.params.environment = environment;
246             return this;
247         }
248
249         public TopicParamsBuilder aftEnvironment(String aftEnvironment) {
250             this.params.aftEnvironment = aftEnvironment;
251             return this;
252         }
253
254         public TopicParamsBuilder partner(String partner) {
255             this.params.partner = partner;
256             return this;
257         }
258
259         public TopicParamsBuilder latitude(String latitude) {
260             this.params.latitude = latitude;
261             return this;
262         }
263
264         public TopicParamsBuilder longitude(String longitude) {
265             this.params.longitude = longitude;
266             return this;
267         }
268
269         public TopicParamsBuilder additionalProps(Map<String, String> additionalProps) {
270             this.params.additionalProps = additionalProps;
271             return this;
272         }
273
274         public TopicParamsBuilder partitionId(String partitionId) {
275             this.params.partitionId = partitionId;
276             return this;
277         }
278
279         public BusTopicParams build() {
280             return params;
281         }
282
283         public TopicParamsBuilder managed(boolean managed) {
284             this.params.managed = managed;
285             return this;
286         }
287
288         public TopicParamsBuilder hostname(String hostname) {
289             this.params.hostname = hostname;
290             return this;
291         }
292
293         public TopicParamsBuilder clientName(String clientName) {
294             this.params.clientName = clientName;
295             return this;
296         }
297
298         public TopicParamsBuilder port(int port) {
299             this.params.port = port;
300             return this;
301         }
302
303         public TopicParamsBuilder basePath(String basePath) {
304             this.params.basePath = basePath;
305             return this;
306         }
307
308         public TopicParamsBuilder serializationProvider(String serializationProvider) {
309             this.params.serializationProvider = serializationProvider;
310             return this;
311         }
312
313     }
314 }
315