[DMAAP-BC] Consolidate bus controller repos
[dmaap/buscontroller.git] / dmaap-bc / src / main / java / org / onap / dmaap / dbcapi / model / DR_Pub.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dmaap
4  * ================================================================================
5  * Copyright (C) 2017 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.dmaap.dbcapi.model;
22
23 import javax.xml.bind.annotation.XmlRootElement;
24
25 import org.onap.dmaap.dbcapi.util.RandomString;
26
27 import java.util.Objects;
28
29 @XmlRootElement
30 public class DR_Pub extends DmaapObject {
31
32         private String dcaeLocationName;
33         private String username;
34         private String userpwd;
35         private String feedId;
36         private String pubId;
37         
38         // NOTE: the following fields are optional in the API but not stored in the DB
39         private String  feedName;
40         private String  feedVersion;
41
42         
43         public DR_Pub() {
44                 status = DmaapObject_Status.EMPTY;
45                 
46         }
47         
48         public DR_Pub( String dLN ) {
49                 this.dcaeLocationName = dLN;
50                 this.status = DmaapObject_Status.STAGED;
51         }
52         
53         public DR_Pub( String dLN, 
54                                         String uN,
55                                         String uP,
56                                         String fI,
57                                         String pI ) {
58                 this.dcaeLocationName = dLN;
59                 this.username = uN;
60                 this.userpwd = uP;
61                 this.feedId = fI;
62                 this.pubId = pI;
63                 this.status = DmaapObject_Status.VALID;
64         }
65
66
67         public DR_Pub( String dLN, 
68                                                         String uN,
69                                                         String uP,
70                                                         String fI ) {
71                 this.dcaeLocationName = dLN;
72                 this.username = uN;
73                 this.userpwd = uP;
74                 this.feedId = fI;
75                 this.pubId = fI + "." +  DR_Pub.nextKey();
76                 this.status = DmaapObject_Status.VALID; 
77         }
78                         
79
80         public String getDcaeLocationName() {
81                 return dcaeLocationName;
82         }
83
84         public void setDcaeLocationName(String dcaeLocationName) {
85                 this.dcaeLocationName = dcaeLocationName;
86         }
87
88         public String getUsername() {
89                 return username;
90         }
91
92         public void setUsername(String username) {
93                 this.username = username;
94         }
95
96         public String getUserpwd() {
97                 return userpwd;
98         }
99
100         public void setUserpwd(String userpwd) {
101                 this.userpwd = userpwd;
102         }
103
104         public String getFeedId() {
105                 return feedId;
106         }
107
108         public void setFeedId(String feedId) {
109                 this.feedId = feedId;
110         }
111
112         public String getPubId() {
113                 return pubId;
114         }
115
116         public void setPubId(String pubId) {
117                 this.pubId = pubId;
118         }
119         
120         public void setNextPubId() {
121                 this.pubId = this.feedId + "." +  DR_Pub.nextKey();
122         }
123         
124         public String getFeedName() {
125                 return feedName;
126         }
127
128         public void setFeedName(String feedName) {
129                 this.feedName = feedName;
130         }
131
132         public String getFeedVersion() {
133                 return feedVersion;
134         }
135
136         public void setFeedVersion(String feedVersion) {
137                 this.feedVersion = feedVersion;
138         }
139
140         public DR_Pub setRandomUserName() {
141                 RandomString r = new RandomString(15);
142                 this.username = "tmp_" + r.nextString();        
143                 return this;
144         }
145         public DR_Pub setRandomPassword() {
146                 RandomString r = new RandomString(15);
147                 this.userpwd = r.nextString();
148                 return this;
149         }
150
151         public static String nextKey() {
152                 RandomString ri = new RandomString(5);
153                 return ri.nextString();
154                 
155         }
156
157         @Override
158         public boolean equals(Object o) {
159                 if (this == o) return true;
160                 if (o == null || getClass() != o.getClass()) return false;
161                 DR_Pub dr_pub = (DR_Pub) o;
162                 return Objects.equals(dcaeLocationName, dr_pub.dcaeLocationName) &&
163                                 Objects.equals(username, dr_pub.username) &&
164                                 Objects.equals(userpwd, dr_pub.userpwd) &&
165                                 Objects.equals(feedId, dr_pub.feedId) &&
166                                 Objects.equals(pubId, dr_pub.pubId);
167         }
168
169         @Override
170         public int hashCode() {
171
172                 return Objects.hash(dcaeLocationName, username, userpwd, feedId, pubId);
173         }
174
175         @Override
176         public String toString() {
177                 return "DR_Pub{" +
178                                 "dcaeLocationName='" + dcaeLocationName + '\'' +
179                                 ", username='" + username + '\'' +
180                                 ", userpwd='" + userpwd + '\'' +
181                                 ", feedId='" + feedId + '\'' +
182                                 ", pubId='" + pubId + '\'' +
183                                 ", feedName='" + feedName + '\'' +
184                                 ", feedVersion='" + feedVersion + '\'' +
185                                 '}';
186         }
187 }