67ee84e54f8334cede2d6c536aff09ee4e174ffa
[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 self signed certificates.
50      */
51     protected boolean allowSelfSignedCerts;
52
53     /**
54      * Instantiates a new Bus Topic Base.
55      *
56      * <p>servers list of servers
57      *  topic topic name
58      *  apiKey API Key
59      *  apiSecret API Secret
60      *  useHttps does connection use HTTPS?
61      *  allowSelfSignedCerts are self-signed certificates allow
62      * @param busTopicParams holds all our parameters
63      * @throws IllegalArgumentException if invalid parameters are present
64      */
65     protected BusTopicBase(BusTopicParams busTopicParams) {
66         super(busTopicParams.getServers(), busTopicParams.getTopic(), busTopicParams.getEffectiveTopic());
67         this.apiKey = busTopicParams.getApiKey();
68         this.apiSecret = busTopicParams.getApiSecret();
69         this.useHttps = busTopicParams.isUseHttps();
70         this.allowSelfSignedCerts = busTopicParams.isAllowSelfSignedCerts();
71     }
72
73     protected boolean anyNullOrEmpty(String... args) {
74         for (String arg : args) {
75             if (arg == null || arg.isEmpty()) {
76                 return true;
77             }
78         }
79
80         return false;
81     }
82
83     protected boolean allNullOrEmpty(String... args) {
84         for (String arg : args) {
85             if (!(arg == null || arg.isEmpty())) {
86                 return false;
87             }
88         }
89
90         return true;
91     }
92
93
94     @Override
95     public String toString() {
96         return "BusTopicBase [apiKey=" + apiKey + ", apiSecret=" + apiSecret + ", useHttps=" + useHttps
97                 + ", allowSelfSignedCerts=" + allowSelfSignedCerts + ", toString()=" + super.toString() + "]";
98     }
99
100 }