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.util.genxsd;
24 import org.apache.commons.lang3.StringUtils;
25 import org.onap.aai.setup.SchemaVersion;
26 import org.onap.aai.util.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;
37 public PutOperation(String useOpId, String xmlRootElementName, String tag, String path, String pathParams, SchemaVersion v) {
39 this.useOpId = useOpId;
40 this.xmlRootElementName = xmlRootElementName;
43 this.pathParams = pathParams;
48 public String toString() {
49 //a valid tag is necessary
50 if ( StringUtils.isEmpty(tag) ) {
53 //All Put operation paths end with "relationship"
54 //or there is a parameter at the end of the path
55 //and there is a parameter in the path
56 if ( path.contains("/"+RELATIONSHIP+"/") ) { // filter paths with relationship-list
59 if ( path.endsWith("/"+RELATIONSHIP+"-list")) {
62 if ( !path.endsWith("/"+RELATIONSHIP) && !path.endsWith("}") ) {
65 if ( path.startsWith("/search")) {
68 StringBuffer pathSb = new StringBuffer();
69 StringBuffer relationshipExamplesSb = new StringBuffer();
70 if ( path.endsWith("/"+RELATIONSHIP) ) {
71 pathSb.append(" " + path + ":\n" );
73 pathSb.append(" put:\n");
74 pathSb.append(" tags:\n");
75 pathSb.append(" - " + tag + "\n");
77 if ( path.endsWith("/"+RELATIONSHIP) ) {
78 pathSb.append(" summary: see node definition for valid relationships\n");
80 pathSb.append(" summary: create or update an existing " + xmlRootElementName + "\n");
81 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");
83 relationshipExamplesSb.append("[Valid relationship examples shown here](apidocs/relations/"+version.toString()+"/"+useOpId.replace("RelationshipListRelationship", "")+".json)");
84 pathSb.append(" operationId: createOrUpdate" + useOpId + "\n");
85 pathSb.append(" consumes:\n");
86 pathSb.append(" - application/json\n");
87 pathSb.append(" - application/xml\n");
88 pathSb.append(" produces:\n");
89 pathSb.append(" - application/json\n");
90 pathSb.append(" - application/xml\n");
91 pathSb.append(" responses:\n");
92 pathSb.append(" \"default\":\n");
93 pathSb.append(" " + GenerateXsd.getResponsesUrl());
95 pathSb.append(" parameters:\n");
96 pathSb.append(pathParams); // for nesting
97 pathSb.append(" - name: body\n");
98 pathSb.append(" in: body\n");
99 pathSb.append(" description: " + xmlRootElementName + " object that needs to be created or updated. "+relationshipExamplesSb.toString()+"\n");
100 pathSb.append(" required: true\n");
101 pathSb.append(" schema:\n");
102 pathSb.append(" $ref: \"#/definitions/" + xmlRootElementName + "\"\n");
103 this.tagRelationshipPathMapEntry();
104 return pathSb.toString();
107 public String tagRelationshipPathMapEntry() {
108 if ( path.endsWith("/"+RELATIONSHIP) ) {
109 PutRelationPathSet.add(useOpId, path);