347ae42c5c76fd8ed6c0e1551e1dc7b65dcb71aa
[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  * 
29  * <p>servers DMaaP servers
30  * topic DMaaP Topic to be monitored
31  * apiKey DMaaP API Key (optional)
32  * apiSecret DMaaP API Secret (optional)
33  * consumerGroup DMaaP Reader Consumer Group
34  * consumerInstance DMaaP Reader Instance
35  * fetchTimeout DMaaP fetch timeout
36  * fetchLimit DMaaP fetch limit
37  * environment DME2 Environment
38  * aftEnvironment DME2 AFT Environment
39  * partner DME2 Partner
40  * latitude DME2 Latitude
41  * longitude DME2 Longitude
42  * additionalProps Additional properties to pass to DME2
43  * useHttps does connection use HTTPS?
44  * allowSelfSignedCerts are self-signed certificates allow
45  */
46 public class BusTopicParams {
47
48     public static TopicParamsBuilder builder() {
49         return new TopicParamsBuilder();
50     }
51
52     private List<String> servers;
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
63     private String userName;
64     private String password;
65     private String environment;
66     private String aftEnvironment;
67     private String partner;
68     private String latitude;
69     private String longitude;
70     private Map<String, String> additionalProps;
71     private String partitionId;
72     private boolean managed;
73
74     public String getPartitionId() {
75         return partitionId;
76     }
77
78     public String getUserName() {
79         return userName;
80     }
81
82     public String getPassword() {
83         return password;
84     }
85
86     public String getEnvironment() {
87         return environment;
88     }
89
90     public String getAftEnvironment() {
91         return aftEnvironment;
92     }
93
94     public String getPartner() {
95         return partner;
96     }
97
98     public String getLatitude() {
99         return latitude;
100     }
101
102     public String getLongitude() {
103         return longitude;
104     }
105
106     public Map<String, String> getAdditionalProps() {
107         return additionalProps;
108     }
109
110     public List<String> getServers() {
111         return servers;
112     }
113
114     public String getTopic() {
115         return topic;
116     }
117
118     public String getApiKey() {
119         return apiKey;
120     }
121
122     public String getApiSecret() {
123         return apiSecret;
124     }
125
126     public String getConsumerGroup() {
127         return consumerGroup;
128     }
129
130     public String getConsumerInstance() {
131         return consumerInstance;
132     }
133
134     public int getFetchTimeout() {
135         return fetchTimeout;
136     }
137
138     public int getFetchLimit() {
139         return fetchLimit;
140     }
141
142     public boolean isUseHttps() {
143         return useHttps;
144     }
145
146     public boolean isAllowSelfSignedCerts() {
147         return allowSelfSignedCerts;
148     }
149
150     boolean isEnvironmentNullOrEmpty() {
151         return (environment == null || environment.trim().isEmpty());
152     }
153
154     boolean isAftEnvironmentNullOrEmpty() {
155         return (aftEnvironment == null || aftEnvironment.trim().isEmpty());
156     }
157
158     boolean isLatitudeNullOrEmpty() {
159         return (latitude == null || latitude.trim().isEmpty());
160     }
161
162     boolean isLongitudeNullOrEmpty() {
163         return (longitude == null || longitude.trim().isEmpty());
164     }
165
166     boolean isConsumerInstanceNullOrEmpty() {
167         return (consumerInstance == null || consumerInstance.trim().isEmpty());
168     }
169
170     boolean isConsumerGroupNullOrEmpty() {
171         return (consumerGroup == null || consumerGroup.trim().isEmpty());
172     }
173
174     boolean isApiKeyValid() {
175         return !(apiKey == null || apiKey.trim().isEmpty());
176     }
177
178     boolean isApiSecretValid() {
179         return !(apiSecret == null || apiSecret.trim().isEmpty());
180     }
181
182     boolean isUserNameValid() {
183         return !(userName == null || userName.trim().isEmpty());
184     }
185
186     boolean isPasswordValid() {
187         return !(password == null || password.trim().isEmpty());
188     }
189
190     boolean isPartnerNullOrEmpty() {
191         return (partner == null || partner.trim().isEmpty());
192     }
193
194     boolean isServersNullOrEmpty() {
195         return (servers == null || servers.isEmpty()
196                 || (servers.size() == 1 && ("".equals(servers.get(0)))));
197     }
198
199     boolean isAdditionalPropsValid() {
200         return additionalProps != null;
201     }
202
203     boolean isTopicNullOrEmpty() {
204         return (topic == null || topic.trim().isEmpty());
205     }
206
207     boolean isPartitionIdNullOrEmpty() {
208         return (partitionId == null || partitionId.trim().isEmpty());
209     }
210
211     public boolean isManaged() {
212         return managed;
213     }
214
215     public static class TopicParamsBuilder {
216         BusTopicParams m = new BusTopicParams();
217
218         private TopicParamsBuilder() {
219         }
220
221         public TopicParamsBuilder servers(List<String> servers) {
222             this.m.servers = servers;
223             return this;
224         }
225
226         public TopicParamsBuilder topic(String topic) {
227             this.m.topic = topic;
228             return this;
229         }
230
231         public TopicParamsBuilder apiKey(String apiKey) {
232             this.m.apiKey = apiKey;
233             return this;
234         }
235
236         public TopicParamsBuilder apiSecret(String apiSecret) {
237             this.m.apiSecret = apiSecret;
238             return this;
239         }
240
241         public TopicParamsBuilder consumerGroup(String consumerGroup) {
242             this.m.consumerGroup = consumerGroup;
243             return this;
244         }
245
246         public TopicParamsBuilder consumerInstance(String consumerInstance) {
247             this.m.consumerInstance = consumerInstance;
248             return this;
249         }
250
251         public TopicParamsBuilder fetchTimeout(int fetchTimeout) {
252             this.m.fetchTimeout = fetchTimeout;
253             return this;
254         }
255
256         public TopicParamsBuilder fetchLimit(int fetchLimit) {
257             this.m.fetchLimit = fetchLimit;
258             return this;
259         }
260
261         public TopicParamsBuilder useHttps(boolean useHttps) {
262             this.m.useHttps = useHttps;
263             return this;
264         }
265
266         public TopicParamsBuilder allowSelfSignedCerts(boolean allowSelfSignedCerts) {
267             this.m.allowSelfSignedCerts = allowSelfSignedCerts;
268             return this;
269         }
270
271         public TopicParamsBuilder userName(String userName) {
272             this.m.userName = userName;
273             return this;
274         }
275
276         public TopicParamsBuilder password(String password) {
277             this.m.password = password;
278             return this;
279         }
280
281         public TopicParamsBuilder environment(String environment) {
282             this.m.environment = environment;
283             return this;
284         }
285
286         public TopicParamsBuilder aftEnvironment(String aftEnvironment) {
287             this.m.aftEnvironment = aftEnvironment;
288             return this;
289         }
290
291         public TopicParamsBuilder partner(String partner) {
292             this.m.partner = partner;
293             return this;
294         }
295
296         public TopicParamsBuilder latitude(String latitude) {
297             this.m.latitude = latitude;
298             return this;
299         }
300
301         public TopicParamsBuilder longitude(String longitude) {
302             this.m.longitude = longitude;
303             return this;
304         }
305
306         public TopicParamsBuilder additionalProps(Map<String, String> additionalProps) {
307             this.m.additionalProps = additionalProps;
308             return this;
309         }
310
311         public TopicParamsBuilder partitionId(String partitionId) {
312             this.m.partitionId = partitionId;
313             return this;
314         }
315
316         public BusTopicParams build() {
317             return m;
318         }
319
320         public TopicParamsBuilder managed(boolean managed) {
321             this.m.managed = managed;
322             return this;
323         }
324     }
325 }
326