793260c0697bde197ca554f9138e9f0ca133ba19
[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  * Modifications Copyright (C) 2019 IBM.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.dmaap.dbcapi.aaf;
23
24 import java.util.ArrayList;
25
26 import org.apache.log4j.Logger;
27 import org.onap.dmaap.dbcapi.util.DmaapConfig;
28
29
30 public class AafNamespace extends AafObject  {
31         private static final Logger logger = Logger.getLogger(AafNamespace.class);
32         
33         private String  name;
34         private ArrayList<String> admin;
35         private ArrayList<String> responsible;
36         
37         // in some environments, an AAF Namespace must be owned by a human.
38         // So, when needed, this var can be set via a property
39         private static String NsOwnerIdentity;
40         
41         public AafNamespace(String ns, String identity ) {
42                 super();
43                 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
44                 NsOwnerIdentity = p.getProperty( "aaf.NsOwnerIdentity", "");
45                 this.admin = new ArrayList<>();
46                 this.responsible = new ArrayList<>();
47                 
48                 this.name = ns;
49                 this.admin.add( identity );
50                 this.responsible.add( NsOwnerIdentity );
51         }
52         public void setName( String ns ) {
53                 this.name = ns;
54         }
55         public String getName() {
56                 return name;
57         }
58         public ArrayList<String> getAdmin() {
59                 return admin;
60         }
61         public void setAdmin(ArrayList<String> admin) {
62                 this.admin = admin;
63         }
64         public ArrayList<String> getResponsible() {
65                 return responsible;
66         }
67         public void setResponsible(ArrayList<String> responsible) {
68                 this.responsible = responsible;
69         }
70
71
72         // given an Array of Strings, return a String that is a separated list of quoted strings.
73         // e.g. input [ a, b, c ]
74         //       output  "a", "b", "c"
75         private String separatedList( ArrayList<String> list, String sep ) {
76                 if (list.isEmpty()) return null;
77                 String aList = "";
78                 String delim = "";
79                 for( String item: list) {
80                         if( ! item.isEmpty()) {
81                                 aList += String.format( "%s\"%s\"", delim, item );
82                                 delim = sep;
83                         }
84                 }
85                 return aList;
86         }
87
88         public String toJSON() {
89
90                 String postJSON = String.format(" { \"name\": \"%s\", \"admin\": [", 
91                                 this.getName()
92                                  );
93                 postJSON += separatedList( this.getAdmin(), "," );
94                 postJSON += "], \"responsible\":[";
95                 postJSON += separatedList( this.getResponsible(), ",");
96                 postJSON += "]}";
97                 logger.info( "returning JSON: " + postJSON);
98                         
99                 return postJSON;
100         }
101         
102         
103         
104         
105 }