2 * Copyright (c) 2018 Orange
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.nbi.apis.serviceinventory;
18 import java.util.LinkedHashMap;
19 import org.onap.nbi.OnapComponentsUrlPaths;
20 import org.onap.nbi.exceptions.BackendFunctionalException;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.springframework.beans.factory.annotation.Value;
24 import org.springframework.http.HttpHeaders;
25 import org.springframework.http.HttpStatus;
26 import org.springframework.http.ResponseEntity;
27 import org.springframework.stereotype.Service;
30 public class AaiClient extends BaseClient {
32 public static final String CUSTOMER_ID = "$customerId";
35 private String aaiHost;
37 @Value("${aai.header.authorization}")
38 private String aaiHeaderAuthorization;
40 @Value("${aai.api.id}")
41 private String aaiApiId;
43 private static final String HEADER_AUTHORIZATION = "Authorization";
44 private static final String X_FROM_APP_ID = "X-FromAppId";
45 private static final Logger LOGGER = LoggerFactory.getLogger(AaiClient.class);
47 private HttpHeaders buildRequestHeaderForAAI() {
49 HttpHeaders httpHeaders = new HttpHeaders();
50 httpHeaders.add(HEADER_AUTHORIZATION, aaiHeaderAuthorization);
51 httpHeaders.add(X_FROM_APP_ID, aaiApiId);
52 httpHeaders.add("Accept", "application/json");
53 httpHeaders.add("Content-Type", "application/json");
58 public LinkedHashMap getCatalogService(String customerId, String serviceSpecName, String serviceId) {
60 StringBuilder callURL =
61 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_FOR_CUSTOMER_PATH);
62 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
63 callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceSpecName);
64 callUrlFormated = callUrlFormated.replace("$serviceId", serviceId);
66 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
67 if (response != null && response.getStatusCode().equals(HttpStatus.OK)) {
68 return (LinkedHashMap) response.getBody();
74 public LinkedHashMap getVNF(String relatedLink) {
76 StringBuilder callURL = new StringBuilder().append(aaiHost).append(relatedLink);
78 ResponseEntity<Object> response = callApiGet(callURL.toString(), buildRequestHeaderForAAI());
79 return (LinkedHashMap) response.getBody();
83 public LinkedHashMap getServicesInAaiForCustomer(String customerId) {
84 StringBuilder callURL =
85 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICES_FOR_CUSTOMER_PATH);
86 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
88 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
89 return (LinkedHashMap) response.getBody();
90 } catch (BackendFunctionalException e) {
91 LOGGER.error("error on calling {0} , {1}" , callUrlFormated, e);
96 public LinkedHashMap getServiceInstancesInAaiForCustomer(String customerId, String serviceType) {
97 StringBuilder callURL =
98 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_INSTANCES_PATH);
99 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
100 callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceType);
103 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
104 return (LinkedHashMap) response.getBody();
105 } catch (BackendFunctionalException e) {
106 LOGGER.error("error on calling {0} , {1}" , callUrlFormated, e);