Add instructions to invoke the linter and code formatter plugins to the README and...
[aai/schema-service.git] / aai-schema-gen / src / main / java / org / onap / aai / schemagen / genxsd / DeleteOperation.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  * <p>
11  * http://www.apache.org/licenses/LICENSE-2.0
12  * <p>
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=========================================================
19  */
20
21 package org.onap.aai.schemagen.genxsd;
22
23 import java.util.HashMap;
24 import java.util.StringTokenizer;
25
26 import org.apache.commons.lang3.StringUtils;
27 import org.onap.aai.schemagen.GenerateXsd;
28
29 public class DeleteOperation {
30     private String useOpId;
31     private String xmlRootElementName;
32     private String tag;
33     private String path;
34     private String pathParams;
35
36     public static HashMap<String, String> deletePaths = new HashMap<String, String>();
37
38     public DeleteOperation(String useOpId, String xmlRootElementName, String tag, String path,
39         String pathParams) {
40         super();
41         this.useOpId = useOpId;
42         this.xmlRootElementName = xmlRootElementName;
43         this.tag = tag;
44         this.path = path;
45         this.pathParams = pathParams;
46     }
47
48     @Override
49     public String toString() {
50         StringTokenizer st;
51         st = new StringTokenizer(path, "/");
52         // a valid tag is necessary
53         if (StringUtils.isEmpty(tag)) {
54             return "";
55         }
56         if (path.contains("/relationship/")) { // filter paths with relationship-list
57             return "";
58         }
59         if (path.endsWith("/relationship-list")) {
60             return "";
61         }
62         if (path.startsWith("/search")) {
63             return "";
64         }
65         // All Delete operation paths end with "relationship"
66         // or there is a parameter at the end of the path
67         // and there is a parameter in the path
68
69         if (!path.endsWith("/relationship") && !path.endsWith("}")) {
70             return "";
71         }
72         StringBuilder pathSb = new StringBuilder();
73         pathSb.append("    delete:\n");
74         pathSb.append("      tags:\n");
75         pathSb.append("        - ").append(tag).append("\n");
76         pathSb.append("      summary: delete an existing ").append(xmlRootElementName).append("\n");
77
78         pathSb.append("      description: delete an existing ").append(xmlRootElementName)
79             .append("\n");
80
81         pathSb.append("      operationId: delete").append(useOpId).append("\n");
82         pathSb.append("      consumes:\n");
83         pathSb.append("        - application/json\n");
84         pathSb.append("        - application/xml\n");
85         pathSb.append("      produces:\n");
86         pathSb.append("        - application/json\n");
87         pathSb.append("        - application/xml\n");
88         pathSb.append("      responses:\n");
89         pathSb.append("        \"default\":\n");
90         pathSb.append("          ").append(GenerateXsd.getResponsesUrl());
91         pathSb.append("      parameters:\n");
92
93         pathSb.append(pathParams); // for nesting
94         if (!path.endsWith("/relationship")) {
95             pathSb.append("        - name: resource-version\n");
96
97             pathSb.append("          in: query\n");
98             pathSb.append("          description: resource-version for concurrency\n");
99             pathSb.append("          required: true\n");
100             pathSb.append("          type: string\n");
101         }
102         this.objectPathMapEntry();
103         return pathSb.toString();
104     }
105
106     public String objectPathMapEntry() {
107         if (!path.endsWith("/relationship")) {
108             deletePaths.put(path, xmlRootElementName);
109         }
110         return (xmlRootElementName + ":" + path);
111     }
112 }