2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.sli.adaptors.aai;
24 import java.io.UnsupportedEncodingException;
25 import java.net.MalformedURLException;
27 import java.util.Properties;
29 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
30 import org.openecomp.aai.inventory.v11.GenericVnf;
32 import com.fasterxml.jackson.core.JsonProcessingException;
33 import com.fasterxml.jackson.databind.ObjectMapper;
35 public class GenericVnfRequest extends AAIRequest {
38 public static final String GENERIC_VNF_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.generic.vnf";
39 public static final String GENERIC_VNF_QUERY_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.generic.vnf.query";
41 private final String generic_vnf_path;
42 private final String generic_vnf_query_path;
44 public static final String GENERIC_VNF_ID = "generic_vnf.vnf_id";
45 public static final String VNF_ID = "vnf_id";
48 public GenericVnfRequest() {
49 generic_vnf_path = configProperties.getProperty(GENERIC_VNF_PATH);
50 generic_vnf_query_path = configProperties.getProperty(GENERIC_VNF_QUERY_PATH);
55 public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
57 String request_url = target_uri+generic_vnf_path;
59 if(requestProperties.containsKey(GENERIC_VNF_ID)) {
63 if(!requestProperties.containsKey(key)) {
64 aaiService.logKeyError(String.format("%s,%s", VNF_ID, GENERIC_VNF_ID));
67 String encoded_vnf = encodeQuery(requestProperties.getProperty(key));
68 request_url = request_url.replace("{vnf-id}", encoded_vnf) ;
69 if(resourceVersion != null) {
70 request_url = request_url +"?resource-version="+resourceVersion;
72 URL http_req_url = new URL(request_url);
74 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
75 aaiService.LOGwriteDateTrace("vnf-id", requestProperties.getProperty(key));
81 public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
83 String request_url = target_uri+generic_vnf_path;
86 if(requestProperties.containsKey(GENERIC_VNF_ID)) {
90 if(!requestProperties.containsKey(key)) {
91 aaiService.logKeyError(String.format("%s,%s", VNF_ID, GENERIC_VNF_ID));
94 String encoded_vnf = encodeQuery(requestProperties.getProperty(key));
95 request_url = request_url.replace("{vnf-id}", encoded_vnf) ;
96 URL http_req_url = new URL(request_url);
98 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
99 aaiService.LOGwriteDateTrace("vnf-id", requestProperties.getProperty(key));
106 public String toJSONString() {
107 ObjectMapper mapper = getObjectMapper();
108 GenericVnf tenant = (GenericVnf)requestDatum;
109 String json_text = null;
111 json_text = mapper.writeValueAsString(tenant);
112 } catch (JsonProcessingException exc) {
113 handleException(this, exc);
121 public String[] getArgsList() {
122 String[] args = {VNF_ID, GENERIC_VNF_ID};
128 public Class<? extends AAIDatum> getModelClass() {
129 return GenericVnf.class;
133 public static String processPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException {
136 if(requestProperties.containsKey(GENERIC_VNF_ID)) {
137 key = GENERIC_VNF_ID;
139 String encoded_vnf = encodeQuery(requestProperties.getProperty(key));
140 request_url = request_url.replace("{vnf-id}", encoded_vnf) ;