Merge "Reorder modifiers"
[so.git] / common / src / main / java / org / openecomp / mso / 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.openecomp.mso.client.aai;
22
23 import java.net.URI;
24 import java.util.UUID;
25
26 import javax.ws.rs.core.UriBuilder;
27
28 import org.openecomp.mso.client.RestPropertiesLoader;
29 import org.openecomp.mso.client.aai.entities.uri.AAIUri;
30 import org.openecomp.mso.client.defaultproperties.DefaultAAIPropertiesImpl;
31 import org.openecomp.mso.client.policy.RestClient;
32
33 import com.att.eelf.configuration.EELFLogger;
34 import com.att.eelf.configuration.EELFManager;
35
36 public abstract class AAIClient {
37
38         protected final AAIVersion defaultVersion;
39         private static final String AAI_ROOT = "/aai";
40         protected final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
41         private final AAIProperties properties;
42         protected final UUID requestId;
43         public AAIClient(UUID requestId) {
44                 AAIProperties props = RestPropertiesLoader.getInstance().getNewImpl(AAIProperties.class);
45                 if (props == null) {
46                         metricsLogger.error("No RestProperty.AAIProperties implementation found on classpath");
47                         props = new DefaultAAIPropertiesImpl();
48                 }
49                 this.properties = props;
50                 this.defaultVersion = props.getDefaultVersion();
51                 this.requestId = requestId;
52         }
53         protected URI constructPath(AAIUri uri) {
54                 
55                 return UriBuilder.fromUri(AAI_ROOT + "/" + this.getVersion().toString() + uri.build().toString()).build();
56         }
57         
58         protected RestClient createClient(AAIUri uri) {
59                 return new AAIRestClient(properties, this.getRequestId(), constructPath(uri)).addRequestId(this.getRequestId());
60
61         }
62         
63         protected UUID getRequestId() {
64                 return this.requestId;
65         }
66         protected AAIVersion getVersion() {
67                 return defaultVersion;
68         }
69 }