Fix license headers
[ccsdk/sli/adaptors.git] / aai-service / provider / src / main / java / org / onap / ccsdk / sli / adaptors / aai / SelfLinkRequest.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.URI;
27 import java.net.URL;
28
29 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
30
31 import com.fasterxml.jackson.core.JsonProcessingException;
32 import com.fasterxml.jackson.databind.ObjectMapper;
33 import com.google.common.base.Joiner;
34
35 public class SelfLinkRequest extends AAIRequest {
36         
37         private final  Class<? extends AAIDatum> classType;
38         
39         public static final String SELFLINK = "selflink";
40
41         public SelfLinkRequest(Class<?> type) {
42                 classType = (Class<? extends AAIDatum>)type;
43         }
44
45         
46         @Override
47         public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
48
49                 String request_url = null;
50                 
51                 request_url = requestProperties.getProperty(SELFLINK);
52                 try {
53                         URI uri = new URI(request_url);
54                         if(uri.getHost() == null) {
55                                 request_url = target_uri + request_url;
56                         }
57                 } catch(Exception exc) {
58                         LOG.error("SelfLinkRequest.getRequestUrl", exc);
59                 }
60                 String query = null;
61                 
62                 if(request_url.contains("?")) {
63                         query = request_url.substring(request_url.indexOf("?"));
64                         Joiner.MapJoiner mapJoiner = Joiner.on(",").withKeyValueSeparator("=");
65 //                      String queryString = mapJoiner.join(query);
66                 } else {
67                         request_url = request_url + "?depth=1";
68                 }
69
70                 URL http_req_url =      new URL(request_url);
71
72                 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
73                 
74                 return http_req_url;
75         }
76         
77         @Override
78         public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
79                 return this.getRequestUrl(method, null);
80         }
81
82
83         @Override
84         public String toJSONString() {
85                 ObjectMapper mapper = getObjectMapper();
86                 String json_text = null;
87                 try {
88                         json_text = mapper.writeValueAsString(classType);
89                 } catch (JsonProcessingException exc) {
90                         handleException(this, exc);
91                         return null;
92                 }
93                 return json_text;
94         }
95
96         @Override
97         public String[] getArgsList() {
98                 String[] args = {SELFLINK};
99                 return args;
100         }
101         
102         @Override
103         public Class<? extends AAIDatum> getModelClass() {
104                 return classType;
105         }
106 }