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