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.onap.ccsdk.sli.adaptors.aai;
24 import java.io.UnsupportedEncodingException;
25 import java.net.MalformedURLException;
27 import java.util.HashMap;
29 import java.util.Properties;
31 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
32 import org.openecomp.aai.inventory.v10.CloudRegion;
34 import com.fasterxml.jackson.core.JsonProcessingException;
35 import com.fasterxml.jackson.databind.ObjectMapper;
36 import com.google.common.base.Joiner;
38 public class CloudRegionRequest extends AAIRequest {
40 public static final String CLOUD_REGION_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.cloud.region";
42 private final String cloud_region_path;
44 public static final String CLOUD_REGION_CLOUD_OWNER = "cloud-region.cloud-owner";
45 public static final String CLOUD_REGION_CLOUD_REGION_ID = "cloud-region.cloud-region-id";
48 public CloudRegionRequest() {
49 cloud_region_path = configProperties.getProperty(CLOUD_REGION_PATH);
53 public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException {
54 return this.getRequestUrl(method, null);
58 public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException {
60 String request_url = target_uri+cloud_region_path;
62 request_url = processPathData(request_url, requestProperties);
64 Map<String, String> query = new HashMap<String, String>();
65 if(requestProperties.containsKey(DEPTH)) {
66 query.put(DEPTH, requestProperties.getProperty(DEPTH));
69 if(resourceVersion != null) {
70 // request_url = request_url +"?resource-version="+resourceVersion;
71 query.put(RESOURCE_VERSION, resourceVersion);
74 if(!query.isEmpty()) {
75 Joiner.MapJoiner mapJoiner = Joiner.on("&").withKeyValueSeparator("=");
76 String queryString = mapJoiner.join(query);
77 request_url = String.format("%s?%s", request_url, queryString);
79 URL http_req_url = new URL(request_url);
81 aaiService.LOGwriteFirstTrace(method, http_req_url.toString());
88 public String toJSONString() {
89 ObjectMapper mapper = getObjectMapper();
90 CloudRegion vnfc = (CloudRegion)requestDatum;
91 String json_text = null;
93 json_text = mapper.writeValueAsString(vnfc);
94 } catch (JsonProcessingException exc) {
95 handleException(this, exc);
102 public String[] getArgsList() {
105 CLOUD_REGION_CLOUD_OWNER,
106 CLOUD_REGION_CLOUD_REGION_ID,
114 public Class<? extends AAIDatum> getModelClass() {
115 return CloudRegion.class;
118 public static String processPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException {
120 if(!requestProperties.containsKey(CLOUD_REGION_CLOUD_OWNER) || !requestProperties.containsKey(CLOUD_REGION_CLOUD_REGION_ID)) {
121 aaiService.logKeyError(String.format("%s,%s", CLOUD_REGION_CLOUD_OWNER, CLOUD_REGION_CLOUD_REGION_ID));
124 String encoded_vnf = encodeQuery(requestProperties.getProperty(CLOUD_REGION_CLOUD_OWNER));
125 request_url = request_url.replace("{cloud-owner}", encoded_vnf) ;
127 encoded_vnf = encodeQuery(requestProperties.getProperty(CLOUD_REGION_CLOUD_REGION_ID));
128 request_url = request_url.replace("{cloud-region-id}", encoded_vnf) ;
130 aaiService.LOGwriteDateTrace("cloud-owner", requestProperties.getProperty(CLOUD_REGION_CLOUD_OWNER));
131 aaiService.LOGwriteDateTrace("cloud-region-id", requestProperties.getProperty(CLOUD_REGION_CLOUD_REGION_ID));