Update sli-adaptor/aai-service package names
[ccsdk/sli/adaptors.git] / aai-service / provider / src / main / java / org / onap / sli / adaptors / aai / SubInterfaceRequest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 ONAP Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.ccsdk.sli.adaptors.aai;
23
24 import java.io.UnsupportedEncodingException;
25 import java.net.MalformedURLException;
26 import java.net.URL;
27 import java.util.Properties;
28
29 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
30 import org.openecomp.aai.inventory.v10.LInterface;
31
32 import com.fasterxml.jackson.core.JsonProcessingException;
33 import com.fasterxml.jackson.databind.ObjectMapper;
34
35 public class SubInterfaceRequest extends AAIRequest {
36
37         // tenant (1602)
38         public static final String PNF_LAGINTERFACE_SUBINTERFACE_PATH           = "org.onap.ccsdk.sli.adaptors.aai.path.pnf.lag.interface.subinterface";
39         public static final String PNF_LAGINTERFACE_SUBINTERFACE_QUERY_PATH     = "org.onap.ccsdk.sli.adaptors.aai.path.pnf.lag.interface.subinterface.query";
40
41         public static final String PNF_P_INTERFACE_SUBINTERFACE_PATH            = "org.onap.ccsdk.sli.adaptors.aai.path.pnf.p.interface.l.interface";
42         public static final String PNF_P_INTERFACE_SUBINTERFACE_QUERY_PATH      = "org.onap.ccsdk.sli.adaptors.aai.path.pnf.p.interface.l.interface.query";
43
44         private final String pnf_laginterface_subinterface_path;
45         private final String pnf_laginterface_subinterface_query_path;
46         private final String pnf_p_interface_subinterface_path;
47         private final String pnf_p_interface_subinterface_query_path;
48
49         public static final String SUBINTERFACE_INTERFACE_NAME  = "l-interface.interface-name";
50         public static final String LAG_INTERFACE_INTERFACE_NAME = "lag-interface.interface-name";
51         public static final String PNF_PNF_NAME = "pnf.pnf-name";
52         public static enum TYPE { L2_BRIDGE_BGF, L2_BRIDGE_SBG};
53
54         private final TYPE type;
55
56         public SubInterfaceRequest(TYPE type) {
57                 this.type = type;
58
59                 pnf_laginterface_subinterface_path = configProperties.getProperty(PNF_LAGINTERFACE_SUBINTERFACE_PATH);
60                 pnf_laginterface_subinterface_query_path = configProperties.getProperty(PNF_LAGINTERFACE_SUBINTERFACE_QUERY_PATH);
61
62                 pnf_p_interface_subinterface_path = configProperties.getProperty(PNF_P_INTERFACE_SUBINTERFACE_PATH);
63                 pnf_p_interface_subinterface_query_path = configProperties.getProperty(PNF_P_INTERFACE_SUBINTERFACE_QUERY_PATH);
64         }
65
66
67         @Override
68         public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
69
70                 String request_url = null;
71                 String encoded_vnf = null;
72
73                 String pnfname = null;
74                 String interfaceName = null;
75
76                 if(type == TYPE.L2_BRIDGE_SBG) {
77                         request_url = target_uri + pnf_laginterface_subinterface_path;
78
79                         if(requestProperties.containsKey(PNF_PNF_NAME)) {
80                                 pnfname = requestProperties.getProperty(PNF_PNF_NAME);
81                                 encoded_vnf = encodeQuery(pnfname);
82                                 request_url = request_url.replace("{pnf-name}", encoded_vnf);
83                         }
84
85                         encoded_vnf = encodeQuery(requestProperties.getProperty(LAG_INTERFACE_INTERFACE_NAME));
86                         request_url = request_url.replace("{lag-interface.interface-name}", encoded_vnf) ;
87
88
89                         interfaceName = requestProperties.getProperty(SUBINTERFACE_INTERFACE_NAME);
90                         encoded_vnf = encodeQuery(interfaceName);
91                         request_url = request_url.replace("{interface-name}", encoded_vnf) ;
92
93                 }
94                 if(type == TYPE.L2_BRIDGE_BGF) {
95                         request_url = target_uri + pnf_p_interface_subinterface_path;
96
97                         if(requestProperties.containsKey(PNF_PNF_NAME)) {
98                                 pnfname = requestProperties.getProperty(PNF_PNF_NAME);
99                                 encoded_vnf = encodeQuery(pnfname);
100                                 request_url = request_url.replace("{pnf-name}", encoded_vnf);
101                         }
102
103                         encoded_vnf = encodeQuery(requestProperties.getProperty(PInterfaceRequest.PINTERFACE_INTERFACE_NAME));
104                         request_url = request_url.replace("{p-interface.interface-name}", encoded_vnf) ;
105
106
107                         interfaceName = requestProperties.getProperty(SUBINTERFACE_INTERFACE_NAME);
108                         encoded_vnf = encodeQuery(interfaceName);
109                         request_url = request_url.replace("{interface-name}", encoded_vnf) ;
110                 }
111
112
113                 if(resourceVersion != null) {
114                         request_url = request_url +"?resource-version="+resourceVersion;
115                 }
116                 URL http_req_url =      new URL(request_url);
117
118                 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
119
120                 if(pnfname != null)
121                         aaiService.LOGwriteDateTrace("pnf-name", pnfname);
122                 if(requestProperties.containsKey(LAG_INTERFACE_INTERFACE_NAME)) {
123                         aaiService.LOGwriteDateTrace("lag-interface.interface-name", requestProperties.getProperty(LAG_INTERFACE_INTERFACE_NAME));
124                 }
125                 if(requestProperties.containsKey(PInterfaceRequest.PINTERFACE_INTERFACE_NAME)) {
126                         aaiService.LOGwriteDateTrace("p-interface.interface-name", requestProperties.getProperty(PInterfaceRequest.PINTERFACE_INTERFACE_NAME));
127                 }
128                 aaiService.LOGwriteDateTrace("interface-name", interfaceName);
129
130                 return http_req_url;
131         }
132
133         @Override
134         public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
135                 return this.getRequestUrl(method, null);
136         }
137
138
139         @Override
140         public String toJSONString() {
141                 ObjectMapper mapper = getObjectMapper();
142                 LInterface vnfc = (LInterface)requestDatum;
143                 String json_text = null;
144                 try {
145                         json_text = mapper.writeValueAsString(vnfc);
146                 } catch (JsonProcessingException exc) {
147                         handleException(this, exc);
148                         return null;
149                 }
150                 return json_text;
151         }
152
153
154         @Override
155         public String[] getArgsList() {
156                 String[] args = {};
157                 if(type == TYPE.L2_BRIDGE_SBG) {
158                         String[] tmpArray = {SUBINTERFACE_INTERFACE_NAME, LAG_INTERFACE_INTERFACE_NAME, PNF_PNF_NAME};
159                         args = tmpArray;
160                 }
161                 if(type == TYPE.L2_BRIDGE_BGF) {
162                         String[] tmpArray = {SUBINTERFACE_INTERFACE_NAME, PInterfaceRequest.PINTERFACE_INTERFACE_NAME, PNF_PNF_NAME};
163                         args = tmpArray;
164                 }
165
166                 return args;
167         }
168
169         @Override
170         public Class<? extends AAIDatum> getModelClass() {
171                 return LInterface.class;
172         }
173
174         @Override
175         public String getPrimaryResourceName(String resource) {
176                 return "sub-interface";
177         }
178
179         public static final String processPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException {
180                 String interfaceName = requestProperties.getProperty(SUBINTERFACE_INTERFACE_NAME);
181                 request_url = request_url.replace("{interface-name}", encodeQuery(interfaceName)) ;
182                 return request_url;
183         }
184 }