Isolate deprecated code in CCSDK aai-service
[ccsdk/sli/adaptors.git] / aai-service / provider / src / main / java / org / onap / ccsdk / sli / adaptors / aai / GenericQueryRequest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                      reserved.
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.ccsdk.sli.adaptors.aai;
23
24 import java.io.UnsupportedEncodingException;
25 import java.net.MalformedURLException;
26 import java.net.URL;
27 import java.util.Properties;
28
29 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
30 import org.openecomp.aai.inventory.v11.ResultData;
31
32 import com.fasterxml.jackson.core.JsonProcessingException;
33 import com.fasterxml.jackson.databind.ObjectMapper;
34
35 public class GenericQueryRequest extends AAIRequest {
36
37         public static final String GENERIC_SEARCH_PATH                  = "org.onap.ccsdk.sli.adaptors.aai.query.generic";
38
39         private final String generic_search_path;
40
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";
44
45
46         public GenericQueryRequest() {
47                 generic_search_path = configProperties.getProperty(GENERIC_SEARCH_PATH);
48         }
49
50         @Override
51         public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
52
53                 String request_url = targetUri+generic_search_path;
54
55                 request_url = processPathData(request_url, requestProperties);
56
57                 if(resourceVersion != null) {
58                         request_url = request_url +"?resource-version="+resourceVersion;
59                 }
60                 URL http_req_url =      new URL(request_url);
61
62                 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
63
64                 return http_req_url;
65         }
66
67         @Override
68         public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
69                 return getRequestUrl(method, null);
70         }
71
72
73         @Override
74         public String toJSONString() {
75                 ObjectMapper mapper = getObjectMapper();
76                 ResultData tenant = (ResultData)requestDatum;
77                 String json_text = null;
78                 try {
79                         json_text = mapper.writeValueAsString(tenant);
80                 } catch (JsonProcessingException exc) {
81                         handleException(this, exc);
82                         return null;
83                 }
84                 return json_text;
85         }
86
87
88         @Override
89         public String[] getArgsList() {
90                 String[] args = {START_NODE_TYPE, IDENTIFIER, VALUE};
91                 return args;
92         }
93
94
95         @Override
96         public Class<? extends AAIDatum> getModelClass() {
97                 return ResultData.class;
98         }
99
100
101         public static String processPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException {
102
103                 String key = IDENTIFIER;
104
105                 String encoded_vnf = encodeQuery(requestProperties.getProperty(key));
106                 request_url = request_url.replace("{identifier}", encoded_vnf) ;
107                 aaiService.LOGwriteDateTrace("identifier", requestProperties.getProperty(key));
108
109                 key = VALUE;
110
111                 encoded_vnf = encodeQuery(requestProperties.getProperty(key));
112                 request_url = request_url.replace("{value}", encoded_vnf) ;
113                 aaiService.LOGwriteDateTrace("value", requestProperties.getProperty(key));
114
115                 key = START_NODE_TYPE;
116
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));
120
121                 return request_url;
122         }
123 }