c869bdbf84a9dd2f8578a9dc11fa77d6be0cf3f1
[ccsdk/sli.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                      reserved.
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
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  * 
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=========================================================
22  */
23 /**
24  * @author Rich Tabedzki
25  *
26  */
27 package org.onap.ccsdk.sli.adaptors.aai;
28
29 import java.io.IOException;
30 import java.io.UnsupportedEncodingException;
31 import java.net.MalformedURLException;
32 import java.net.URL;
33 import java.util.Properties;
34
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;
38
39 import com.fasterxml.jackson.core.JsonProcessingException;
40 import com.fasterxml.jackson.databind.ObjectMapper;
41
42
43 public class DslNaradQueryRequest extends AAIRequest {
44
45         private final String generic_search_path;
46
47         public static final String FORMAT = "format";
48
49
50         public DslNaradQueryRequest() {
51                 generic_search_path = "/narad/v24/dsl";
52         }
53
54
55         @Override
56         public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
57
58                 String requestUrl = getTargetUri()+generic_search_path;
59
60                 requestUrl = processPathData(requestUrl, requestProperties);
61
62                 String formatQuery = requestProperties.getProperty(FORMAT);
63
64                 if(formatQuery != null) {
65                         requestUrl = requestUrl +"?format="+formatQuery;
66                 }
67                 URL httpReqUrl =        new URL(requestUrl);
68
69                 aaiService.LOGwriteFirstTrace(method, httpReqUrl.toString());
70
71                 return httpReqUrl;
72         }
73
74         @Override
75         public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
76                 return getRequestUrl(method, null);
77         }
78
79
80         @Override
81         public String toJSONString() {
82                 ObjectMapper mapper = getObjectMapper();
83                 DslNaradQueryRequestData tenant = (DslNaradQueryRequestData)requestDatum;
84                 String jsonText = null;
85                 try {
86                         jsonText = mapper.writeValueAsString(tenant);
87                 } catch (JsonProcessingException exc) {
88                         handleException(this, exc);
89                         return null;
90                 }
91                 return jsonText;
92         }
93
94
95         @Override
96         public String[] getArgsList() {
97                 String[] args = {FORMAT};
98                 return args;
99         }
100
101
102         @Override
103         public Class<? extends AAIDatum> getModelClass() {
104                 return DslNaradQueryRequestData.class;
105         }
106
107
108         public static String processPathData(String requestUrl, Properties requestProperties) throws UnsupportedEncodingException {
109                 return requestUrl;
110         }
111         
112         @Override
113         public AAIDatum jsonStringToObject(String jsonData) throws IOException {
114                 if(jsonData == null) {
115                         return null;
116                 }
117
118                 AAIDatum response = null;
119                 ObjectMapper mapper = getObjectMapper();
120                 response = mapper.readValue(jsonData, FormattedQueryResultList.class);
121                 return response;
122         }
123
124         protected boolean expectsDataFromPUTRequest() {
125                 return true;
126         }
127         
128     public String getTargetUri() {
129         return targetNaradUri;
130     }
131
132 }