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;
26 import java.util.StringTokenizer;
28 public class DeleteOperation {
29 private String useOpId;
30 private String xmlRootElementName;
33 private String pathParams;
35 public static HashMap<String, String> deletePaths = new HashMap<String, String>();
36 public DeleteOperation(String useOpId, String xmlRootElementName, String tag, String path, String pathParams) {
38 this.useOpId = useOpId;
39 this.xmlRootElementName = xmlRootElementName;
42 this.pathParams = pathParams;
45 public String toString() {
47 st = new StringTokenizer(path, "/");
48 //a valid tag is necessary
49 if ( StringUtils.isEmpty(tag) ) {
52 if ( path.contains("/relationship/") ) { // filter paths with relationship-list
55 if ( path.endsWith("/relationship-list")) {
58 if ( path.startsWith("/search")) {
61 //All Delete operation paths end with "relationship"
62 //or there is a parameter at the end of the path
63 //and there is a parameter in the path
65 if ( !path.endsWith("/relationship") && !path.endsWith("}") ) {
68 StringBuffer pathSb = new StringBuffer();
69 pathSb.append(" delete:\n");
70 pathSb.append(" tags:\n");
71 pathSb.append(" - " + tag + "\n");
72 pathSb.append(" summary: delete an existing " + xmlRootElementName + "\n");
74 pathSb.append(" description: delete an existing " + xmlRootElementName + "\n");
76 pathSb.append(" operationId: delete" + useOpId + "\n");
77 pathSb.append(" consumes:\n");
78 pathSb.append(" - application/json\n");
79 pathSb.append(" - application/xml\n");
80 pathSb.append(" produces:\n");
81 pathSb.append(" - application/json\n");
82 pathSb.append(" - application/xml\n");
83 pathSb.append(" responses:\n");
84 pathSb.append(" \"default\":\n");
85 pathSb.append(" " + GenerateXsd.getResponsesUrl());
86 pathSb.append(" parameters:\n");
88 pathSb.append(pathParams); // for nesting
89 if ( !path.endsWith("/relationship") ) {
90 pathSb.append(" - name: resource-version\n");
92 pathSb.append(" in: query\n");
93 pathSb.append(" description: resource-version for concurrency\n");
94 pathSb.append(" required: true\n");
95 pathSb.append(" type: string\n");
97 this.objectPathMapEntry();
98 return pathSb.toString();
100 public String objectPathMapEntry() {
101 if (! path.endsWith("/relationship") ) {
102 deletePaths.put(path, xmlRootElementName);
104 return (xmlRootElementName+":"+path);