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