Fix sonar issues + merge
[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 import org.apache.commons.lang3.StringUtils;
26 import org.onap.aai.schemagen.GenerateXsd;
27
28 public class DeleteOperation {
29     private String useOpId;
30     private String xmlRootElementName;
31     private String tag;
32     private String path;
33     private String pathParams;
34
35     public static HashMap<String, String> deletePaths = new HashMap<String, String>();
36
37     public DeleteOperation(String useOpId, String xmlRootElementName, String tag, String path,
38                            String pathParams) {
39         super();
40         this.useOpId = useOpId;
41         this.xmlRootElementName = xmlRootElementName;
42         this.tag = tag;
43         this.path = path;
44         this.pathParams = pathParams;
45     }
46
47     @Override
48     public String toString() {
49         StringTokenizer st;
50         st = new StringTokenizer(path, "/");
51         //a valid tag is necessary
52         if (StringUtils.isEmpty(tag)) {
53             return "";
54         }
55         if (path.contains("/relationship/")) { // filter paths with relationship-list
56             return "";
57         }
58         if (path.endsWith("/relationship-list")) {
59             return "";
60         }
61         if (path.startsWith("/search")) {
62             return "";
63         }
64         //All Delete operation paths end with "relationship"
65         //or there is a parameter at the end of the path
66         //and there is a parameter in the path
67
68         if (!path.endsWith("/relationship") && !path.endsWith("}")) {
69             return "";
70         }
71         StringBuilder pathSb = new StringBuilder();
72         pathSb.append("    delete:\n");
73         pathSb.append("      tags:\n");
74         pathSb.append("        - ").append(tag).append("\n");
75         pathSb.append("      summary: delete an existing ").append(xmlRootElementName)
76             .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 }