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=========================================================
23 package org.onap.aai.schemagen.genxsd;
25 import org.apache.commons.lang3.StringUtils;
26 import org.onap.aai.schemagen.GenerateXsd;
27 import org.onap.aai.setup.SchemaVersion;
29 public class PutOperation {
30 public static final String RELATIONSHIP = "relationship";
31 private String useOpId;
32 private String xmlRootElementName;
35 private String pathParams;
36 private SchemaVersion version;
37 private String basePath;
39 public PutOperation(String useOpId, String xmlRootElementName, String tag, String path,
40 String pathParams, SchemaVersion v, String basePath) {
42 this.useOpId = useOpId;
43 this.xmlRootElementName = xmlRootElementName;
46 this.pathParams = pathParams;
48 this.basePath = basePath;
52 public String toString() {
53 //a valid tag is necessary
54 if (StringUtils.isEmpty(tag)) {
57 //All Put operation paths end with "relationship"
58 //or there is a parameter at the end of the path
59 //and there is a parameter in the path
60 if (path.contains("/" + RELATIONSHIP + "/")) { // filter paths with relationship-list
63 if (path.endsWith("/" + RELATIONSHIP + "-list")) {
66 if (!path.endsWith("/" + RELATIONSHIP) && !path.endsWith("}")) {
69 if (path.startsWith("/search")) {
72 StringBuilder pathSb = new StringBuilder();
73 StringBuilder relationshipExamplesSb = new StringBuilder();
74 if (path.endsWith("/" + RELATIONSHIP)) {
75 pathSb.append(" ").append(path).append(":\n");
77 pathSb.append(" put:\n");
78 pathSb.append(" tags:\n");
79 pathSb.append(" - ").append(tag).append("\n");
81 if (path.endsWith("/" + RELATIONSHIP)) {
82 pathSb.append(" summary: see node definition for valid relationships\n");
84 pathSb.append(" summary: create or update an existing ")
85 .append(xmlRootElementName).append("\n");
86 pathSb.append(" description: |\n Create or update an existing ")
87 .append(xmlRootElementName).append(
88 ".\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");
90 relationshipExamplesSb.append("[Valid relationship examples shown here](apidocs")
91 .append(basePath).append("/relations/").append(version.toString()).append("/")
92 .append(useOpId.replace("RelationshipListRelationship", "")).append(".json)");
93 pathSb.append(" operationId: createOrUpdate").append(useOpId).append("\n");
94 pathSb.append(" consumes:\n");
95 pathSb.append(" - application/json\n");
96 pathSb.append(" - application/xml\n");
97 pathSb.append(" produces:\n");
98 pathSb.append(" - application/json\n");
99 pathSb.append(" - application/xml\n");
100 pathSb.append(" responses:\n");
101 pathSb.append(" \"default\":\n");
102 pathSb.append(" ").append(GenerateXsd.getResponsesUrl());
104 pathSb.append(" parameters:\n");
105 pathSb.append(pathParams); // for nesting
106 pathSb.append(" - name: body\n");
107 pathSb.append(" in: body\n");
108 pathSb.append(" description: ").append(xmlRootElementName)
109 .append(" object that needs to be created or updated. ")
110 .append(relationshipExamplesSb.toString()).append("\n");
111 pathSb.append(" required: true\n");
112 pathSb.append(" schema:\n");
113 String useElement = xmlRootElementName;
114 if (xmlRootElementName.equals("relationship")) {
115 useElement += "-dict";
117 pathSb.append(" $ref: \"#/definitions/").append(useElement).append("\"\n");
118 this.tagRelationshipPathMapEntry();
119 return pathSb.toString();
122 public String tagRelationshipPathMapEntry() {
123 if (path.endsWith("/" + RELATIONSHIP)) {
124 PutRelationPathSet.add(useOpId, path);