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.util.genxsd;
21 import java.util.StringTokenizer;
23 import org.apache.commons.lang3.StringUtils;
24 import org.onap.aai.setup.SchemaVersion;
25 import org.onap.aai.util.GenerateXsd;
27 public class PutOperation {
28 private String useOpId;
29 private String xmlRootElementName;
32 private String pathParams;
33 private SchemaVersion version;
35 public PutOperation(String useOpId, String xmlRootElementName, String tag, String path, String pathParams, SchemaVersion v) {
37 this.useOpId = useOpId;
38 this.xmlRootElementName = xmlRootElementName;
41 this.pathParams = pathParams;
46 public String toString() {
47 StringTokenizer st = new StringTokenizer(path, "/");
48 //a valid tag is necessary
49 if ( StringUtils.isEmpty(tag) ) {
52 //All Put operation paths end with "relationship"
53 //or there is a parameter at the end of the path
54 //and there is a parameter in the path
55 if ( path.contains("/relationship/") ) { // filter paths with relationship-list
58 if ( path.endsWith("/relationship-list")) {
61 if ( !path.endsWith("/relationship") && !path.endsWith("}") ) {
64 if ( path.startsWith("/search")) {
67 StringBuffer pathSb = new StringBuffer();
68 StringBuffer relationshipExamplesSb = new StringBuffer();
69 if ( path.endsWith("/relationship") ) {
70 pathSb.append(" " + path + ":\n" );
72 pathSb.append(" put:\n");
73 pathSb.append(" tags:\n");
74 pathSb.append(" - " + tag + "\n");
76 if ( path.endsWith("/relationship") ) {
77 pathSb.append(" summary: see node definition for valid relationships\n");
79 pathSb.append(" summary: create or update an existing " + xmlRootElementName + "\n");
80 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");
82 relationshipExamplesSb.append("[Valid relationship examples shown here](apidocs/relations/"+version.toString()+"/"+useOpId.replace("RelationshipListRelationship", "")+".json)");
83 pathSb.append(" operationId: createOrUpdate" + useOpId + "\n");
84 pathSb.append(" consumes:\n");
85 pathSb.append(" - application/json\n");
86 pathSb.append(" - application/xml\n");
87 pathSb.append(" produces:\n");
88 pathSb.append(" - application/json\n");
89 pathSb.append(" - application/xml\n");
90 pathSb.append(" responses:\n");
91 pathSb.append(" \"default\":\n");
92 pathSb.append(" " + GenerateXsd.getResponsesUrl());
94 pathSb.append(" parameters:\n");
95 pathSb.append(pathParams); // for nesting
96 pathSb.append(" - name: body\n");
97 pathSb.append(" in: body\n");
98 pathSb.append(" description: " + xmlRootElementName + " object that needs to be created or updated. "+relationshipExamplesSb.toString()+"\n");
99 pathSb.append(" required: true\n");
100 pathSb.append(" schema:\n");
101 pathSb.append(" $ref: \"#/definitions/" + xmlRootElementName + "\"\n");
102 this.tagRelationshipPathMapEntry();
103 return pathSb.toString();
106 public String tagRelationshipPathMapEntry() {
107 if ( path.endsWith("/relationship") ) {
108 PutRelationPathSet.add(useOpId, path);