6dd6a3ebfbfe5fd28f7d8bacf3005ef6cc322267
[policy/common.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2017-2019 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 org.onap.policy.common.endpoints.event.comm.bus.ApiKeyEnabled;
25
26 /**
27  * Bus Topic Base.
28  */
29 public abstract class BusTopicBase extends TopicBase implements ApiKeyEnabled {
30
31     /**
32      * API Key.
33      */
34     protected String apiKey;
35
36     /**
37      * API Secret.
38      */
39     protected String apiSecret;
40
41     /**
42      * Use https.
43      */
44     protected boolean useHttps;
45
46     /**
47      * allow self signed certificates.
48      */
49     protected boolean allowSelfSignedCerts;
50
51     /**
52      * Instantiates a new Bus Topic Base.
53      *
54      * <p>servers list of servers
55      *  topic topic name
56      *  apiKey API Key
57      *  apiSecret API Secret
58      *  useHttps does connection use HTTPS?
59      *  allowSelfSignedCerts are self-signed certificates allow
60      * @param busTopicParams holds all our parameters
61      * @throws IllegalArgumentException if invalid parameters are present
62      */
63     protected BusTopicBase(BusTopicParams busTopicParams) {
64         super(busTopicParams.getServers(), busTopicParams.getTopic(), busTopicParams.getEffectiveTopic());
65         this.apiKey = busTopicParams.getApiKey();
66         this.apiSecret = busTopicParams.getApiSecret();
67         this.useHttps = busTopicParams.isUseHttps();
68         this.allowSelfSignedCerts = busTopicParams.isAllowSelfSignedCerts();
69     }
70
71     @Override
72     public String getApiKey() {
73         return apiKey;
74     }
75
76     @Override
77     public String getApiSecret() {
78         return apiSecret;
79     }
80
81     /**
82      * Is using HTTPS.
83      *
84      * @return if using https
85      */
86     public boolean isUseHttps() {
87         return useHttps;
88     }
89
90     /**
91      * Is self signed certificates allowed.
92      *
93      * @return if self signed certificates are allowed
94      */
95     public boolean isAllowSelfSignedCerts() {
96         return allowSelfSignedCerts;
97     }
98
99     protected boolean anyNullOrEmpty(String... args) {
100         for (String arg : args) {
101             if (arg == null || arg.isEmpty()) {
102                 return true;
103             }
104         }
105
106         return false;
107     }
108
109     protected boolean allNullOrEmpty(String... args) {
110         for (String arg : args) {
111             if (!(arg == null || arg.isEmpty())) {
112                 return false;
113             }
114         }
115
116         return true;
117     }
118
119
120     @Override
121     public String toString() {
122         return "BusTopicBase [apiKey=" + apiKey + ", apiSecret=" + apiSecret + ", useHttps=" + useHttps
123                 + ", allowSelfSignedCerts=" + allowSelfSignedCerts + ", toString()=" + super.toString() + "]";
124     }
125
126 }