Sonar fix: UpdateRequest.java
[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  * Modifications Copyright (C) 2018 IBM.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.ccsdk.sli.adaptors.aai;
24
25 import java.io.UnsupportedEncodingException;
26 import java.net.MalformedURLException;
27 import java.net.URISyntaxException;
28 import java.net.URL;
29 import java.util.Map;
30 import java.util.Properties;
31
32 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
33
34 import com.fasterxml.jackson.core.JsonProcessingException;
35 import com.fasterxml.jackson.databind.ObjectMapper;
36
37 public class UpdateRequest extends AAIRequest {
38         
39         private AAIRequest request;
40         private Map<String, String> params;
41
42         public UpdateRequest(AAIRequest request, Map<String, String> parms) {
43                 this.request = request;
44                 this.params = parms;
45         }
46
47         @Override
48         public URL getRequestUrl(String method, String resourceVersion)
49                         throws UnsupportedEncodingException, MalformedURLException, URISyntaxException {
50                 return request.getRequestUrl(method, resourceVersion);
51         }
52
53         @Override
54         public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException, URISyntaxException {
55                 return request.getRequestQueryUrl(method);
56         }
57
58         @Override
59         public String toJSONString() {
60                 ObjectMapper mapper = AAIService.getObjectMapper();
61                 String json = null;
62                 
63                 try {
64                         json = mapper.writeValueAsString(params);
65                 } catch (JsonProcessingException e) {
66                         LOG.error("Could not convert parameters of " + request.getRequestObject().getClass().getName(), e);
67                 }
68                 
69                 return json;
70         }
71
72         @Override
73         public String[] getArgsList() {
74                 return request.getArgsList();
75         }
76
77         @Override
78         public Class<? extends AAIDatum> getModelClass() {
79                 return request.getModelClass();
80         }
81         
82         @Override
83         public void addRequestProperty(String key, String value) {
84                 request.requestProperties.put(key, value);
85         }
86
87         public static String processPathData(String requestUrl, Properties requestProperties) {
88                 
89 //              if(request != null) {
90 //                      Class<?> clazz = request.getClass();
91 //                      Method function = null;
92 //                      try {
93 //                              function = clazz.getMethod("processPathData", request_url.getClass(), requestProperties.getClass());
94 //                              request_url = (String) function.invoke(null, request_url,  requestProperties);
95 //                      } catch (Exception e) {
96 //                              e.printStackTrace();
97 //                      }
98 //              }
99                 
100 //              request.processPathData(request_url, requestProperties);
101                 return requestUrl;
102         }
103         
104         public void processRequestPathValues(Map<String, String> nameValues) {
105                 request.processRequestPathValues(nameValues);
106         }
107
108 }