2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * Modifications Copyright (C) 2018 IBM.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 * @author Rich Tabedzki
26 package org.onap.ccsdk.sli.adaptors.aai;
28 import java.io.IOException;
29 import java.io.UnsupportedEncodingException;
30 import java.net.MalformedURLException;
32 import java.util.Properties;
34 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
35 import org.onap.ccsdk.sli.adaptors.aai.query.FormattedQueryRequestData;
36 import org.onap.ccsdk.sli.adaptors.aai.query.FormattedQueryResultList;
38 import com.fasterxml.jackson.core.JsonProcessingException;
39 import com.fasterxml.jackson.databind.ObjectMapper;
42 public class CustomQueryRequest extends AAIRequest {
44 public static final String GENERIC_SEARCH_PATH_CONST = "org.onap.ccsdk.sli.adaptors.aai.query.generic";
46 private final String generic_search_path;
48 public static final String FORMAT = "format";
51 public CustomQueryRequest() {
52 String tmpGenericSearchPath = configProperties.getProperty(GENERIC_SEARCH_PATH_CONST);
53 tmpGenericSearchPath = tmpGenericSearchPath.split("search")[0];
54 generic_search_path = tmpGenericSearchPath +"query";
59 public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
61 String requestUrl = targetUri+generic_search_path;
63 requestUrl = processPathData(requestUrl, requestProperties);
65 String formatQuery = requestProperties.getProperty(FORMAT);
67 if(formatQuery != null) {
68 requestUrl = requestUrl +"?format="+formatQuery;
70 URL httpReqUrl = new URL(requestUrl);
72 aaiService.LOGwriteFirstTrace(method, httpReqUrl.toString());
78 public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
79 return getRequestUrl(method, null);
84 public String toJSONString() {
85 ObjectMapper mapper = getObjectMapper();
86 FormattedQueryRequestData tenant = (FormattedQueryRequestData)requestDatum;
87 String jsonText = null;
89 jsonText = mapper.writeValueAsString(tenant);
90 } catch (JsonProcessingException exc) {
91 handleException(this, exc);
99 public String[] getArgsList() {
100 String[] args = {FORMAT};
106 public Class<? extends AAIDatum> getModelClass() {
107 return FormattedQueryRequestData.class;
111 public static String processPathData(String requestUrl, Properties requestProperties) throws UnsupportedEncodingException {
115 String encodedVnf = encodeQuery(requestProperties.getProperty(key));
116 requestUrl = requestUrl.replace("{identifier}", encodedVnf) ;
117 aaiService.LOGwriteDateTrace("identifier", requestProperties.getProperty(key));
122 public AAIDatum jsonStringToObject(String jsonData) throws IOException {
123 if(jsonData == null) {
127 AAIDatum response = null;
128 ObjectMapper mapper = getObjectMapper();
129 response = mapper.readValue(jsonData, FormattedQueryResultList.class);
133 protected boolean expectsDataFromPUTRequest() {