Containerization feature of SO
[so.git] / common / src / main / java / org / onap / so / client / aai / AAIClient.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.client.aai;
22
23 import java.net.URI;
24
25 import javax.ws.rs.core.UriBuilder;
26
27 import org.onap.so.client.RestClient;
28 import org.onap.so.client.graphinventory.GraphInventoryClient;
29 import org.onap.so.client.graphinventory.entities.uri.GraphInventoryUri;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public abstract class AAIClient extends GraphInventoryClient {
34
35         private static final String AAI_ROOT = "/aai";
36         protected static Logger logger = LoggerFactory.getLogger(AAIClient.class);
37         protected AAIVersion version;
38         public AAIClient() {
39                 super(AAIProperties.class);
40         }
41         
42         public AAIClient(AAIVersion version) {
43                 super(AAIProperties.class);
44         }
45         @Override
46         protected URI constructPath(GraphInventoryUri uri) {
47                 
48                 return UriBuilder.fromUri(AAI_ROOT + "/" + this.getVersion().toString() + uri.build().toString()).build();
49         }
50         @Override
51         protected RestClient createClient(GraphInventoryUri uri) {
52                 return new AAIRestClient(getRestProperties(), constructPath(uri));
53         }
54         
55         protected AAIVersion getVersion() {
56                 if (version == null) {
57                         return this.<AAIProperties>getRestProperties().getDefaultVersion();
58                 } else {
59                         return this.version;
60                 }
61         }
62 }