DMAAP-83 Initial code import
[dmaap/dbcapi.git] / src / main / java / org / onap / dmaap / dbcapi / model / Topic.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.nio.charset.StandardCharsets;
24 import java.util.ArrayList;
25 import java.util.Date;
26
27 import javax.xml.bind.annotation.XmlRootElement;
28
29 import org.onap.dmaap.dbcapi.service.DmaapService;
30
31
32 @XmlRootElement
33 public class Topic extends DmaapObject  {
34
35         private String fqtn;
36         private String topicName;
37         private String  topicDescription;
38         private String  tnxEnabled;
39         private String  owner;
40         private String  formatUuid;
41         private ReplicationType replicationCase;  
42         private String  globalMrURL;            // optional: URL of global MR to replicate to/from
43
44         private ArrayList<MR_Client> clients;
45
46
47         
48         private static Dmaap dmaap = new DmaapService().getDmaap();
49         
50         //
51         // utility function to generate the FQTN of a topic
52         public static String genFqtn(  String name ) {
53                 CharSequence signal = ".";
54                 String ret;
55                 if ( name.contains( signal )) {
56                         // presence of a dot indicates the name is already fully qualified
57                         ret = name;
58                 } else {
59                         ret = dmaap.getTopicNsRoot() + "." + dmaap.getDmaapName() + "." + name;
60                 }
61                 return ret;
62         }
63
64
65
66         public Topic() {
67                 super();
68                 this.clients = new ArrayList<MR_Client>();
69                 this.lastMod = new Date();
70                 this.replicationCase = ReplicationType.Validator("none");
71                 this.setLastMod();
72                 logger.debug( "Topic constructor " + this.lastMod );
73         }
74         public Topic(String fqtn, String topicName, String topicDescription,
75                          String tnxEnabled, String owner) {
76                 super();
77                 this.fqtn = fqtn;
78                 this.topicName = topicName;
79                 this.topicDescription = topicDescription;
80                 //this.dcaeLocationName = dcaeLocationName;
81                 this.tnxEnabled = tnxEnabled;
82                 this.owner = owner;
83                 this.setLastMod();
84                 this.setStatus( DmaapObject_Status.NEW );
85                 this.replicationCase = ReplicationType.Validator("none");
86                 logger.debug( "Topic constructor " + this.getLastMod() );
87         }
88         public String getFqtn() {
89                 return fqtn;
90         }
91         public void setFqtn(String fqtn) {
92                 this.fqtn = fqtn;
93         }
94         public String getTopicName() {
95                 return topicName;
96         }
97         public void setTopicName(String topicName) {
98                 this.topicName = topicName;
99         }
100         public String getTopicDescription() {
101                 return topicDescription;
102         }
103         public void setTopicDescription(String topicDescription) {
104                 this.topicDescription = topicDescription;
105         }
106
107         public String getTnxEnabled() {
108                 return tnxEnabled;
109         }
110         public void setTnxEnabled(String tnxEnabled) {
111                 this.tnxEnabled = tnxEnabled;
112         }
113         public String getOwner() {
114                 return owner;
115         }
116         public void setOwner(String owner) {
117                 this.owner = owner;
118         }
119
120
121         public void setClients(ArrayList<MR_Client> clients) {
122                 this.clients = clients;
123         }
124
125         public ArrayList<MR_Client> getClients() {
126                 return clients;
127         }
128
129         public int getNumClients() {
130                 if ( this.clients == null ) {
131                         return 0;
132                 }
133                 return this.clients.size();
134         }
135
136
137
138
139         public String getFormatUuid() {
140                 return formatUuid;
141         }
142
143
144
145         public void setFormatUuid(String formatUuid) {
146                 this.formatUuid = formatUuid;
147         }
148
149
150         public ReplicationType getReplicationCase() {
151                 return replicationCase;
152         }
153
154
155
156         /*
157         public void setReplicationCase(String val) {
158                 this.replicationCase = ReplicationType.Validator(val);
159         }
160         */
161         
162         public void setReplicationCase(ReplicationType t) {
163                 this.replicationCase = t;
164         }
165
166
167         public String getGlobalMrURL() {
168                 return globalMrURL;
169         }
170
171
172
173         public void setGlobalMrURL(String globalMrURL) {
174                 this.globalMrURL = globalMrURL;
175         }
176
177
178
179         public String toProvJSON() {
180                 StringBuilder str = new StringBuilder();
181                 str.append("{ \"topicName\": \"");
182                 str.append( this.getFqtn() );
183                 str.append( "\", \"topicDescription\": \"");
184                 str.append( this.getTopicDescription());
185                 str.append( "\", \"partitionCount\": \"2\", \"replicationCount\": \"1\" } ");
186                 logger.info( str.toString() );
187                 return str.toString();
188         }
189         
190         public byte[] getBytes() {
191                 return toProvJSON().getBytes(StandardCharsets.UTF_8);
192         }
193 }