f8236d3d5db28d9da3f1be2df8475b12c3b1084e
[policy/common.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2020 Bell Canada. 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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.common.endpoints.event.comm.bus.internal;
23
24 import lombok.Getter;
25 import org.onap.policy.common.endpoints.event.comm.bus.ApiKeyEnabled;
26
27 /**
28  * Bus Topic Base.
29  */
30 @Getter
31 public abstract class BusTopicBase extends TopicBase implements ApiKeyEnabled {
32
33     /**
34      * API Key.
35      */
36     protected String apiKey;
37
38     /**
39      * API Secret.
40      */
41     protected String apiSecret;
42
43     /**
44      * Use https.
45      */
46     protected boolean useHttps;
47
48     /**
49      * Allow tracing.
50      */
51     protected boolean allowTracing;
52
53     /**
54      * allow self signed certificates.
55      */
56     protected boolean allowSelfSignedCerts;
57
58     /**
59      * Instantiates a new Bus Topic Base.
60      *
61      * <p>servers list of servers
62      *  topic topic name
63      *  apiKey API Key
64      *  apiSecret API Secret
65      *  useHttps does connection use HTTPS?
66      *  allowTracing Is tracing allowed?
67      *  allowSelfSignedCerts are self-signed certificates allow
68      * @param busTopicParams holds all our parameters
69      * @throws IllegalArgumentException if invalid parameters are present
70      */
71     protected BusTopicBase(BusTopicParams busTopicParams) {
72         super(busTopicParams.getServers(), busTopicParams.getTopic(), busTopicParams.getEffectiveTopic());
73         this.apiKey = busTopicParams.getApiKey();
74         this.apiSecret = busTopicParams.getApiSecret();
75         this.useHttps = busTopicParams.isUseHttps();
76         this.allowTracing = busTopicParams.isAllowTracing();
77         this.allowSelfSignedCerts = busTopicParams.isAllowSelfSignedCerts();
78     }
79
80     protected boolean anyNullOrEmpty(String... args) {
81         for (String arg : args) {
82             if (arg == null || arg.isEmpty()) {
83                 return true;
84             }
85         }
86
87         return false;
88     }
89
90     protected boolean allNullOrEmpty(String... args) {
91         for (String arg : args) {
92             if (!(arg == null || arg.isEmpty())) {
93                 return false;
94             }
95         }
96
97         return true;
98     }
99
100
101     @Override
102     public String toString() {
103         return "BusTopicBase [apiKey=" + apiKey + ", apiSecret=" + apiSecret + ", useHttps=" + useHttps
104                 + ", allowSelfSignedCerts=" + allowSelfSignedCerts + ", toString()=" + super.toString() + "]";
105     }
106
107 }