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 @Value("${aai.header.transaction.id}")
45 private String aaiTransactionId;
47 private static final String HEADER_AUTHORIZATION = "Authorization";
48 private static final String X_FROM_APP_ID = "X-FromAppId";
49 private static final Logger LOGGER = LoggerFactory.getLogger(AaiClient.class);
50 private static final String X_TRANSACTION_ID = "X-TransactionId";
52 private HttpHeaders buildRequestHeaderForAAI() {
54 HttpHeaders httpHeaders = new HttpHeaders();
55 httpHeaders.add(HEADER_AUTHORIZATION, aaiHeaderAuthorization);
56 httpHeaders.add(X_FROM_APP_ID, aaiApiId);
57 httpHeaders.add("Accept", "application/json");
58 httpHeaders.add("Content-Type", "application/json");
59 httpHeaders.add(X_TRANSACTION_ID, aaiTransactionId);
65 public Map getCatalogService(String customerId, String serviceSpecName, String serviceId) {
67 StringBuilder callURL =
68 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_FOR_CUSTOMER_PATH);
69 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
70 callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceSpecName);
71 callUrlFormated = callUrlFormated.replace("$serviceId", serviceId);
73 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
74 if (response != null && response.getStatusCode().equals(HttpStatus.OK)) {
75 return (LinkedHashMap) response.getBody();
81 public Map getVNF(String relatedLink) {
83 StringBuilder callURL = new StringBuilder().append(aaiHost).append(relatedLink);
85 ResponseEntity<Object> response = callApiGet(callURL.toString(), buildRequestHeaderForAAI());
86 return (LinkedHashMap) response.getBody();
87 } catch (BackendFunctionalException e) {
88 LOGGER.error("error on calling {} , {}" , callURL.toString(), e);
93 public Map getServicesInAaiForCustomer(String customerId) {
94 StringBuilder callURL =
95 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICES_FOR_CUSTOMER_PATH);
96 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
98 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
99 return (LinkedHashMap) response.getBody();
100 } catch (BackendFunctionalException e) {
101 LOGGER.error("error on calling {} , {}" , callUrlFormated, e);
106 public Map getServiceInstancesInAaiForCustomer(String customerId, String serviceType) {
107 StringBuilder callURL =
108 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_INSTANCES_PATH);
109 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
110 callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceType);
113 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
114 return (LinkedHashMap) response.getBody();
115 } catch (BackendFunctionalException e) {
116 LOGGER.error("error on calling {} , {}" , callUrlFormated, e);