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.util.genxsd;
22 import java.util.ArrayList;
23 import java.util.HashMap;
25 import java.util.StringTokenizer;
26 import java.util.Vector;
28 import org.apache.commons.lang3.StringUtils;
29 import org.onap.aai.util.GenerateXsd;
31 public class NodeGetOperation {
32 static Map<String, Vector<String>> containers = new HashMap<String, Vector<String>>();
33 static ArrayList<String> checklist = createChecklist();
34 private static ArrayList<String> createChecklist()
36 ArrayList<String> list = new ArrayList<String>();
39 public static void addContainerProps(String container, Vector<String> containerProps) {
40 containers.put(container, containerProps);
42 public static void resetContainers() {
43 containers = new HashMap<String, Vector<String>>();
44 checklist = createChecklist();
46 private String useOpId;
47 private String xmlRootElementName;
50 private String CRUDpath;
51 private String pathParams;
52 private String queryParams;
54 public NodeGetOperation(String useOpId, String xmlRootElementName, String tag, String path, String pathParams) {
56 this.useOpId = useOpId;
57 this.xmlRootElementName = xmlRootElementName;
60 this.path = nodePath();
61 this.pathParams = pathParams;
62 StringBuilder p = new StringBuilder();
64 if(containers.get(xmlRootElementName) == null) {
65 this.queryParams = "";
67 this.queryParams= String.join("", containers.get(xmlRootElementName));
68 for(String param : containers.get(xmlRootElementName)) {
71 this.queryParams = p.toString();
76 int loc = CRUDpath.indexOf(xmlRootElementName);
78 path = "/nodes/"+CRUDpath.substring(loc);
83 public String toString() {
85 st = new StringTokenizer(CRUDpath, "/");
86 //Path has to be longer than one element
88 if ( st.countTokens() <= 1) {
92 //a valid tag is necessary
93 if ( StringUtils.isEmpty(tag) ) {
96 if ( CRUDpath.endsWith("/relationship") ) {
99 if ( CRUDpath.contains("/relationship/") ) { // filter paths with relationship-list
102 if ( CRUDpath.endsWith("/relationship-list")) {
105 if ( CRUDpath.startsWith("/search")) {
108 if ( CRUDpath.startsWith("/actions")) {
111 if ( CRUDpath.startsWith("/nodes")) {
114 if (checklist.contains(xmlRootElementName)) {
117 StringBuffer pathSb = new StringBuffer();
118 //Drop out the operations with multiple path parameters
119 if(CRUDpath.lastIndexOf('{') > CRUDpath.indexOf('{') && StringUtils.isNotEmpty(pathParams)) {
122 if(path.lastIndexOf('{') > path.indexOf('{') ) {
125 //trim leading path elements before the current node type
126 // int loc = path.indexOf(xmlRootElementName);
128 // path = "/nodes/"+path.substring(loc);
130 //append generic parameter syntax to all plural queries
131 if(path.indexOf('{') == -1) {
132 path += "?parameter=value[¶meter2=value2]";
134 pathSb.append(" " + path + ":\n" );
135 pathSb.append(" get:\n");
136 pathSb.append(" tags:\n");
137 pathSb.append(" - Operations" + "\n");
138 pathSb.append(" summary: returns " + xmlRootElementName + "\n");
140 pathSb.append(" description: returns " + xmlRootElementName + "\n");
141 pathSb.append(" operationId: get" + useOpId + "\n");
142 pathSb.append(" produces:\n");
143 pathSb.append(" - application/json\n");
144 pathSb.append(" - application/xml\n");
146 pathSb.append(" responses:\n");
147 pathSb.append(" \"200\":\n");
148 pathSb.append(" description: successful operation\n");
149 pathSb.append(" schema:\n");
150 pathSb.append(" $ref: \"#/definitions/" + xmlRootElementName + "\"\n");
151 pathSb.append(" \"default\":\n");
152 pathSb.append(" " + GenerateXsd.getResponsesUrl());
153 if ( StringUtils.isNotEmpty(pathParams) || StringUtils.isNotEmpty(queryParams)) {
154 pathSb.append("\n parameters:\n");
156 if ( StringUtils.isNotEmpty(pathParams)) {
157 pathSb.append(pathParams);
159 if ( StringUtils.isNotEmpty(pathParams) && StringUtils.isNotEmpty(queryParams)) {
162 if ( StringUtils.isNotEmpty(queryParams)) {
163 pathSb.append(queryParams);
165 checklist.add(xmlRootElementName);
166 return pathSb.toString();