[DMAAP-BC] Consolidate bus controller repos
[dmaap/buscontroller.git] / dmaap-bc / src / main / java / org / onap / dmaap / dbcapi / model / MR_Client.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 java.util.Date;
24
25 import javax.xml.bind.annotation.XmlRootElement;
26
27 import org.onap.dmaap.dbcapi.database.DatabaseClass;
28
29 import io.swagger.annotations.ApiModelProperty;
30
31 @XmlRootElement
32 public class MR_Client extends DmaapObject {
33
34         @ApiModelProperty( value="a tag indicating a logical deployment site")
35         private String dcaeLocationName;
36         @ApiModelProperty( value="the URL for a MR instance - typically in the same dcaeLocation - that this client should use to access the topic")
37         private String  topicURL;
38         @ApiModelProperty( value="Fully Qualified Topic Name constructed by dbcapi")
39         private String fqtn;
40         @ApiModelProperty( value="an AAF Role to be granted an appropriate Permission.  If specified, takes precedence over clientIdentity, for backwards compatibility.")
41         private String clientRole;
42         @ApiModelProperty( value="one or more actions from the set (\"pub\", \"sub\", \"view\") for which this client needs Permission")
43         private String[] action;
44         @ApiModelProperty( value="a unique identifier generated by dbcapi for this client")
45         private String mrClientId;
46         @ApiModelProperty( value="an AAF identity to be associated to an appropriate topic Role")
47         private String clientIdentity;
48         
49
50         public MR_Client() {
51                 this.mrClientId = DatabaseClass.getNextClientId();
52                 this.lastMod = new Date();
53                 this.setLastMod();
54                 debugLogger.debug( "MR_Client constructor " + this.lastMod );
55                         
56         }
57         
58         public MR_Client( String dLN,
59                                         String f,
60                                         String cR,
61                                         String[] a ) {
62                 this.dcaeLocationName = dLN;
63                 this.fqtn = f;
64                 this.clientRole = cR;
65                 int i = 0;
66                 
67                 if (a != null) {
68                         this.action = new String[a.length];
69                         for (String aa : a) {
70                                 this.action[i++] = new String(aa);
71                         }
72                 }
73                 this.setStatus( DmaapObject_Status.NEW );
74                 this.mrClientId = DatabaseClass.getNextClientId();
75                 this.setLastMod();
76                 debugLogger.debug( "MR_Client constructor w initialization " + this.lastMod );
77         }
78
79         public String getDcaeLocationName() {
80                 return dcaeLocationName;
81         }
82
83         public void setDcaeLocationName(String dcaeLocationName) {
84                 this.dcaeLocationName = dcaeLocationName;
85         }
86
87         public String getFqtn() {
88                 return fqtn;
89         }
90
91         public void setFqtn(String fqtn) {
92                 this.fqtn = fqtn;
93         }
94
95         public String getClientRole() {
96                 return clientRole;
97         }
98
99         public void setClientRole(String clientRole) {
100                 this.clientRole = clientRole;
101         }
102
103         public String[] getAction() {
104                 return action;
105         }
106
107         public void setAction(String[] action) {
108                 this.action = action;
109         }
110         
111         @ApiModelProperty( hidden=true )
112         public boolean isPublisher() {
113                 return hasAction( "pub");
114         }
115         @ApiModelProperty( hidden=true )
116         public boolean isSubscriber() {
117                 return hasAction( "sub");
118         }
119         
120         public boolean hasAction( String val ) {
121                 for (String s: this.action) {
122                         if ( s!= null && s.equals(val)) {
123                                 return true;
124                         }
125                 }
126                 return false;
127         }
128         public String getMrClientId() {
129                 return mrClientId;
130         }
131
132         public void setMrClientId(String mrClientId) {
133                 this.mrClientId = mrClientId;
134         }
135
136
137
138         public String getTopicURL() {
139                 return topicURL;
140         }
141
142         public void setTopicURL(String topicURL) {
143                 this.topicURL = topicURL;
144         }
145
146         public String getClientIdentity() {
147                 return clientIdentity;
148         }
149
150         public void setClientIdentity(String clientIdentity) {
151                 this.clientIdentity = clientIdentity;
152         }
153         public boolean hasClientIdentity() {
154                 if ( this.clientIdentity == null || this.clientIdentity.isEmpty() ) {
155                         return false;
156                 } else {
157                         return true;
158                 }
159         }
160
161         
162 }