Isolate deprecated code in CCSDK aai-service
[ccsdk/sli/adaptors.git] / aai-service / provider / src / main / java / org / onap / ccsdk / sli / adaptors / aai / UpdateRequest.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.URISyntaxException;
27 import java.net.URL;
28 import java.util.Map;
29 import java.util.Properties;
30
31 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
32
33 import com.fasterxml.jackson.core.JsonProcessingException;
34 import com.fasterxml.jackson.databind.ObjectMapper;
35
36 public class UpdateRequest extends AAIRequest {
37         
38         private AAIRequest request;
39         private Map<String, String> params;
40
41         public UpdateRequest(AAIRequest request, Map<String, String> parms) {
42                 this.request = request;
43                 this.params = parms;
44         }
45
46         @Override
47         public URL getRequestUrl(String method, String resourceVersion)
48                         throws UnsupportedEncodingException, MalformedURLException, URISyntaxException {
49                 return request.getRequestUrl(method, resourceVersion);
50         }
51
52         @Override
53         public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException, URISyntaxException {
54                 return request.getRequestQueryUrl(method);
55         }
56
57         @Override
58         public String toJSONString() {
59                 ObjectMapper mapper = AAIService.getObjectMapper();
60                 String json = null;
61                 
62                 try {
63                         json = mapper.writeValueAsString(params);
64                 } catch (JsonProcessingException e) {
65                         LOG.error("Could not convert parameters of " + request.getRequestObject().getClass().getName(), e);
66                 }
67                 
68                 return json;
69         }
70
71         @Override
72         public String[] getArgsList() {
73                 return request.getArgsList();
74         }
75
76         @Override
77         public Class<? extends AAIDatum> getModelClass() {
78                 return request.getModelClass();
79         }
80         
81         @Override
82         public void addRequestProperty(String key, String value) {
83                 request.requestProperties.put(key, value);
84         }
85
86         public static String processPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException {
87                 
88 //              if(request != null) {
89 //                      Class<?> clazz = request.getClass();
90 //                      Method function = null;
91 //                      try {
92 //                              function = clazz.getMethod("processPathData", request_url.getClass(), requestProperties.getClass());
93 //                              request_url = (String) function.invoke(null, request_url,  requestProperties);
94 //                      } catch (Exception e) {
95 //                              e.printStackTrace();
96 //                      }
97 //              }
98                 
99 //              request.processPathData(request_url, requestProperties);
100                 return request_url; 
101         }
102         
103         public void processRequestPathValues(Map<String, String> nameValues) {
104                 request.processRequestPathValues(nameValues);
105         }
106
107 }