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.v10.SearchResults;
32 import com.fasterxml.jackson.core.JsonProcessingException;
33 import com.fasterxml.jackson.databind.ObjectMapper;
35 public class NodesQueryRequest extends AAIRequest {
37 public static final String NODES_SEARCH_PATH = "org.onap.ccsdk.sli.adaptors.aai.query.nodes";
39 private final String nodes_search_path;
41 public static final String NODE_TYPE = "node-type";
42 public static final String ENTITY_IDENTIFIER = "entity-identifier";
43 public static final String ENTITY_VALUE = "entity-value";
46 public NodesQueryRequest() {
47 nodes_search_path = configProperties.getProperty(NODES_SEARCH_PATH);
52 // public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
54 // String request_url = target_uri+generic_search_path;
55 // String key = START_NODE_TYPE;
57 // String encoded_vnf = encodeQuery(requestProperties.getProperty(key));
58 // request_url = request_url.replace("{vnf-id}", encoded_vnf) ;
60 // if(resourceVersion != null) {
61 // request_url = request_url +"?resource-version="+resourceVersion;
63 // URL http_req_url = new URL(request_url);
65 // aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
68 // return http_req_url;
72 public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
74 String request_url = target_uri+nodes_search_path;
76 request_url = processPathData(request_url, requestProperties);
78 if(resourceVersion != null) {
79 request_url = request_url +"?resource-version="+resourceVersion;
81 URL http_req_url = new URL(request_url);
83 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
89 public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
90 return getRequestUrl(method, null);
95 public String toJSONString() {
96 ObjectMapper mapper = getObjectMapper();
97 SearchResults tenant = (SearchResults)requestDatum;
98 String json_text = null;
100 json_text = mapper.writeValueAsString(tenant);
101 } catch (JsonProcessingException exc) {
102 handleException(this, exc);
110 public String[] getArgsList() {
111 String[] args = {NODE_TYPE, ENTITY_IDENTIFIER, ENTITY_VALUE};
117 public Class<? extends AAIDatum> getModelClass() {
118 return SearchResults.class;
122 public static String processPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException {
124 String key = ENTITY_IDENTIFIER;
126 String encoded_vnf = encodeQuery(requestProperties.getProperty(key));
127 request_url = request_url.replace("{entity-identifier}", encoded_vnf) ;
128 aaiService.LOGwriteDateTrace("entity-identifier", requestProperties.getProperty(key));
132 encoded_vnf = encodeQuery(requestProperties.getProperty(key));
133 request_url = request_url.replace("{entity-name}", encoded_vnf) ;
134 aaiService.LOGwriteDateTrace("entity-name", requestProperties.getProperty(key));
138 encoded_vnf = encodeQuery(requestProperties.getProperty(key));
139 request_url = request_url.replace("{node-type}", encoded_vnf) ;
140 aaiService.LOGwriteDateTrace("node-type", requestProperties.getProperty(key));