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;
40 * The Class ActiveInventoryConfig.
42 public class ActiveInventoryConfig {
46 public static final String CONFIG_FILE =
47 TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "aai.properties";
48 private static ActiveInventoryConfig instance;
49 private static final Logger LOG =
50 LoggerFactory.getInstance().getLogger(ActiveInventoryConfig.class);
51 private static final String HTTP_SCHEME = "http";
52 private static final String HTTPS_SCHEME = "https";
54 public static ActiveInventoryConfig getConfig() throws Exception {
55 if (instance == null) {
56 instance = new ActiveInventoryConfig();
62 private ActiveInventoryRestConfig aaiRestConfig;
63 private ActiveInventorySslConfig aaiSslConfig;
64 private TaskProcessorConfig taskProcessorConfig;
67 * Instantiates a new active inventory config.
69 * @throws Exception the exception
71 protected ActiveInventoryConfig() throws Exception {
73 Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
74 aaiRestConfig = new ActiveInventoryRestConfig(props);
75 aaiSslConfig = new ActiveInventorySslConfig(props, new Encryptor());
77 taskProcessorConfig = new TaskProcessorConfig();
79 .initializeFromProperties(ConfigHelper.getConfigWithPrefix("aai.taskProcessor", props));
84 protected ActiveInventoryConfig(Properties props) throws Exception {
86 aaiRestConfig = new ActiveInventoryRestConfig(props);
87 aaiSslConfig = new ActiveInventorySslConfig(props, new Encryptor());
89 taskProcessorConfig = new TaskProcessorConfig();
91 .initializeFromProperties(ConfigHelper.getConfigWithPrefix("aai.taskProcessor", props));
96 public TaskProcessorConfig getTaskProcessorConfig() {
97 return taskProcessorConfig;
100 public void setTaskProcessorConfig(TaskProcessorConfig taskProcessorConfig) {
101 this.taskProcessorConfig = taskProcessorConfig;
105 public ActiveInventoryRestConfig getAaiRestConfig() {
106 return aaiRestConfig;
109 public void setAaiRestConfig(ActiveInventoryRestConfig aaiRestConfig) {
110 this.aaiRestConfig = aaiRestConfig;
113 public ActiveInventorySslConfig getAaiSslConfig() {
117 public void setAaiSslConfig(ActiveInventorySslConfig aaiSslConfig) {
118 this.aaiSslConfig = aaiSslConfig;
121 public String repairSelfLink(String selflink) {
123 if (selflink == null) {
127 UriBuilder builder = UriBuilder.fromPath(selflink).host(aaiRestConfig.getHost())
128 .port(Integer.parseInt(aaiRestConfig.getPort()));
130 switch (aaiRestConfig.getAuthenticationMode()) {
134 builder.scheme(HTTPS_SCHEME);
139 builder.scheme(HTTP_SCHEME);
143 return builder.build().toString();
147 public static String extractResourcePath(String selflink) {
149 return new URI(selflink).getPath();
150 } catch (URISyntaxException uriSyntaxException) {
151 LOG.error(AaiUiMsgs.ERROR_EXTRACTING_RESOURCE_PATH_FROM_LINK,
152 uriSyntaxException.getMessage());
160 * @see java.lang.Object#toString()
163 public String toString() {
164 return "ActiveInventoryConfig [aaiRestConfig=" + aaiRestConfig + ", aaiSslConfig="
165 + aaiSslConfig + "]";
168 public URI getBaseUri() {
169 return UriBuilder.fromUri("https://" + aaiRestConfig.getHost() + ":" + aaiRestConfig.getPort()
170 + aaiRestConfig.getResourceBasePath()).build();