b133f1c7ea72836bee17c2404dcd214eabc29fa2
[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         
217         BusTopicParams params = new BusTopicParams();
218
219         private TopicParamsBuilder() {
220         }
221
222         public TopicParamsBuilder servers(List<String> servers) {
223             this.params.servers = servers;
224             return this;
225         }
226
227         public TopicParamsBuilder topic(String topic) {
228             this.params.topic = topic;
229             return this;
230         }
231
232         public TopicParamsBuilder apiKey(String apiKey) {
233             this.params.apiKey = apiKey;
234             return this;
235         }
236
237         public TopicParamsBuilder apiSecret(String apiSecret) {
238             this.params.apiSecret = apiSecret;
239             return this;
240         }
241
242         public TopicParamsBuilder consumerGroup(String consumerGroup) {
243             this.params.consumerGroup = consumerGroup;
244             return this;
245         }
246
247         public TopicParamsBuilder consumerInstance(String consumerInstance) {
248             this.params.consumerInstance = consumerInstance;
249             return this;
250         }
251
252         public TopicParamsBuilder fetchTimeout(int fetchTimeout) {
253             this.params.fetchTimeout = fetchTimeout;
254             return this;
255         }
256
257         public TopicParamsBuilder fetchLimit(int fetchLimit) {
258             this.params.fetchLimit = fetchLimit;
259             return this;
260         }
261
262         public TopicParamsBuilder useHttps(boolean useHttps) {
263             this.params.useHttps = useHttps;
264             return this;
265         }
266
267         public TopicParamsBuilder allowSelfSignedCerts(boolean allowSelfSignedCerts) {
268             this.params.allowSelfSignedCerts = allowSelfSignedCerts;
269             return this;
270         }
271
272         public TopicParamsBuilder userName(String userName) {
273             this.params.userName = userName;
274             return this;
275         }
276
277         public TopicParamsBuilder password(String password) {
278             this.params.password = password;
279             return this;
280         }
281
282         public TopicParamsBuilder environment(String environment) {
283             this.params.environment = environment;
284             return this;
285         }
286
287         public TopicParamsBuilder aftEnvironment(String aftEnvironment) {
288             this.params.aftEnvironment = aftEnvironment;
289             return this;
290         }
291
292         public TopicParamsBuilder partner(String partner) {
293             this.params.partner = partner;
294             return this;
295         }
296
297         public TopicParamsBuilder latitude(String latitude) {
298             this.params.latitude = latitude;
299             return this;
300         }
301
302         public TopicParamsBuilder longitude(String longitude) {
303             this.params.longitude = longitude;
304             return this;
305         }
306
307         public TopicParamsBuilder additionalProps(Map<String, String> additionalProps) {
308             this.params.additionalProps = additionalProps;
309             return this;
310         }
311
312         public TopicParamsBuilder partitionId(String partitionId) {
313             this.params.partitionId = partitionId;
314             return this;
315         }
316
317         public BusTopicParams build() {
318             return params;
319         }
320
321         public TopicParamsBuilder managed(boolean managed) {
322             this.params.managed = managed;
323             return this;
324         }
325     }
326 }
327