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;
20 import org.onap.nbi.OnapComponentsUrlPaths;
21 import org.onap.nbi.exceptions.BackendFunctionalException;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.springframework.beans.factory.annotation.Value;
25 import org.springframework.http.HttpHeaders;
26 import org.springframework.http.HttpStatus;
27 import org.springframework.http.ResponseEntity;
28 import org.springframework.stereotype.Service;
31 public class AaiClient extends BaseClient {
33 public static final String CUSTOMER_ID = "$customerId";
36 private String aaiHost;
38 @Value("${aai.header.authorization}")
39 private String aaiHeaderAuthorization;
41 @Value("${aai.api.id}")
42 private String aaiApiId;
44 private static final String HEADER_AUTHORIZATION = "Authorization";
45 private static final String X_FROM_APP_ID = "X-FromAppId";
46 private static final Logger LOGGER = LoggerFactory.getLogger(AaiClient.class);
48 private HttpHeaders buildRequestHeaderForAAI() {
50 HttpHeaders httpHeaders = new HttpHeaders();
51 httpHeaders.add(HEADER_AUTHORIZATION, aaiHeaderAuthorization);
52 httpHeaders.add(X_FROM_APP_ID, aaiApiId);
53 httpHeaders.add("Accept", "application/json");
54 httpHeaders.add("Content-Type", "application/json");
59 public Map getCatalogService(String customerId, String serviceSpecName, String serviceId) {
61 StringBuilder callURL =
62 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_FOR_CUSTOMER_PATH);
63 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
64 callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceSpecName);
65 callUrlFormated = callUrlFormated.replace("$serviceId", serviceId);
67 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
68 if (response != null && response.getStatusCode().equals(HttpStatus.OK)) {
69 return (LinkedHashMap) response.getBody();
75 public Map getVNF(String relatedLink) {
77 StringBuilder callURL = new StringBuilder().append(aaiHost).append(relatedLink);
79 ResponseEntity<Object> response = callApiGet(callURL.toString(), buildRequestHeaderForAAI());
80 return (LinkedHashMap) response.getBody();
84 public Map getServicesInAaiForCustomer(String customerId) {
85 StringBuilder callURL =
86 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICES_FOR_CUSTOMER_PATH);
87 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
89 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
90 return (LinkedHashMap) response.getBody();
91 } catch (BackendFunctionalException e) {
92 LOGGER.error("error on calling {} , {}" , callUrlFormated, e);
97 public Map getServiceInstancesInAaiForCustomer(String customerId, String serviceType) {
98 StringBuilder callURL =
99 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_INSTANCES_PATH);
100 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
101 callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceType);
104 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
105 return (LinkedHashMap) response.getBody();
106 } catch (BackendFunctionalException e) {
107 LOGGER.error("error on calling {} , {}" , callUrlFormated, e);