2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sparky.dal.aai.config;
26 import java.net.URISyntaxException;
27 import java.util.Properties;
29 import javax.ws.rs.core.UriBuilder;
31 import org.onap.aai.sparky.logging.AaiUiMsgs;
32 import org.onap.aai.sparky.synchronizer.config.TaskProcessorConfig;
33 import org.onap.aai.sparky.util.ConfigHelper;
34 import org.onap.aai.sparky.util.Encryptor;
35 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
36 import org.onap.aai.cl.api.Logger;
37 import org.onap.aai.cl.eelf.LoggerFactory;
39 * The Class ActiveInventoryConfig.
41 public class ActiveInventoryConfig {
45 public static final String CONFIG_FILE =
46 TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "aai.properties";
47 private static ActiveInventoryConfig instance;
48 private static final Logger LOG = LoggerFactory.getInstance().getLogger(
49 ActiveInventoryConfig.class);
50 private static final String HTTP_SCHEME = "http";
51 private static final String HTTPS_SCHEME = "https";
53 public static ActiveInventoryConfig getConfig() throws Exception {
54 if (instance == null) {
55 instance = new ActiveInventoryConfig();
61 private ActiveInventoryRestConfig aaiRestConfig;
62 private ActiveInventorySslConfig aaiSslConfig;
63 private TaskProcessorConfig taskProcessorConfig;
66 * Instantiates a new active inventory config.
68 * @throws Exception the exception
70 protected ActiveInventoryConfig() throws Exception {
72 Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
73 aaiRestConfig = new ActiveInventoryRestConfig(props);
74 aaiSslConfig = new ActiveInventorySslConfig(props, new Encryptor());
76 taskProcessorConfig = new TaskProcessorConfig();
78 .initializeFromProperties(ConfigHelper.getConfigWithPrefix("aai.taskProcessor", props));
83 protected ActiveInventoryConfig(Properties props) throws Exception {
85 aaiRestConfig = new ActiveInventoryRestConfig(props);
86 aaiSslConfig = new ActiveInventorySslConfig(props, new Encryptor());
88 taskProcessorConfig = new TaskProcessorConfig();
90 .initializeFromProperties(ConfigHelper.getConfigWithPrefix("aai.taskProcessor", props));
95 public TaskProcessorConfig getTaskProcessorConfig() {
96 return taskProcessorConfig;
99 public void setTaskProcessorConfig(TaskProcessorConfig taskProcessorConfig) {
100 this.taskProcessorConfig = taskProcessorConfig;
104 public ActiveInventoryRestConfig getAaiRestConfig() {
105 return aaiRestConfig;
108 public void setAaiRestConfig(ActiveInventoryRestConfig aaiRestConfig) {
109 this.aaiRestConfig = aaiRestConfig;
112 public ActiveInventorySslConfig getAaiSslConfig() {
116 public void setAaiSslConfig(ActiveInventorySslConfig aaiSslConfig) {
117 this.aaiSslConfig = aaiSslConfig;
120 public String repairSelfLink(String selflink) {
122 if (selflink == null) {
126 UriBuilder builder = UriBuilder.fromPath(selflink).host(aaiRestConfig.getHost())
127 .port(Integer.parseInt(aaiRestConfig.getPort()));
129 switch (aaiRestConfig.getAuthenticationMode()) {
133 builder.scheme(HTTPS_SCHEME);
138 builder.scheme(HTTP_SCHEME);
142 return builder.build().toString();
146 public static String extractResourcePath(String selflink) {
148 return new URI(selflink).getPath();
149 } catch (URISyntaxException uriSyntaxException) {
150 LOG.error(AaiUiMsgs.ERROR_EXTRACTING_RESOURCE_PATH_FROM_LINK, uriSyntaxException.getMessage());
156 * @see java.lang.Object#toString()
159 public String toString() {
160 return "ActiveInventoryConfig [aaiRestConfig=" + aaiRestConfig + ", aaiSslConfig="
161 + aaiSslConfig + "]";
164 public URI getBaseUri() {
165 return UriBuilder.fromUri("https://" + aaiRestConfig.getHost() + ":" + aaiRestConfig.getPort()
166 + aaiRestConfig.getResourceBasePath()).build();