Introduce default pub/sub Roles for Topic
[dmaap/dbcapi.git] / src / main / java / org / onap / dmaap / dbcapi / aaf / AafNamespace.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.aaf;
22
23 import java.util.ArrayList;
24
25 import org.apache.log4j.Logger;
26 import org.onap.dmaap.dbcapi.util.DmaapConfig;
27
28
29 public class AafNamespace extends AafObject  {
30         static final Logger logger = Logger.getLogger(AafNamespace.class);
31         
32         private String  name;
33         private ArrayList<String>       admin;
34         private ArrayList<String>       responsible;
35         
36         // in some environments, an AAF Namespace must be owned by a human.
37         // So, when needed, this var can be set via a property
38         static private String NsOwnerIdentity;
39         
40         public AafNamespace(String ns, String identity ) {
41                 super();
42                 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
43                 NsOwnerIdentity = p.getProperty( "aaf.NsOwnerIdentity", "");
44                 this.admin = new ArrayList<String>();
45                 this.responsible = new ArrayList<String>();
46                 
47                 this.name = ns;
48                 this.admin.add( identity );
49                 this.responsible.add( NsOwnerIdentity );
50         }
51         public void setName( String ns ) {
52                 this.name = ns;
53         }
54         public String getName() {
55                 return name;
56         }
57         public ArrayList<String> getAdmin() {
58                 return admin;
59         }
60         public void setAdmin(ArrayList<String> admin) {
61                 this.admin = admin;
62         }
63         public ArrayList<String> getResponsible() {
64                 return responsible;
65         }
66         public void setResponsible(ArrayList<String> responsible) {
67                 this.responsible = responsible;
68         }
69
70
71         // given an Array of Strings, return a String that is a separated list of quoted strings.
72         // e.g. input [ a, b, c ]
73         //       output  "a", "b", "c"
74         private String separatedList( ArrayList<String> list, String sep ) {
75                 if (list.isEmpty()) return null;
76                 String aList = new String();
77                 String delim = "";
78                 for( String item: list) {
79                         if( ! item.isEmpty()) {
80                                 aList += String.format( "%s\"%s\"", delim, item );
81                                 delim = sep;
82                         }
83                 }
84                 return aList;
85         }
86
87         public String toJSON() {
88
89                 String postJSON = String.format(" { \"name\": \"%s\", \"admin\": [", 
90                                 this.getName()
91                                  );
92                 postJSON += separatedList( this.getAdmin(), "," );
93                 postJSON += "], \"responsible\":[";
94                 postJSON += separatedList( this.getResponsible(), ",");
95                 postJSON += "]}";
96                 logger.info( "returning JSON: " + postJSON);
97                         
98                 return postJSON;
99         }
100         
101         
102         
103         
104 }