[SDNC-30] summary
[ccsdk/sli/adaptors.git] / aai-service / provider / src / main / java / org / onap / ccsdk / sli / adaptors / aai / RelationshipRequest.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.onap.ccsdk.sli.adaptors.aai;
23
24 import java.io.UnsupportedEncodingException;
25 import java.net.MalformedURLException;
26 import java.net.URL;
27
28 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
29 import org.openecomp.aai.inventory.v11.RelationshipList;
30
31 import com.fasterxml.jackson.core.JsonProcessingException;
32 import com.fasterxml.jackson.databind.ObjectMapper;
33
34 public class RelationshipRequest extends AAIRequest {
35
36         // tenant (1602)
37         public static final String RELATIONSHIP_LIST_PATH               = "org.onap.ccsdk.sli.adaptors.aai.path.relationship.list";
38         public static final String RELATIONSHIP_LIST_QUERY_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.relationship.list.query";
39         
40         private final String relationship_path;
41         private final String relationship_query_path;
42         
43         public static final String RELATED_TO = "related-to";
44         public static final String RELATIONSHIP_KEY = "relationship-key";
45
46         public RelationshipRequest() {
47                 relationship_path = configProperties.getProperty(RELATIONSHIP_LIST_PATH, "/relationship-list/relationship");
48                 relationship_query_path = configProperties.getProperty(RELATIONSHIP_LIST_QUERY_PATH);
49         }
50
51         
52         @Override
53         public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
54
55                 AAIRequest masterRequest = (AAIRequest)requestProperties.get(MASTER_REQUEST);
56                 URL masterURL = masterRequest.getRequestUrl(method, null);
57                 
58                 String request_url = masterURL.toString();
59                 request_url = request_url + relationship_path;
60                 
61                 if(request_url.contains("//")) {
62                         request_url = request_url.replaceAll("//", "/");
63                 }
64
65                 if(requestProperties.containsKey(RELATED_TO)) {
66                         String encoded_vnf = encodeQuery(requestProperties.getProperty(RELATED_TO));
67                         request_url = request_url.replace("{related-to}", encoded_vnf) ;                        
68                 }
69
70 //              if(resourceVersion != null) {
71 //                      request_url = request_url +"?resource-version="+resourceVersion;
72 //              }
73                 URL http_req_url =      new URL(request_url);
74
75                 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
76                 aaiService.LOGwriteDateTrace("related-to", requestProperties.getProperty(RELATED_TO));
77                 
78                 return http_req_url;
79         }
80         
81         @Override
82         public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
83
84                 String request_url = target_uri+relationship_query_path;
85                 String encoded_vnf = encodeQuery(requestProperties.getProperty(RELATIONSHIP_KEY));
86                 request_url = request_url.replace("{tenant-name}", encoded_vnf) ;
87                 URL http_req_url =      new URL(request_url);
88
89                 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
90                 aaiService.LOGwriteDateTrace("tenant_name", requestProperties.getProperty(RELATIONSHIP_KEY));
91                 
92                 return http_req_url;
93         }
94
95
96         @Override
97         public String toJSONString() {
98                 ObjectMapper mapper = getObjectMapper();
99                 Object tenant = requestDatum;
100                 String json_text = null;
101                 try {
102                         json_text = mapper.writeValueAsString(tenant);
103                 } catch (JsonProcessingException exc) {
104                         handleException(this, exc);
105                         return null;
106                 }
107                 return json_text;
108         }
109
110
111         @Override
112         public String[] getArgsList() {
113                 String[] args = {RELATED_TO, RELATIONSHIP_KEY};
114                 return args;
115         }
116
117
118         @Override
119         public Class<? extends AAIDatum> getModelClass() {
120                 return RelationshipList.class;
121         }
122         
123         public boolean isDeleteDataRequired() {
124                 return true;
125         }
126 }