2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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=========================================================
20 package org.onap.aai.schemagen.genxsd;
22 import org.apache.commons.lang3.StringUtils;
23 import org.onap.aai.schemagen.GenerateXsd;
27 public class NodeGetOperation {
28 static Map<String, Vector<String>> containers = new HashMap<String, Vector<String>>();
29 static ArrayList<String> checklist = createChecklist();
30 private static ArrayList<String> createChecklist()
32 ArrayList<String> list = new ArrayList<String>();
35 public static void addContainerProps(String container, Vector<String> containerProps) {
36 containers.put(container, containerProps);
38 public static void resetContainers() {
39 containers = new HashMap<String, Vector<String>>();
40 checklist = createChecklist();
42 private String useOpId;
43 private String xmlRootElementName;
46 private String CRUDpath;
47 private String pathParams;
48 private String queryParams;
50 public NodeGetOperation(String useOpId, String xmlRootElementName, String tag, String path, String pathParams) {
52 this.useOpId = useOpId;
53 this.xmlRootElementName = xmlRootElementName;
56 this.path = nodePath();
57 this.pathParams = pathParams;
58 StringBuilder p = new StringBuilder();
60 if(containers.get(xmlRootElementName) == null) {
61 this.queryParams = "";
63 this.queryParams= String.join("", containers.get(xmlRootElementName));
64 for(String param : containers.get(xmlRootElementName)) {
67 this.queryParams = p.toString();
72 int loc = CRUDpath.indexOf(xmlRootElementName);
74 path = "/nodes/"+CRUDpath.substring(loc);
79 public String toString() {
81 st = new StringTokenizer(CRUDpath, "/");
82 //Path has to be longer than one element
84 if ( st.countTokens() <= 1) {
88 //a valid tag is necessary
89 if ( StringUtils.isEmpty(tag) ) {
92 if ( CRUDpath.endsWith("/relationship") ) {
95 if ( CRUDpath.contains("/relationship/") ) { // filter paths with relationship-list
98 if ( CRUDpath.endsWith("/relationship-list")) {
101 if ( CRUDpath.startsWith("/search")) {
104 if ( CRUDpath.startsWith("/actions")) {
107 if ( CRUDpath.startsWith("/nodes")) {
110 if (checklist.contains(xmlRootElementName)) {
113 StringBuffer pathSb = new StringBuffer();
114 //Drop out the operations with multiple path parameters
115 if(CRUDpath.lastIndexOf('{') > CRUDpath.indexOf('{') && StringUtils.isNotEmpty(pathParams)) {
118 if(path.lastIndexOf('{') > path.indexOf('{') ) {
121 //trim leading path elements before the current node type
122 // int loc = path.indexOf(xmlRootElementName);
124 // path = "/nodes/"+path.substring(loc);
126 //append generic parameter syntax to all plural queries
127 if(path.indexOf('{') == -1) {
128 path += "?parameter=value[¶meter2=value2]";
130 pathSb.append(" " + path + ":\n" );
131 pathSb.append(" get:\n");
132 pathSb.append(" tags:\n");
133 pathSb.append(" - Operations" + "\n");
134 pathSb.append(" summary: returns " + xmlRootElementName + "\n");
136 pathSb.append(" description: returns " + xmlRootElementName + "\n");
137 pathSb.append(" operationId: get" + useOpId + "\n");
138 pathSb.append(" produces:\n");
139 pathSb.append(" - application/json\n");
140 pathSb.append(" - application/xml\n");
142 pathSb.append(" responses:\n");
143 pathSb.append(" \"200\":\n");
144 pathSb.append(" description: successful operation\n");
145 pathSb.append(" schema:\n");
146 pathSb.append(" $ref: \"#/definitions/" + xmlRootElementName + "\"\n");
147 pathSb.append(" \"default\":\n");
148 pathSb.append(" " + GenerateXsd.getResponsesUrl());
149 if ( StringUtils.isNotEmpty(pathParams) || StringUtils.isNotEmpty(queryParams)) {
150 pathSb.append("\n parameters:\n");
152 if ( StringUtils.isNotEmpty(pathParams)) {
153 pathSb.append(pathParams);
155 if ( StringUtils.isNotEmpty(pathParams) && StringUtils.isNotEmpty(queryParams)) {
158 if ( StringUtils.isNotEmpty(queryParams)) {
159 pathSb.append(queryParams);
161 checklist.add(xmlRootElementName);
162 return pathSb.toString();