f9eca08126fb95123e11bdc57cd9b289206f4ec1
[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
73     String getPartitionId() {
74         return partitionId;
75     }
76
77     String getUserName() {
78         return userName;
79     }
80
81     String getPassword() {
82         return password;
83     }
84
85     String getEnvironment() {
86         return environment;
87     }
88
89     String getAftEnvironment() {
90         return aftEnvironment;
91     }
92
93     String getPartner() {
94         return partner;
95     }
96
97     String getLatitude() {
98         return latitude;
99     }
100
101     String getLongitude() {
102         return longitude;
103     }
104
105     Map<String, String> getAdditionalProps() {
106         return additionalProps;
107     }
108
109     List<String> getServers() {
110         return servers;
111     }
112
113     String getTopic() {
114         return topic;
115     }
116
117     String getApiKey() {
118         return apiKey;
119     }
120
121     String getApiSecret() {
122         return apiSecret;
123     }
124
125     String getConsumerGroup() {
126         return consumerGroup;
127     }
128
129     String getConsumerInstance() {
130         return consumerInstance;
131     }
132
133     int getFetchTimeout() {
134         return fetchTimeout;
135     }
136
137     int getFetchLimit() {
138         return fetchLimit;
139     }
140
141     boolean isUseHttps() {
142         return useHttps;
143     }
144
145     boolean isAllowSelfSignedCerts() {
146         return allowSelfSignedCerts;
147     }
148
149     boolean isEnvironmentNullOrEmpty() {
150         return (environment == null || environment.trim().isEmpty());
151     }
152
153     boolean isAftEnvironmentNullOrEmpty() {
154         return (aftEnvironment == null || aftEnvironment.trim().isEmpty());
155     }
156
157     boolean isLatitudeNullOrEmpty() {
158         return (latitude == null || latitude.trim().isEmpty());
159     }
160
161     boolean isLongitudeNullOrEmpty() {
162         return (longitude == null || longitude.trim().isEmpty());
163     }
164
165     boolean isConsumerInstanceNullOrEmpty() {
166         return (consumerInstance == null || consumerInstance.trim().isEmpty());
167     }
168
169     boolean isConsumerGroupNullOrEmpty() {
170         return (consumerGroup == null || consumerGroup.trim().isEmpty());
171     }
172
173     boolean isApiKeyValid() {
174         return !(apiKey == null || apiKey.trim().isEmpty());
175     }
176
177     boolean isApiSecretValid() {
178         return !(apiSecret == null || apiSecret.trim().isEmpty());
179     }
180
181     boolean isUserNameValid() {
182         return !(userName == null || userName.trim().isEmpty());
183     }
184
185     boolean isPasswordValid() {
186         return !(password == null || password.trim().isEmpty());
187     }
188
189     boolean isPartnerNullOrEmpty() {
190         return (partner == null || partner.trim().isEmpty());
191     }
192
193     boolean isServersNullOrEmpty() {
194         return (servers == null || servers.isEmpty()
195                 || (servers.size() == 1 && ("".equals(servers.get(0)))));
196     }
197
198     boolean isAdditionalPropsValid() {
199         return additionalProps != null;
200     }
201
202     boolean isTopicNullOrEmpty() {
203         return (topic == null || topic.trim().isEmpty());
204     }
205
206     boolean isPartitionIdNullOrEmpty() {
207         return (partitionId == null || partitionId.trim().isEmpty());
208     }
209
210     public static class TopicParamsBuilder {
211         BusTopicParams m = new BusTopicParams();
212
213         private TopicParamsBuilder() {
214         }
215
216         public TopicParamsBuilder servers(List<String> servers) {
217             this.m.servers = servers;
218             return this;
219         }
220
221         public TopicParamsBuilder topic(String topic) {
222             this.m.topic = topic;
223             return this;
224         }
225
226         public TopicParamsBuilder apiKey(String apiKey) {
227             this.m.apiKey = apiKey;
228             return this;
229         }
230
231         public TopicParamsBuilder apiSecret(String apiSecret) {
232             this.m.apiSecret = apiSecret;
233             return this;
234         }
235
236         public TopicParamsBuilder consumerGroup(String consumerGroup) {
237             this.m.consumerGroup = consumerGroup;
238             return this;
239         }
240
241         public TopicParamsBuilder consumerInstance(String consumerInstance) {
242             this.m.consumerInstance = consumerInstance;
243             return this;
244         }
245
246         public TopicParamsBuilder fetchTimeout(int fetchTimeout) {
247             this.m.fetchTimeout = fetchTimeout;
248             return this;
249         }
250
251         public TopicParamsBuilder fetchLimit(int fetchLimit) {
252             this.m.fetchLimit = fetchLimit;
253             return this;
254         }
255
256         public TopicParamsBuilder useHttps(boolean useHttps) {
257             this.m.useHttps = useHttps;
258             return this;
259         }
260
261         public TopicParamsBuilder allowSelfSignedCerts(boolean allowSelfSignedCerts) {
262             this.m.allowSelfSignedCerts = allowSelfSignedCerts;
263             return this;
264         }
265
266         public TopicParamsBuilder userName(String userName) {
267             this.m.userName = userName;
268             return this;
269         }
270
271         public TopicParamsBuilder password(String password) {
272             this.m.password = password;
273             return this;
274         }
275
276         public TopicParamsBuilder environment(String environment) {
277             this.m.environment = environment;
278             return this;
279         }
280
281         public TopicParamsBuilder aftEnvironment(String aftEnvironment) {
282             this.m.aftEnvironment = aftEnvironment;
283             return this;
284         }
285
286         public TopicParamsBuilder partner(String partner) {
287             this.m.partner = partner;
288             return this;
289         }
290
291         public TopicParamsBuilder latitude(String latitude) {
292             this.m.latitude = latitude;
293             return this;
294         }
295
296         public TopicParamsBuilder longitude(String longitude) {
297             this.m.longitude = longitude;
298             return this;
299         }
300
301         public TopicParamsBuilder additionalProps(Map<String, String> additionalProps) {
302             this.m.additionalProps = additionalProps;
303             return this;
304         }
305
306         public TopicParamsBuilder partitionId(String partitionId) {
307             this.m.partitionId = partitionId;
308             return this;
309         }
310
311         public BusTopicParams build() {
312             return m;
313         }
314
315     }
316 }
317