2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T 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.ResultData;
32 import com.fasterxml.jackson.core.JsonProcessingException;
33 import com.fasterxml.jackson.databind.ObjectMapper;
35 public class GenericQueryRequest extends AAIRequest {
37 public static final String GENERIC_SEARCH_PATH = "org.onap.ccsdk.sli.adaptors.aai.query.generic";
39 private final String generic_search_path;
41 public static final String START_NODE_TYPE = "start-node-type";
42 public static final String IDENTIFIER = "identifier";
43 public static final String VALUE = "value";
46 public GenericQueryRequest() {
47 generic_search_path = configProperties.getProperty(GENERIC_SEARCH_PATH);
51 public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
53 String request_url = targetUri+generic_search_path;
55 request_url = processPathData(request_url, requestProperties);
57 if(resourceVersion != null) {
58 request_url = request_url +"?resource-version="+resourceVersion;
60 URL http_req_url = new URL(request_url);
62 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
68 public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
69 return getRequestUrl(method, null);
74 public String toJSONString() {
75 ObjectMapper mapper = getObjectMapper();
76 ResultData tenant = (ResultData)requestDatum;
77 String json_text = null;
79 json_text = mapper.writeValueAsString(tenant);
80 } catch (JsonProcessingException exc) {
81 handleException(this, exc);
89 public String[] getArgsList() {
90 String[] args = {START_NODE_TYPE, IDENTIFIER, VALUE};
96 public Class<? extends AAIDatum> getModelClass() {
97 return ResultData.class;
101 public static String processPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException {
103 String key = IDENTIFIER;
105 String encoded_vnf = encodeQuery(requestProperties.getProperty(key));
106 request_url = request_url.replace("{identifier}", encoded_vnf) ;
107 aaiService.LOGwriteDateTrace("identifier", requestProperties.getProperty(key));
111 encoded_vnf = encodeQuery(requestProperties.getProperty(key));
112 request_url = request_url.replace("{value}", encoded_vnf) ;
113 aaiService.LOGwriteDateTrace("value", requestProperties.getProperty(key));
115 key = START_NODE_TYPE;
117 encoded_vnf = encodeQuery(requestProperties.getProperty(key));
118 request_url = request_url.replace("{start-node-type}", encoded_vnf) ;
119 aaiService.LOGwriteDateTrace("start-node-type", requestProperties.getProperty(key));