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.IOException;
25 import java.io.UnsupportedEncodingException;
26 import java.net.MalformedURLException;
28 import java.util.Properties;
30 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
31 import org.onap.ccsdk.sli.adaptors.aai.query.FormattedQueryRequestData;
32 import org.onap.ccsdk.sli.adaptors.aai.query.FormattedQueryResultList;
34 import com.fasterxml.jackson.core.JsonParseException;
35 import com.fasterxml.jackson.core.JsonProcessingException;
36 import com.fasterxml.jackson.databind.JsonMappingException;
37 import com.fasterxml.jackson.databind.ObjectMapper;
40 public class CustomQueryRequest extends AAIRequest {
42 public static final String GENERIC_SEARCH_PATH = "org.onap.ccsdk.sli.adaptors.aai.query.generic";
44 private final String generic_search_path;
46 public static final String FORMAT = "format";
49 public CustomQueryRequest() {
50 String tmp_generic_search_path = configProperties.getProperty(GENERIC_SEARCH_PATH);
51 tmp_generic_search_path = tmp_generic_search_path.split("search")[0];
52 generic_search_path = tmp_generic_search_path +"query";
57 public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
59 String request_url = target_uri+generic_search_path;
61 request_url = processPathData(request_url, requestProperties);
63 String formatQuery = requestProperties.getProperty(FORMAT);
65 if(formatQuery != null) {
66 request_url = request_url +"?format="+formatQuery;
68 URL http_req_url = new URL(request_url);
70 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
76 public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
77 return getRequestUrl(method, null);
82 public String toJSONString() {
83 ObjectMapper mapper = getObjectMapper();
84 FormattedQueryRequestData tenant = (FormattedQueryRequestData)requestDatum;
85 String json_text = null;
87 json_text = mapper.writeValueAsString(tenant);
88 } catch (JsonProcessingException exc) {
89 handleException(this, exc);
97 public String[] getArgsList() {
98 String[] args = {FORMAT};
104 public Class<? extends AAIDatum> getModelClass() {
105 return FormattedQueryRequestData.class;
109 public static String processPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException {
113 String encoded_vnf = encodeQuery(requestProperties.getProperty(key));
114 request_url = request_url.replace("{identifier}", encoded_vnf) ;
115 aaiService.LOGwriteDateTrace("identifier", requestProperties.getProperty(key));
120 public AAIDatum jsonStringToObject(String jsonData) throws JsonParseException, JsonMappingException, IOException {
121 if(jsonData == null) {
125 AAIDatum response = null;
126 ObjectMapper mapper = getObjectMapper();
127 response = mapper.readValue(jsonData, FormattedQueryResultList.class);
131 protected boolean expectsDataFromPUTRequest() {