3 * Copyright (c) 2017 Orange. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org.onap.nbi.apis.serviceinventory;
19 import java.util.LinkedHashMap;
20 import org.onap.nbi.OnapComponentsUrlPaths;
21 import org.springframework.beans.factory.annotation.Value;
22 import org.springframework.http.HttpHeaders;
23 import org.springframework.http.HttpStatus;
24 import org.springframework.http.ResponseEntity;
25 import org.springframework.stereotype.Service;
28 public class AaiClient extends BaseClient {
30 public static final String CUSTOMER_ID = "$customerId";
33 private String aaiHost;
35 @Value("${aai.header.authorization}")
36 private String aaiHeaderAuthorization;
38 @Value("${aai.api.id}")
39 private String aaiApiId;
41 private static final String HEADER_AUTHORIZATION = "Authorization";
42 private static final String X_FROM_APP_ID = "X-FromAppId";
44 private HttpHeaders buildRequestHeaderForAAI() {
46 HttpHeaders httpHeaders = new HttpHeaders();
47 httpHeaders.add(HEADER_AUTHORIZATION, aaiHeaderAuthorization);
48 httpHeaders.add(X_FROM_APP_ID, aaiApiId);
49 httpHeaders.add("Accept", "application/json");
50 httpHeaders.add("Content-Type", "application/json");
55 public LinkedHashMap getCatalogService(String customerId, String serviceSpecName, String serviceId) {
57 StringBuilder callURL =
58 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_FOR_CUSTOMER_PATH);
59 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
60 callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceSpecName);
61 callUrlFormated = callUrlFormated.replace("$serviceId", serviceId);
63 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
64 if (response != null && response.getStatusCode().equals(HttpStatus.OK)) {
65 return (LinkedHashMap) response.getBody();
71 public LinkedHashMap getVNF(String relatedLink) {
73 StringBuilder callURL = new StringBuilder().append(aaiHost).append(relatedLink);
75 ResponseEntity<Object> response = callApiGet(callURL.toString(), buildRequestHeaderForAAI());
76 return (LinkedHashMap) response.getBody();
80 public LinkedHashMap getServicesInAaiForCustomer(String customerId) {
81 StringBuilder callURL =
82 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICES_FOR_CUSTOMER_PATH);
83 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
85 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
86 return (LinkedHashMap) response.getBody();
89 public LinkedHashMap getServiceInstancesInAaiForCustomer(String customerId, String serviceType) {
90 StringBuilder callURL =
91 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_INSTANCES_PATH);
92 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
93 callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceType);
95 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
96 return (LinkedHashMap) response.getBody();