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;
25 import java.util.HashMap;
27 import java.util.StringTokenizer;
28 import java.util.Vector;
30 public class GetOperation {
31 static Map<String, Vector<String>> containers = new HashMap<String, Vector<String>>();
32 public static void addContainerProps(String container, Vector<String> containerProps) {
33 containers.put(container, containerProps);;
35 private String useOpId;
36 private String xmlRootElementName;
39 private String pathParams;
40 private String queryParams;
42 public GetOperation(String useOpId, String xmlRootElementName, String tag, String path, String pathParams) {
44 this.useOpId = useOpId;
45 this.xmlRootElementName = xmlRootElementName;
48 this.pathParams = pathParams;
49 // StringBuilder p = new StringBuilder();
51 if(containers.get(xmlRootElementName) == null) {
52 this.queryParams = "";
54 this.queryParams= String.join("", containers.get(xmlRootElementName));
55 // for(String param : containers.get(xmlRootElementName)) {
58 // this.queryParams = p.toString();
62 public String toString() {
64 st = new StringTokenizer(path, "/");
65 //Path has to be longer than one element
67 if ( st.countTokens() <= 1) {
71 //a valid tag is necessary
72 if ( StringUtils.isEmpty(tag) ) {
75 if ( path.endsWith("/relationship") ) {
78 if ( path.contains("/relationship/") ) { // filter paths with relationship-list
81 if ( path.endsWith("/relationship-list")) {
84 if ( path.startsWith("/search")) {
87 StringBuffer pathSb = new StringBuffer();
88 pathSb.append(" " + path + ":\n" );
89 pathSb.append(" get:\n");
90 pathSb.append(" tags:\n");
91 pathSb.append(" - " + tag + "\n");
92 pathSb.append(" summary: returns " + xmlRootElementName + "\n");
94 pathSb.append(" description: returns " + xmlRootElementName + "\n");
95 pathSb.append(" operationId: get" + useOpId + "\n");
96 pathSb.append(" produces:\n");
97 pathSb.append(" - application/json\n");
98 pathSb.append(" - application/xml\n");
100 pathSb.append(" responses:\n");
101 pathSb.append(" \"200\":\n");
102 pathSb.append(" description: successful operation\n");
103 pathSb.append(" schema:\n");
104 pathSb.append(" $ref: \"#/definitions/" + xmlRootElementName + "\"\n");
105 pathSb.append(" \"default\":\n");
106 pathSb.append(" " + GenerateXsd.getResponsesUrl());
107 if ( StringUtils.isNotEmpty(pathParams) || StringUtils.isNotEmpty(queryParams)) {
108 pathSb.append(" parameters:\n");
110 if ( StringUtils.isNotEmpty(pathParams)) {
111 pathSb.append(pathParams);
113 // if ( StringUtils.isNotEmpty(pathParams) && StringUtils.isNotEmpty(queryParams)) {
114 // pathSb.append("\n");
116 if ( StringUtils.isNotEmpty(queryParams)) {
117 pathSb.append(queryParams);
119 return pathSb.toString();