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.HashMap;
25 import java.util.StringTokenizer;
26 import java.util.Vector;
27 import org.apache.commons.lang3.StringUtils;
28 import org.onap.aai.schemagen.GenerateXsd;
30 public class GetOperation {
31 static Map<String, Vector<String>> containers = new HashMap<String, Vector<String>>();
33 public static void addContainerProps(String container, Vector<String> containerProps) {
34 containers.put(container, containerProps);
38 private String useOpId;
39 private String xmlRootElementName;
42 private String pathParams;
43 private String queryParams;
45 public GetOperation(String useOpId, String xmlRootElementName, String tag, String path,
48 this.useOpId = useOpId;
49 this.xmlRootElementName = xmlRootElementName;
52 this.pathParams = pathParams;
53 // StringBuilder p = new StringBuilder();
55 if (containers.get(xmlRootElementName) == null) {
56 this.queryParams = "";
58 this.queryParams = String.join("", containers.get(xmlRootElementName));
59 // for(String param : containers.get(xmlRootElementName)) {
62 // this.queryParams = p.toString();
67 public String toString() {
69 st = new StringTokenizer(path, "/");
70 //Path has to be longer than one element
72 if ( st.countTokens() <= 1) {
76 //a valid tag is necessary
77 if (StringUtils.isEmpty(tag)) {
80 if (path.endsWith("/relationship")) {
83 if (path.contains("/relationship/")) { // filter paths with relationship-list
86 if (path.endsWith("/relationship-list")) {
89 if (path.startsWith("/search")) {
92 StringBuilder pathSb = new StringBuilder();
93 pathSb.append(" ").append(path).append(":\n");
94 pathSb.append(" get:\n");
95 pathSb.append(" tags:\n");
96 pathSb.append(" - ").append(tag).append("\n");
97 pathSb.append(" summary: returns ").append(xmlRootElementName).append("\n");
99 pathSb.append(" description: returns ").append(xmlRootElementName).append("\n");
100 pathSb.append(" operationId: get").append(useOpId).append("\n");
101 pathSb.append(" produces:\n");
102 pathSb.append(" - application/json\n");
103 pathSb.append(" - application/xml\n");
105 pathSb.append(" responses:\n");
106 pathSb.append(" \"200\":\n");
107 pathSb.append(" description: successful operation\n");
108 pathSb.append(" schema:\n");
109 pathSb.append(" $ref: \"#/definitions/").append(xmlRootElementName)
111 pathSb.append(" \"default\":\n");
112 pathSb.append(" ").append(GenerateXsd.getResponsesUrl());
113 if (StringUtils.isNotEmpty(pathParams) || StringUtils.isNotEmpty(queryParams)) {
114 pathSb.append(" parameters:\n");
116 if (StringUtils.isNotEmpty(pathParams)) {
117 pathSb.append(pathParams);
119 // if ( StringUtils.isNotEmpty(pathParams) && StringUtils.isNotEmpty(queryParams)) {
120 // pathSb.append("\n");
122 if (StringUtils.isNotEmpty(queryParams)) {
123 pathSb.append(queryParams);
125 return pathSb.toString();