Fix sonar issues + merge
[aai/schema-service.git] / aai-schema-gen / src / main / java / org / onap / aai / schemagen / genxsd / DeleteOperation.java
index e1d993f..c59e8f0 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
-package org.onap.aai.schemagen.genxsd;
 
-import org.apache.commons.lang3.StringUtils;
-import org.onap.aai.schemagen.GenerateXsd;
+package org.onap.aai.schemagen.genxsd;
 
 import java.util.HashMap;
 import java.util.StringTokenizer;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.aai.schemagen.GenerateXsd;
 
 public class DeleteOperation {
-       private String useOpId;
-       private String xmlRootElementName;
-       private String tag;
-       private String path;
-       private String pathParams;
+    private String useOpId;
+    private String xmlRootElementName;
+    private String tag;
+    private String path;
+    private String pathParams;
+
+    public static HashMap<String, String> deletePaths = new HashMap<String, String>();
+
+    public DeleteOperation(String useOpId, String xmlRootElementName, String tag, String path,
+                           String pathParams) {
+        super();
+        this.useOpId = useOpId;
+        this.xmlRootElementName = xmlRootElementName;
+        this.tag = tag;
+        this.path = path;
+        this.pathParams = pathParams;
+    }
+
+    @Override
+    public String toString() {
+        StringTokenizer st;
+        st = new StringTokenizer(path, "/");
+        //a valid tag is necessary
+        if (StringUtils.isEmpty(tag)) {
+            return "";
+        }
+        if (path.contains("/relationship/")) { // filter paths with relationship-list
+            return "";
+        }
+        if (path.endsWith("/relationship-list")) {
+            return "";
+        }
+        if (path.startsWith("/search")) {
+            return "";
+        }
+        //All Delete operation paths end with "relationship"
+        //or there is a parameter at the end of the path
+        //and there is a parameter in the path
 
-       public static HashMap<String, String> deletePaths = new HashMap<String, String>();
-               public DeleteOperation(String useOpId, String xmlRootElementName, String tag, String path, String pathParams) {
-                       super();
-                       this.useOpId = useOpId;
-                       this.xmlRootElementName = xmlRootElementName;
-                       this.tag = tag;
-                       this.path = path;
-                       this.pathParams = pathParams;
-               }
-               @Override
-               public String toString() {
-                       StringTokenizer st;
-                       st = new StringTokenizer(path, "/");
-                       //a valid tag is necessary
-                       if ( StringUtils.isEmpty(tag) ) {
-                               return "";
-                       }
-                       if ( path.contains("/relationship/") ) { // filter paths with relationship-list
-                               return "";
-                       }
-                       if ( path.endsWith("/relationship-list")) {
-                               return "";
-                       }
-                       if ( path.startsWith("/search")) {
-                               return "";
-                       }
-                       //All Delete operation paths end with "relationship"
-                       //or there is a parameter at the end of the path
-                       //and there is a parameter in the path
+        if (!path.endsWith("/relationship") && !path.endsWith("}")) {
+            return "";
+        }
+        StringBuilder pathSb = new StringBuilder();
+        pathSb.append("    delete:\n");
+        pathSb.append("      tags:\n");
+        pathSb.append("        - ").append(tag).append("\n");
+        pathSb.append("      summary: delete an existing ").append(xmlRootElementName)
+            .append("\n");
 
-                       if ( !path.endsWith("/relationship")  &&  !path.endsWith("}") ) {
-                               return "";
-                       }
-                       StringBuffer pathSb = new StringBuffer();
-                       pathSb.append("    delete:\n");
-                       pathSb.append("      tags:\n");
-                       pathSb.append("        - " + tag + "\n");
-                       pathSb.append("      summary: delete an existing " + xmlRootElementName + "\n");
+        pathSb.append("      description: delete an existing ").append(xmlRootElementName)
+            .append("\n");
 
-                       pathSb.append("      description: delete an existing " + xmlRootElementName + "\n");
+        pathSb.append("      operationId: delete").append(useOpId).append("\n");
+        pathSb.append("      consumes:\n");
+        pathSb.append("        - application/json\n");
+        pathSb.append("        - application/xml\n");
+        pathSb.append("      produces:\n");
+        pathSb.append("        - application/json\n");
+        pathSb.append("        - application/xml\n");
+        pathSb.append("      responses:\n");
+        pathSb.append("        \"default\":\n");
+        pathSb.append("          ").append(GenerateXsd.getResponsesUrl());
+        pathSb.append("      parameters:\n");
 
-                       pathSb.append("      operationId: delete" + useOpId + "\n");
-                       pathSb.append("      consumes:\n");
-                       pathSb.append("        - application/json\n");
-                       pathSb.append("        - application/xml\n");
-                       pathSb.append("      produces:\n");
-                       pathSb.append("        - application/json\n");
-                       pathSb.append("        - application/xml\n");
-                       pathSb.append("      responses:\n");
-                       pathSb.append("        \"default\":\n");
-                       pathSb.append("          " + GenerateXsd.getResponsesUrl());
-                       pathSb.append("      parameters:\n");
+        pathSb.append(pathParams); // for nesting
+        if (!path.endsWith("/relationship")) {
+            pathSb.append("        - name: resource-version\n");
 
-                       pathSb.append(pathParams); // for nesting
-                       if ( !path.endsWith("/relationship") ) {
-                               pathSb.append("        - name: resource-version\n");
+            pathSb.append("          in: query\n");
+            pathSb.append("          description: resource-version for concurrency\n");
+            pathSb.append("          required: true\n");
+            pathSb.append("          type: string\n");
+        }
+        this.objectPathMapEntry();
+        return pathSb.toString();
+    }
 
-                               pathSb.append("          in: query\n");
-                               pathSb.append("          description: resource-version for concurrency\n");
-                               pathSb.append("          required: true\n");
-                               pathSb.append("          type: string\n");
-                       }
-                       this.objectPathMapEntry();
-                       return pathSb.toString();
-               }
-               public String objectPathMapEntry() {
-                       if (! path.endsWith("/relationship") ) {
-                               deletePaths.put(path, xmlRootElementName);
-                       }
-                       return (xmlRootElementName+":"+path);
-               }
-       }
+    public String objectPathMapEntry() {
+        if (!path.endsWith("/relationship")) {
+            deletePaths.put(path, xmlRootElementName);
+        }
+        return (xmlRootElementName + ":" + path);
+    }
+}