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