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