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.springframework.beans.factory.annotation.Value;
21 import org.springframework.http.HttpHeaders;
22 import org.springframework.http.HttpStatus;
23 import org.springframework.http.ResponseEntity;
24 import org.springframework.stereotype.Service;
27 public class AaiClient extends BaseClient {
29 public static final String CUSTOMER_ID = "$customerId";
32 private String aaiHost;
34 @Value("${aai.header.authorization}")
35 private String aaiHeaderAuthorization;
37 @Value("${aai.api.id}")
38 private String aaiApiId;
40 private static final String HEADER_AUTHORIZATION = "Authorization";
41 private static final String X_FROM_APP_ID = "X-FromAppId";
43 private HttpHeaders buildRequestHeaderForAAI() {
45 HttpHeaders httpHeaders = new HttpHeaders();
46 httpHeaders.add(HEADER_AUTHORIZATION, aaiHeaderAuthorization);
47 httpHeaders.add(X_FROM_APP_ID, aaiApiId);
48 httpHeaders.add("Accept", "application/json");
49 httpHeaders.add("Content-Type", "application/json");
54 public LinkedHashMap getCatalogService(String customerId, String serviceSpecName, String serviceId) {
56 StringBuilder callURL =
57 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_FOR_CUSTOMER_PATH);
58 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
59 callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceSpecName);
60 callUrlFormated = callUrlFormated.replace("$serviceId", serviceId);
62 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
63 if (response != null && response.getStatusCode().equals(HttpStatus.OK)) {
64 return (LinkedHashMap) response.getBody();
70 public LinkedHashMap getVNF(String relatedLink) {
72 StringBuilder callURL = new StringBuilder().append(aaiHost).append(relatedLink);
74 ResponseEntity<Object> response = callApiGet(callURL.toString(), buildRequestHeaderForAAI());
75 return (LinkedHashMap) response.getBody();
79 public LinkedHashMap getServicesInAaiForCustomer(String customerId) {
80 StringBuilder callURL =
81 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICES_FOR_CUSTOMER_PATH);
82 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
84 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
85 return (LinkedHashMap) response.getBody();
88 public LinkedHashMap getServiceInstancesInAaiForCustomer(String customerId, String serviceType) {
89 StringBuilder callURL =
90 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_INSTANCES_PATH);
91 String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
92 callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceType);
94 ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
95 return (LinkedHashMap) response.getBody();