[SDNC-30] summary
[ccsdk/sli/adaptors.git] / aai-service / provider / src / main / java / org / onap / ccsdk / sli / adaptors / aai / PInterfaceRequest.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
28 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
29 import org.openecomp.aai.inventory.v11.PInterface;
30 import org.slf4j.LoggerFactory;
31
32 import com.fasterxml.jackson.core.JsonProcessingException;
33 import com.fasterxml.jackson.databind.ObjectMapper;
34
35 public class PInterfaceRequest extends AAIRequest {
36
37         // tenant (1602)
38         public static final String PINTERFACE_PATH                      = "org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface";
39         public static final String PINTERFACE_QUERY_PATH        = "org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface.query";
40         
41         private final String pinterface_path;
42         private final String pinterface_query_path;
43         
44         public static final String HOSTNAME = "hostname";
45         public static final String PSERVER_HOSTNAME = "pserver.hostname";
46         public static final String INTERFACE_NAME = "interface-name";
47         public static final String PINTERFACE_INTERFACE_NAME = "p-interface.interface-name";
48
49
50         public PInterfaceRequest() {
51                 pinterface_path = configProperties.getProperty(PINTERFACE_PATH);
52                 pinterface_query_path = configProperties.getProperty(PINTERFACE_QUERY_PATH);
53                 LoggerFactory.getLogger(PInterfaceRequest.class).debug("org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface=\t" + pinterface_path);
54                 LoggerFactory.getLogger(PInterfaceRequest.class).debug("org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface.query=\t" + pinterface_query_path);
55                 if(pinterface_path == null) {
56                         LoggerFactory.getLogger(PInterfaceRequest.class).warn("org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface PATH not found in aaiclient.properties");
57                 }
58         }
59
60         
61         @Override
62         public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
63
64                 String request_url = target_uri + pinterface_path;
65                 String encoded_vnf = null;
66                 
67                 String hostname = null;
68                 String interfaceName = null;
69
70                 if(requestProperties.containsKey(HOSTNAME)) {
71                         hostname = requestProperties.getProperty(HOSTNAME);
72                 }
73                 if(requestProperties.containsKey(PSERVER_HOSTNAME)) {
74                         hostname = requestProperties.getProperty(PSERVER_HOSTNAME);
75                 }
76                 
77                 if(requestProperties.containsKey(INTERFACE_NAME)) {
78                         interfaceName = requestProperties.getProperty(INTERFACE_NAME);
79                 }
80                 if(requestProperties.containsKey(PINTERFACE_INTERFACE_NAME)) {
81                         interfaceName = requestProperties.getProperty(PINTERFACE_INTERFACE_NAME);
82                 }
83
84                 encoded_vnf = encodeQuery(hostname);
85                 request_url = request_url.replace("{hostname}", encoded_vnf) ;
86
87                 encoded_vnf = encodeQuery(interfaceName);
88                 request_url = request_url.replace("{interface-name}", encoded_vnf) ;
89
90                 if(resourceVersion != null) {
91                         request_url = request_url +"?resource-version="+resourceVersion;
92                 }
93                 URL http_req_url =      new URL(request_url);
94
95                 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
96                 aaiService.LOGwriteDateTrace("hostname", hostname);
97                 aaiService.LOGwriteDateTrace("interface-name", hostname);
98                 
99                 return http_req_url;
100         }
101         
102         @Override
103         public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
104                 return this.getRequestUrl(method, null);
105         }
106
107
108         @Override
109         public String toJSONString() {
110                 ObjectMapper mapper = getObjectMapper();
111                 PInterface vnfc = (PInterface)requestDatum;
112                 String json_text = null;
113                 try {
114                         json_text = mapper.writeValueAsString(vnfc);
115                 } catch (JsonProcessingException exc) {
116                         handleException(this, exc);
117                         return null;
118                 }
119                 return json_text;
120         }
121
122         @Override
123         public String[] getArgsList() {
124                 String[] args = {HOSTNAME, PSERVER_HOSTNAME, INTERFACE_NAME, PINTERFACE_INTERFACE_NAME};
125                 return args;
126         }
127         
128         @Override
129         public Class<? extends AAIDatum> getModelClass() {
130                 return PInterface.class;
131         }
132 }