1f5f74d17a53696d75fed5a2fb80ae5c7d310daa
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / serviceinventory / AaiClient.java
1 package org.onap.nbi.apis.serviceinventory;
2
3 import java.util.LinkedHashMap;
4 import org.onap.nbi.OnapComponentsUrlPaths;
5 import org.springframework.beans.factory.annotation.Value;
6 import org.springframework.http.HttpHeaders;
7 import org.springframework.http.HttpStatus;
8 import org.springframework.http.ResponseEntity;
9 import org.springframework.stereotype.Service;
10
11 @Service
12 public class AaiClient extends BaseClient {
13
14     public static final String CUSTOMER_ID = "$customerId";
15
16     @Value("${aai.host}")
17     private String aaiHost;
18
19     @Value("${aai.header.authorization}")
20     private String aaiHeaderAuthorization;
21
22     @Value("${aai.api.id}")
23     private String aaiApiId;
24
25     private static final String HEADER_AUTHORIZATION = "Authorization";
26     private static final String X_FROM_APP_ID = "X-FromAppId";
27
28     private HttpHeaders buildRequestHeaderForAAI() {
29
30         HttpHeaders httpHeaders = new HttpHeaders();
31         httpHeaders.add(HEADER_AUTHORIZATION, aaiHeaderAuthorization);
32         httpHeaders.add(X_FROM_APP_ID, aaiApiId);
33         httpHeaders.add("Accept", "application/json");
34         httpHeaders.add("Content-Type", "application/json");
35         return httpHeaders;
36
37     }
38
39     public LinkedHashMap getCatalogService(String customerId, String serviceSpecName, String serviceId) {
40
41         StringBuilder callURL =
42                 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_FOR_CUSTOMER_PATH);
43         String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
44         callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceSpecName);
45         callUrlFormated = callUrlFormated.replace("$serviceId", serviceId);
46
47         ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
48         if (response != null && response.getStatusCode().equals(HttpStatus.OK)) {
49             return (LinkedHashMap) response.getBody();
50         }
51         return null;
52     }
53
54
55     public LinkedHashMap getVNF(String relatedLink) {
56
57         StringBuilder callURL = new StringBuilder().append(aaiHost).append(relatedLink);
58
59         ResponseEntity<Object> response = callApiGet(callURL.toString(), buildRequestHeaderForAAI());
60         return (LinkedHashMap) response.getBody();
61
62     }
63
64     public LinkedHashMap getServicesInAaiForCustomer(String customerId) {
65         StringBuilder callURL =
66                 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICES_FOR_CUSTOMER_PATH);
67         String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
68
69         ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
70         return (LinkedHashMap) response.getBody();
71     }
72
73     public LinkedHashMap getServiceInstancesInAaiForCustomer(String customerId, String serviceType) {
74         StringBuilder callURL =
75                 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_INSTANCES_PATH);
76         String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
77         callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceType);
78
79         ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
80         return (LinkedHashMap) response.getBody();
81     }
82 }