2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright © 2018 IBM.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.aai.schemagen.genxsd;
24 import org.apache.commons.lang3.StringUtils;
25 import org.onap.aai.setup.SchemaVersion;
26 import org.onap.aai.schemagen.GenerateXsd;
28 public class PutOperation {
29 public static final String RELATIONSHIP = "relationship";
30 private String useOpId;
31 private String xmlRootElementName;
34 private String pathParams;
35 private SchemaVersion version;
36 private String basePath;
38 public PutOperation(String useOpId, String xmlRootElementName, String tag, String path,
39 String pathParams, SchemaVersion v, String basePath) {
41 this.useOpId = useOpId;
42 this.xmlRootElementName = xmlRootElementName;
45 this.pathParams = pathParams;
47 this.basePath = basePath;
51 public String toString() {
52 //a valid tag is necessary
53 if ( StringUtils.isEmpty(tag) ) {
56 //All Put operation paths end with "relationship"
57 //or there is a parameter at the end of the path
58 //and there is a parameter in the path
59 if ( path.contains("/"+RELATIONSHIP+"/") ) { // filter paths with relationship-list
62 if ( path.endsWith("/"+RELATIONSHIP+"-list")) {
65 if ( !path.endsWith("/"+RELATIONSHIP) && !path.endsWith("}") ) {
68 if ( path.startsWith("/search")) {
71 StringBuffer pathSb = new StringBuffer();
72 StringBuffer relationshipExamplesSb = new StringBuffer();
73 if ( path.endsWith("/"+RELATIONSHIP) ) {
74 pathSb.append(" " + path + ":\n" );
76 pathSb.append(" put:\n");
77 pathSb.append(" tags:\n");
78 pathSb.append(" - " + tag + "\n");
80 if ( path.endsWith("/"+RELATIONSHIP) ) {
81 pathSb.append(" summary: see node definition for valid relationships\n");
83 pathSb.append(" summary: create or update an existing " + xmlRootElementName + "\n");
84 pathSb.append(" description: |\n Create or update an existing " + xmlRootElementName + ".\n #\n Note! This PUT method has a corresponding PATCH method that can be used to update just a few of the fields of an existing object, rather than a full object replacement. An example can be found in the [PATCH section] below\n");
86 relationshipExamplesSb.append("[Valid relationship examples shown here](apidocs" + basePath + "/relations/"+version.toString()+"/"+useOpId.replace("RelationshipListRelationship", "")+".json)");
87 pathSb.append(" operationId: createOrUpdate" + useOpId + "\n");
88 pathSb.append(" consumes:\n");
89 pathSb.append(" - application/json\n");
90 pathSb.append(" - application/xml\n");
91 pathSb.append(" produces:\n");
92 pathSb.append(" - application/json\n");
93 pathSb.append(" - application/xml\n");
94 pathSb.append(" responses:\n");
95 pathSb.append(" \"default\":\n");
96 pathSb.append(" " + GenerateXsd.getResponsesUrl());
98 pathSb.append(" parameters:\n");
99 pathSb.append(pathParams); // for nesting
100 pathSb.append(" - name: body\n");
101 pathSb.append(" in: body\n");
102 pathSb.append(" description: " + xmlRootElementName + " object that needs to be created or updated. "+relationshipExamplesSb.toString()+"\n");
103 pathSb.append(" required: true\n");
104 pathSb.append(" schema:\n");
105 String useElement = xmlRootElementName;
106 if ( xmlRootElementName.equals("relationship")) {
107 useElement += "-dict";
109 pathSb.append(" $ref: \"#/definitions/" + useElement + "\"\n");
110 this.tagRelationshipPathMapEntry();
111 return pathSb.toString();
114 public String tagRelationshipPathMapEntry() {
115 if ( path.endsWith("/"+RELATIONSHIP) ) {
116 PutRelationPathSet.add(useOpId, path);