Replace cambria with DmaaP client
[dcaegen2/collectors/ves.git] / src / main / java / org / onap / dcae / common / publishing / PublisherConfig.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dcaegen2.collectors.ves
4  * ================================================================================
5  * Copyright (C) 2018,2021 Nokia. 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 package org.onap.dcae.common.publishing;
21
22 import io.vavr.collection.List;
23 import io.vavr.control.Option;
24
25 import java.util.Objects;
26
27 /**
28  * @author Pawel Szalapski (pawel.szalapski@nokia.com)
29  */
30 public final class PublisherConfig {
31
32     private final List<String> destinations;
33     private final String topic;
34     private String userName;
35     private String password;
36
37     PublisherConfig(List<String> destinations, String topic) {
38         this.destinations = destinations;
39         this.topic = topic;
40     }
41
42
43     PublisherConfig(List<String> destinations, String topic, String userName, String password) {
44         this.destinations = destinations;
45         this.topic = topic;
46         this.userName = userName;
47         this.password = password;
48     }
49
50     List<String> destinations() {
51         return destinations;
52     }
53
54     String getHostAndPort(){
55         return destinations.get(0);
56     }
57
58     String topic() {
59         return topic;
60     }
61
62     Option<String> userName() {
63         return Option.of(userName);
64     }
65
66     Option<String> password() {
67         return Option.of(password);
68     }
69
70     boolean isSecured() {
71         return userName().isDefined() && password().isDefined();
72     }
73
74
75     @Override
76     public boolean equals(Object o) {
77         if (this == o) {
78             return true;
79         }
80         if (o == null || getClass() != o.getClass()) {
81             return false;
82         }
83         PublisherConfig that = (PublisherConfig) o;
84         return Objects.equals(destinations, that.destinations) &&
85                 Objects.equals(topic, that.topic) &&
86                 Objects.equals(userName, that.userName) &&
87                 Objects.equals(password, that.password);
88     }
89
90     @Override
91     public int hashCode() {
92         return Objects.hash(destinations, topic, userName, password);
93     }
94
95     @Override
96     public String toString() {
97         return "PublisherConfig{" +
98                 "destinations=" + destinations +
99                 ", topic='" + topic + '\'' +
100                 ", userName='" + userName + '\'' +
101                 ", password='" + password + '\'' +
102                 '}';
103     }
104 }