2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.dmaap.dbcapi.model;
23 import java.nio.charset.StandardCharsets;
24 import java.util.ArrayList;
25 import java.util.Date;
27 import javax.xml.bind.annotation.XmlRootElement;
29 import org.onap.dmaap.dbcapi.service.DmaapService;
33 public class Topic extends DmaapObject {
36 private String topicName;
37 private String topicDescription;
38 private String tnxEnabled;
40 private String formatUuid;
41 private ReplicationType replicationCase;
42 private String globalMrURL; // optional: URL of global MR to replicate to/from
44 private ArrayList<MR_Client> clients;
48 private static Dmaap dmaap = new DmaapService().getDmaap();
51 // utility function to generate the FQTN of a topic
52 public static String genFqtn( String name ) {
53 CharSequence signal = ".";
55 if ( name.contains( signal )) {
56 // presence of a dot indicates the name is already fully qualified
59 ret = dmaap.getTopicNsRoot() + "." + dmaap.getDmaapName() + "." + name;
68 this.clients = new ArrayList<MR_Client>();
69 this.lastMod = new Date();
70 this.replicationCase = ReplicationType.Validator("none");
72 logger.debug( "Topic constructor " + this.lastMod );
74 public Topic(String fqtn, String topicName, String topicDescription,
75 String tnxEnabled, String owner) {
78 this.topicName = topicName;
79 this.topicDescription = topicDescription;
80 //this.dcaeLocationName = dcaeLocationName;
81 this.tnxEnabled = tnxEnabled;
84 this.setStatus( DmaapObject_Status.NEW );
85 this.replicationCase = ReplicationType.Validator("none");
86 logger.debug( "Topic constructor " + this.getLastMod() );
88 public String getFqtn() {
91 public void setFqtn(String fqtn) {
94 public String getTopicName() {
97 public void setTopicName(String topicName) {
98 this.topicName = topicName;
100 public String getTopicDescription() {
101 return topicDescription;
103 public void setTopicDescription(String topicDescription) {
104 this.topicDescription = topicDescription;
107 public String getTnxEnabled() {
110 public void setTnxEnabled(String tnxEnabled) {
111 this.tnxEnabled = tnxEnabled;
113 public String getOwner() {
116 public void setOwner(String owner) {
121 public void setClients(ArrayList<MR_Client> clients) {
122 this.clients = clients;
125 public ArrayList<MR_Client> getClients() {
129 public int getNumClients() {
130 if ( this.clients == null ) {
133 return this.clients.size();
139 public String getFormatUuid() {
145 public void setFormatUuid(String formatUuid) {
146 this.formatUuid = formatUuid;
150 public ReplicationType getReplicationCase() {
151 return replicationCase;
157 public void setReplicationCase(String val) {
158 this.replicationCase = ReplicationType.Validator(val);
162 public void setReplicationCase(ReplicationType t) {
163 this.replicationCase = t;
167 public String getGlobalMrURL() {
173 public void setGlobalMrURL(String globalMrURL) {
174 this.globalMrURL = globalMrURL;
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();
190 public byte[] getBytes() {
191 return toProvJSON().getBytes(StandardCharsets.UTF_8);