72a381a0489ab907e60d9be14f2f8b0a51852c4f
[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.NotFoundException;
26 import javax.ws.rs.core.UriBuilder;
27
28 import org.onap.so.client.RestClient;
29 import org.onap.so.client.graphinventory.GraphInventoryClient;
30 import org.onap.so.client.graphinventory.GraphInventoryVersion;
31 import org.onap.so.client.graphinventory.entities.uri.GraphInventoryUri;
32 import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriComputationException;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class AAIClient extends GraphInventoryClient {
37
38         private static final String AAI_ROOT = "/aai";
39         protected static Logger logger = LoggerFactory.getLogger(AAIClient.class);
40         protected AAIVersion version;
41         protected AAIClient() {
42                 super(AAIProperties.class);
43         }
44         
45         protected AAIClient(AAIVersion version) {
46                 super(AAIProperties.class);
47                 this.version = version;
48         }
49         @Override
50         protected URI constructPath(GraphInventoryUri uri) {
51                 
52                 return UriBuilder.fromUri(AAI_ROOT + "/" + this.getVersion().toString() + uri.build().toString()).build();
53         }
54
55         @Override
56         public RestClient createClient(GraphInventoryUri uri) {
57                 try {
58                         return new AAIRestClient(getRestProperties(), constructPath(uri));
59                 } catch (GraphInventoryUriComputationException | NotFoundException e) {
60                         logger.debug("failed to construct A&AI uri", e);
61                         throw e;
62                 }
63         }
64         
65         @Override
66         public AAIVersion getVersion() {
67                 if (version == null) {
68                         return this.<AAIProperties>getRestProperties().getDefaultVersion();
69                 } else {
70                         return this.version;
71                 }
72         }
73         
74
75         @Override
76         public String getGraphDBName() {
77                 return "A&AI";
78         }
79 }