Add plugin to check coverage
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / util / 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  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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 package org.onap.aai.util.genxsd;
21
22 import org.apache.commons.lang3.StringUtils;
23 import org.onap.aai.util.GenerateXsd;
24
25 import java.util.HashMap;
26 import java.util.StringTokenizer;
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                 public DeleteOperation(String useOpId, String xmlRootElementName, String tag, String path, String pathParams) {
37                         super();
38                         this.useOpId = useOpId;
39                         this.xmlRootElementName = xmlRootElementName;
40                         this.tag = tag;
41                         this.path = path;
42                         this.pathParams = pathParams;
43                 }
44                 @Override
45                 public String toString() {
46                         StringTokenizer st;
47                         st = new StringTokenizer(path, "/");
48                         //a valid tag is necessary
49                         if ( StringUtils.isEmpty(tag) ) {
50                                 return "";
51                         }
52                         if ( path.contains("/relationship/") ) { // filter paths with relationship-list
53                                 return "";
54                         }
55                         if ( path.endsWith("/relationship-list")) {
56                                 return "";
57                         }
58                         if ( path.startsWith("/search")) {
59                                 return "";
60                         }
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
64                         
65                         if ( !path.endsWith("/relationship")  &&  !path.endsWith("}") ) {
66                                 return "";
67                         }
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");
73                         
74                         pathSb.append("      description: delete an existing " + xmlRootElementName + "\n");
75                         
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");
87
88                         pathSb.append(pathParams); // for nesting
89                         if ( !path.endsWith("/relationship") ) {
90                                 pathSb.append("        - name: resource-version\n");
91
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");
96                         }
97                         this.objectPathMapEntry();
98                         return pathSb.toString();
99                 }
100                 public String objectPathMapEntry() {
101                         if (! path.endsWith("/relationship") ) {
102                                 deletePaths.put(path, xmlRootElementName);
103                         }
104                         return (xmlRootElementName+":"+path);
105                 }               
106         }