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