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;
28 import org.apache.commons.lang3.StringUtils;
29 import org.onap.aai.schemagen.GenerateXsd;
31 public class NodeGetOperation {
32 static Map<String, Vector<String>> containers = new HashMap<String, Vector<String>>();
33 static ArrayList<String> checklist = createChecklist();
35 private static ArrayList<String> createChecklist() {
36 ArrayList<String> list = new ArrayList<String>();
40 public static void addContainerProps(String container, Vector<String> containerProps) {
41 containers.put(container, containerProps);
44 public static void resetContainers() {
45 containers = new HashMap<String, Vector<String>>();
46 checklist = createChecklist();
49 private String useOpId;
50 private String xmlRootElementName;
53 private String CRUDpath;
54 private String pathParams;
55 private String queryParams;
57 public NodeGetOperation(String useOpId, String xmlRootElementName, String tag, String path,
60 this.useOpId = useOpId;
61 this.xmlRootElementName = xmlRootElementName;
64 this.path = nodePath();
65 this.pathParams = pathParams;
66 StringBuilder p = new StringBuilder();
68 if (containers.get(xmlRootElementName) == null) {
69 this.queryParams = "";
71 this.queryParams = String.join("", containers.get(xmlRootElementName));
72 for (String param : containers.get(xmlRootElementName)) {
75 this.queryParams = p.toString();
81 int loc = CRUDpath.indexOf(xmlRootElementName);
83 path = "/nodes/" + CRUDpath.substring(loc);
89 public String toString() {
91 st = new StringTokenizer(CRUDpath, "/");
92 //Path has to be longer than one element
94 if ( st.countTokens() <= 1) {
98 //a valid tag is necessary
99 if (StringUtils.isEmpty(tag)) {
102 if (CRUDpath.endsWith("/relationship")) {
105 if (CRUDpath.contains("/relationship/")) { // filter paths with relationship-list
108 if (CRUDpath.endsWith("/relationship-list")) {
111 if (CRUDpath.startsWith("/search")) {
114 if (CRUDpath.startsWith("/actions")) {
117 if (CRUDpath.startsWith("/nodes")) {
120 if (checklist.contains(xmlRootElementName)) {
123 StringBuilder pathSb = new StringBuilder();
124 if (path.indexOf('{') == -1) {
125 path += "?parameter=value[¶meter2=value2]";
127 pathSb.append(" ").append(path).append(":\n");
128 pathSb.append(" get:\n");
129 pathSb.append(" tags:\n");
130 pathSb.append(" - Operations" + "\n");
131 pathSb.append(" summary: returns ").append(xmlRootElementName).append("\n");
133 pathSb.append(" description: returns ").append(xmlRootElementName).append("\n");
134 pathSb.append(" operationId: get").append(useOpId).append("\n");
135 pathSb.append(" produces:\n");
136 pathSb.append(" - application/json\n");
137 pathSb.append(" - application/xml\n");
139 pathSb.append(" responses:\n");
140 pathSb.append(" \"200\":\n");
141 pathSb.append(" description: successful operation\n");
142 pathSb.append(" schema:\n");
143 pathSb.append(" $ref: \"#/definitions/").append(xmlRootElementName)
145 pathSb.append(" \"default\":\n");
146 pathSb.append(" ").append(GenerateXsd.getResponsesUrl());
147 if (StringUtils.isNotEmpty(pathParams) || StringUtils.isNotEmpty(queryParams)) {
148 pathSb.append("\n parameters:\n");
150 if (StringUtils.isNotEmpty(pathParams)) {
151 pathSb.append(pathParams);
153 if (StringUtils.isNotEmpty(pathParams) && StringUtils.isNotEmpty(queryParams)) {
156 if (StringUtils.isNotEmpty(queryParams)) {
157 pathSb.append(queryParams);
159 checklist.add(xmlRootElementName);
160 return pathSb.toString();