Add Apache license header per file
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / serviceinventory / AaiClient.java
1 /**
2  *
3  *     Copyright (c) 2017 Orange.  All rights reserved.
4  *
5  *     Licensed under the Apache License, Version 2.0 (the "License");
6  *     you may not use this file except in compliance with the License.
7  *     You may obtain a copy of the License at
8  *
9  *         http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *     Unless required by applicable law or agreed to in writing, software
12  *     distributed under the License is distributed on an "AS IS" BASIS,
13  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *     See the License for the specific language governing permissions and
15  *     limitations under the License.
16  */
17 package org.onap.nbi.apis.serviceinventory;
18
19 import java.util.LinkedHashMap;
20 import org.onap.nbi.OnapComponentsUrlPaths;
21 import org.springframework.beans.factory.annotation.Value;
22 import org.springframework.http.HttpHeaders;
23 import org.springframework.http.HttpStatus;
24 import org.springframework.http.ResponseEntity;
25 import org.springframework.stereotype.Service;
26
27 @Service
28 public class AaiClient extends BaseClient {
29
30     public static final String CUSTOMER_ID = "$customerId";
31
32     @Value("${aai.host}")
33     private String aaiHost;
34
35     @Value("${aai.header.authorization}")
36     private String aaiHeaderAuthorization;
37
38     @Value("${aai.api.id}")
39     private String aaiApiId;
40
41     private static final String HEADER_AUTHORIZATION = "Authorization";
42     private static final String X_FROM_APP_ID = "X-FromAppId";
43
44     private HttpHeaders buildRequestHeaderForAAI() {
45
46         HttpHeaders httpHeaders = new HttpHeaders();
47         httpHeaders.add(HEADER_AUTHORIZATION, aaiHeaderAuthorization);
48         httpHeaders.add(X_FROM_APP_ID, aaiApiId);
49         httpHeaders.add("Accept", "application/json");
50         httpHeaders.add("Content-Type", "application/json");
51         return httpHeaders;
52
53     }
54
55     public LinkedHashMap getCatalogService(String customerId, String serviceSpecName, String serviceId) {
56
57         StringBuilder callURL =
58                 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_FOR_CUSTOMER_PATH);
59         String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
60         callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceSpecName);
61         callUrlFormated = callUrlFormated.replace("$serviceId", serviceId);
62
63         ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
64         if (response != null && response.getStatusCode().equals(HttpStatus.OK)) {
65             return (LinkedHashMap) response.getBody();
66         }
67         return null;
68     }
69
70
71     public LinkedHashMap getVNF(String relatedLink) {
72
73         StringBuilder callURL = new StringBuilder().append(aaiHost).append(relatedLink);
74
75         ResponseEntity<Object> response = callApiGet(callURL.toString(), buildRequestHeaderForAAI());
76         return (LinkedHashMap) response.getBody();
77
78     }
79
80     public LinkedHashMap getServicesInAaiForCustomer(String customerId) {
81         StringBuilder callURL =
82                 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICES_FOR_CUSTOMER_PATH);
83         String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
84
85         ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
86         return (LinkedHashMap) response.getBody();
87     }
88
89     public LinkedHashMap getServiceInstancesInAaiForCustomer(String customerId, String serviceType) {
90         StringBuilder callURL =
91                 new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICE_INSTANCES_PATH);
92         String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId);
93         callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceType);
94
95         ResponseEntity<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
96         return (LinkedHashMap) response.getBody();
97     }
98 }