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=========================================================
21 package org.onap.aai.schemagen.genxsd;
23 import java.util.ArrayList;
24 import java.util.HashMap;
26 import java.util.StringTokenizer;
27 import java.util.Vector;
29 import org.apache.commons.lang3.StringUtils;
30 import org.onap.aai.schemagen.GenerateXsd;
32 public class NodeGetOperation {
33 static Map<String, Vector<String>> containers = new HashMap<String, Vector<String>>();
34 static ArrayList<String> checklist = createChecklist();
36 private static ArrayList<String> createChecklist() {
37 ArrayList<String> list = new ArrayList<String>();
41 public static void addContainerProps(String container, Vector<String> containerProps) {
42 containers.put(container, containerProps);
45 public static void resetContainers() {
46 containers = new HashMap<String, Vector<String>>();
47 checklist = createChecklist();
50 private String useOpId;
51 private String xmlRootElementName;
54 private String CRUDpath;
55 private String pathParams;
56 private String queryParams;
58 public NodeGetOperation(String useOpId, String xmlRootElementName, String tag, String path,
61 this.useOpId = useOpId;
62 this.xmlRootElementName = xmlRootElementName;
65 this.path = nodePath();
66 this.pathParams = pathParams;
67 StringBuilder p = new StringBuilder();
69 if (containers.get(xmlRootElementName) == null) {
70 this.queryParams = "";
72 this.queryParams = String.join("", containers.get(xmlRootElementName));
73 for (String param : containers.get(xmlRootElementName)) {
76 this.queryParams = p.toString();
82 int loc = CRUDpath.indexOf(xmlRootElementName);
84 path = "/nodes/" + CRUDpath.substring(loc);
90 public String toString() {
92 st = new StringTokenizer(CRUDpath, "/");
93 // Path has to be longer than one element
95 * if ( st.countTokens() <= 1) {
99 // a valid tag is necessary
100 if (StringUtils.isEmpty(tag)) {
103 if (CRUDpath.endsWith("/relationship")) {
106 if (CRUDpath.contains("/relationship/")) { // filter paths with relationship-list
109 if (CRUDpath.endsWith("/relationship-list")) {
112 if (CRUDpath.startsWith("/search")) {
115 if (CRUDpath.startsWith("/actions")) {
118 if (CRUDpath.startsWith("/nodes")) {
121 if (checklist.contains(xmlRootElementName)) {
124 StringBuilder pathSb = new StringBuilder();
125 if (path.indexOf('{') == -1) {
126 path += "?parameter=value[¶meter2=value2]";
128 pathSb.append(" ").append(path).append(":\n");
129 pathSb.append(" get:\n");
130 pathSb.append(" tags:\n");
131 pathSb.append(" - Operations" + "\n");
132 pathSb.append(" summary: returns ").append(xmlRootElementName).append("\n");
134 pathSb.append(" description: returns ").append(xmlRootElementName).append("\n");
135 pathSb.append(" operationId: get").append(useOpId).append("\n");
136 pathSb.append(" produces:\n");
137 pathSb.append(" - application/json\n");
138 pathSb.append(" - application/xml\n");
140 pathSb.append(" responses:\n");
141 pathSb.append(" \"200\":\n");
142 pathSb.append(" description: successful operation\n");
143 pathSb.append(" schema:\n");
144 pathSb.append(" $ref: \"#/definitions/").append(xmlRootElementName)
146 pathSb.append(" \"default\":\n");
147 pathSb.append(" ").append(GenerateXsd.getResponsesUrl());
148 if (StringUtils.isNotEmpty(pathParams) || StringUtils.isNotEmpty(queryParams)) {
149 pathSb.append("\n parameters:\n");
151 if (StringUtils.isNotEmpty(pathParams)) {
152 pathSb.append(pathParams);
154 if (StringUtils.isNotEmpty(pathParams) && StringUtils.isNotEmpty(queryParams)) {
157 if (StringUtils.isNotEmpty(queryParams)) {
158 pathSb.append(queryParams);
160 checklist.add(xmlRootElementName);
161 return pathSb.toString();