2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.openecomp.sdnc.sli.aai;
24 import java.io.UnsupportedEncodingException;
25 import java.net.MalformedURLException;
28 import org.openecomp.aai.inventory.v10.RelationshipList;
29 import org.openecomp.sdnc.sli.aai.data.AAIDatum;
31 import com.fasterxml.jackson.core.JsonProcessingException;
32 import com.fasterxml.jackson.databind.ObjectMapper;
34 public class RelationshipRequest extends AAIRequest {
37 public static final String RELATIONSHIP_LIST_PATH = "org.openecomp.sdnc.sli.aai.path.relationship.list";
38 public static final String RELATIONSHIP_LIST_QUERY_PATH = "org.openecomp.sdnc.sli.aai.path.relationship.list.query";
40 private final String relationship_path;
41 private final String relationship_query_path;
43 public static final String RELATED_TO = "related-to";
44 public static final String RELATIONSHIP_KEY = "relationship-key";
46 public RelationshipRequest() {
47 relationship_path = configProperties.getProperty(RELATIONSHIP_LIST_PATH, "/relationship-list/relationship");
48 relationship_query_path = configProperties.getProperty(RELATIONSHIP_LIST_QUERY_PATH);
53 public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
55 AAIRequest masterRequest = (AAIRequest)requestProperties.get(MASTER_REQUEST);
56 URL masterURL = masterRequest.getRequestUrl(method, null);
58 String request_url = masterURL.toString();
59 request_url = request_url + relationship_path;
61 if(request_url.contains("//")) {
62 request_url = request_url.replaceAll("//", "/");
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) ;
70 // if(resourceVersion != null) {
71 // request_url = request_url +"?resource-version="+resourceVersion;
73 URL http_req_url = new URL(request_url);
75 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
76 aaiService.LOGwriteDateTrace("related-to", requestProperties.getProperty(RELATED_TO));
82 public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
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);
89 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
90 aaiService.LOGwriteDateTrace("tenant_name", requestProperties.getProperty(RELATIONSHIP_KEY));
97 public String toJSONString() {
98 ObjectMapper mapper = getObjectMapper();
99 Object tenant = requestDatum;
100 String json_text = null;
102 json_text = mapper.writeValueAsString(tenant);
103 } catch (JsonProcessingException exc) {
104 handleException(this, exc);
112 public String[] getArgsList() {
113 String[] args = {RELATED_TO, RELATIONSHIP_KEY};
119 public Class<? extends AAIDatum> getModelClass() {
120 return RelationshipList.class;
123 public boolean isDeleteDataRequired() {