2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * Modifications Copyright (C) 2018 IBM.
8 * Modifications Copyright (C) 2019 IBM.
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 * @author Rich Tabedzki
27 package org.onap.ccsdk.sli.adaptors.aai;
29 import java.io.IOException;
30 import java.io.UnsupportedEncodingException;
31 import java.net.MalformedURLException;
33 import java.util.Properties;
35 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
36 import org.onap.ccsdk.sli.adaptors.aai.query.DslNaradQueryRequestData;
37 import org.onap.ccsdk.sli.adaptors.aai.query.FormattedQueryResultList;
39 import com.fasterxml.jackson.core.JsonProcessingException;
40 import com.fasterxml.jackson.databind.ObjectMapper;
43 public class DslNaradQueryRequest extends AAIRequest {
45 private final String generic_search_path;
47 public static final String FORMAT = "format";
50 public DslNaradQueryRequest() {
51 generic_search_path = "/narad/v24/dsl";
56 public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
58 String requestUrl = getTargetUri()+generic_search_path;
60 requestUrl = processPathData(requestUrl, requestProperties);
62 String formatQuery = requestProperties.getProperty(FORMAT);
64 if(formatQuery != null) {
65 requestUrl = requestUrl +"?format="+formatQuery;
67 URL httpReqUrl = new URL(requestUrl);
69 aaiService.LOGwriteFirstTrace(method, httpReqUrl.toString());
75 public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
76 return getRequestUrl(method, null);
81 public String toJSONString() {
82 ObjectMapper mapper = getObjectMapper();
83 DslNaradQueryRequestData tenant = (DslNaradQueryRequestData)requestDatum;
84 String jsonText = null;
86 jsonText = mapper.writeValueAsString(tenant);
87 } catch (JsonProcessingException exc) {
88 handleException(this, exc);
96 public String[] getArgsList() {
97 String[] args = {FORMAT};
103 public Class<? extends AAIDatum> getModelClass() {
104 return DslNaradQueryRequestData.class;
108 public static String processPathData(String requestUrl, Properties requestProperties) throws UnsupportedEncodingException {
113 public AAIDatum jsonStringToObject(String jsonData) throws IOException {
114 if(jsonData == null) {
118 AAIDatum response = null;
119 ObjectMapper mapper = getObjectMapper();
120 response = mapper.readValue(jsonData, FormattedQueryResultList.class);
124 protected boolean expectsDataFromPUTRequest() {
128 public String getTargetUri() {
129 return targetNaradUri;