2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
6 * Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.common.endpoints.event.comm.bus.internal;
24 import java.util.List;
26 import org.apache.commons.lang3.StringUtils;
29 * Member variables of this Params class are as follows.
31 * <p>servers DMaaP servers
32 * topic DMaaP Topic to be monitored
33 * apiKey DMaaP API Key (optional)
34 * apiSecret DMaaP API Secret (optional)
35 * consumerGroup DMaaP Reader Consumer Group
36 * consumerInstance DMaaP Reader Instance
37 * fetchTimeout DMaaP fetch timeout
38 * fetchLimit DMaaP fetch limit
39 * environment DME2 Environment
40 * aftEnvironment DME2 AFT Environment
41 * partner DME2 Partner
42 * latitude DME2 Latitude
43 * longitude DME2 Longitude
44 * additionalProps Additional properties to pass to DME2
45 * useHttps does connection use HTTPS?
46 * allowSelfSignedCerts are self-signed certificates allow
48 public class BusTopicParams {
51 private List<String> servers;
52 private Map<String, String> additionalProps;
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 private boolean managed;
64 private String userName;
65 private String password;
66 private String environment;
67 private String aftEnvironment;
68 private String partner;
69 private String latitude;
70 private String longitude;
71 private String partitionId;
72 private String clientName;
73 private String hostname;
74 private String basePath;
76 public static TopicParamsBuilder builder() {
77 return new TopicParamsBuilder();
80 public String getPartitionId() {
84 public String getUserName() {
88 public String getPassword() {
92 public String getEnvironment() {
96 public String getAftEnvironment() {
97 return aftEnvironment;
100 public String getPartner() {
104 public String getLatitude() {
108 public String getLongitude() {
112 public Map<String, String> getAdditionalProps() {
113 return additionalProps;
116 public List<String> getServers() {
120 public String getTopic() {
124 public String getApiKey() {
128 public String getApiSecret() {
132 public String getConsumerGroup() {
133 return consumerGroup;
136 public String getConsumerInstance() {
137 return consumerInstance;
140 public int getFetchTimeout() {
144 public int getFetchLimit() {
148 public String getClientName() {
152 public String getHostname() {
156 public int getPort() {
160 public String getBasePath() {
164 public boolean isManaged() {
168 public boolean isUseHttps() {
172 public boolean isAllowSelfSignedCerts() {
173 return allowSelfSignedCerts;
177 * Methods to Check if the property is INVALID.
180 boolean isEnvironmentInvalid() {
181 return StringUtils.isBlank(environment);
184 boolean isAftEnvironmentInvalid() {
185 return StringUtils.isBlank(aftEnvironment);
188 boolean isLatitudeInvalid() {
189 return StringUtils.isBlank(latitude);
192 boolean isLongitudeInvalid() {
193 return StringUtils.isBlank(longitude);
196 boolean isConsumerInstanceInvalid() {
197 return StringUtils.isBlank(consumerInstance);
200 boolean isConsumerGroupInvalid() {
201 return StringUtils.isBlank(consumerGroup);
204 public boolean isClientNameInvalid() {
205 return StringUtils.isBlank(clientName);
208 boolean isPartnerInvalid() {
209 return StringUtils.isBlank(partner);
212 boolean isServersInvalid() {
213 return (servers == null || servers.isEmpty()
214 || (servers.size() == 1 && ("".equals(servers.get(0)))));
217 boolean isTopicInvalid() {
218 return StringUtils.isBlank(topic);
221 boolean isPartitionIdInvalid() {
222 return StringUtils.isBlank(partitionId);
225 public boolean isHostnameInvalid() {
226 return StringUtils.isBlank(hostname);
229 public boolean isPortInvalid() {
230 return (getPort() <= 0 || getPort() >= 65535);
234 * Methods to Check if the property is Valid.
237 boolean isApiKeyValid() {
238 return StringUtils.isNotBlank(apiKey);
241 boolean isApiSecretValid() {
242 return StringUtils.isNotBlank(apiSecret);
245 boolean isUserNameValid() {
246 return StringUtils.isNotBlank(userName);
249 boolean isPasswordValid() {
250 return StringUtils.isNotBlank(password);
253 boolean isAdditionalPropsValid() {
254 return additionalProps != null;
257 public static class TopicParamsBuilder {
259 final BusTopicParams params = new BusTopicParams();
261 private TopicParamsBuilder() {
264 public TopicParamsBuilder servers(List<String> servers) {
265 this.params.servers = servers;
269 public TopicParamsBuilder topic(String topic) {
270 this.params.topic = topic;
274 public TopicParamsBuilder apiKey(String apiKey) {
275 this.params.apiKey = apiKey;
279 public TopicParamsBuilder apiSecret(String apiSecret) {
280 this.params.apiSecret = apiSecret;
284 public TopicParamsBuilder consumerGroup(String consumerGroup) {
285 this.params.consumerGroup = consumerGroup;
289 public TopicParamsBuilder consumerInstance(String consumerInstance) {
290 this.params.consumerInstance = consumerInstance;
294 public TopicParamsBuilder fetchTimeout(int fetchTimeout) {
295 this.params.fetchTimeout = fetchTimeout;
299 public TopicParamsBuilder fetchLimit(int fetchLimit) {
300 this.params.fetchLimit = fetchLimit;
304 public TopicParamsBuilder useHttps(boolean useHttps) {
305 this.params.useHttps = useHttps;
309 public TopicParamsBuilder allowSelfSignedCerts(boolean allowSelfSignedCerts) {
310 this.params.allowSelfSignedCerts = allowSelfSignedCerts;
314 public TopicParamsBuilder userName(String userName) {
315 this.params.userName = userName;
319 public TopicParamsBuilder password(String password) {
320 this.params.password = password;
324 public TopicParamsBuilder environment(String environment) {
325 this.params.environment = environment;
329 public TopicParamsBuilder aftEnvironment(String aftEnvironment) {
330 this.params.aftEnvironment = aftEnvironment;
334 public TopicParamsBuilder partner(String partner) {
335 this.params.partner = partner;
339 public TopicParamsBuilder latitude(String latitude) {
340 this.params.latitude = latitude;
344 public TopicParamsBuilder longitude(String longitude) {
345 this.params.longitude = longitude;
349 public TopicParamsBuilder additionalProps(Map<String, String> additionalProps) {
350 this.params.additionalProps = additionalProps;
354 public TopicParamsBuilder partitionId(String partitionId) {
355 this.params.partitionId = partitionId;
359 public BusTopicParams build() {
363 public TopicParamsBuilder managed(boolean managed) {
364 this.params.managed = managed;
368 public TopicParamsBuilder hostname(String hostname) {
369 this.params.hostname = hostname;
373 public TopicParamsBuilder clientName(String clientName) {
374 this.params.clientName = clientName;
378 public TopicParamsBuilder port(int port) {
379 this.params.port = port;
383 public TopicParamsBuilder basePath(String basePath) {
384 this.params.basePath = basePath;