2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.openecomp.sparky.dal.aai.config;
29 import java.util.Properties;
31 import javax.ws.rs.core.UriBuilder;
33 import org.openecomp.sparky.synchronizer.config.TaskProcessorConfig;
34 import org.openecomp.sparky.util.ConfigHelper;
35 import org.openecomp.sparky.util.Encryptor;
36 import org.openecomp.sparky.viewandinspect.config.TierSupportUiConstants;
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;
49 private static final String HTTP_SCHEME = "http";
50 private static final String HTTPS_SCHEME = "https";
52 public static ActiveInventoryConfig getConfig() throws Exception {
53 if (instance == null) {
54 instance = new ActiveInventoryConfig();
60 private ActiveInventoryRestConfig aaiRestConfig;
61 private ActiveInventorySslConfig aaiSslConfig;
62 private TaskProcessorConfig taskProcessorConfig;
65 * Instantiates a new active inventory config.
67 * @throws Exception the exception
69 protected ActiveInventoryConfig() throws Exception {
71 Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
72 aaiRestConfig = new ActiveInventoryRestConfig(props);
73 aaiSslConfig = new ActiveInventorySslConfig(props, new Encryptor());
75 taskProcessorConfig = new TaskProcessorConfig();
77 .initializeFromProperties(ConfigHelper.getConfigWithPrefix("aai.taskProcessor", props));
82 protected ActiveInventoryConfig(Properties props) throws Exception {
84 aaiRestConfig = new ActiveInventoryRestConfig(props);
85 aaiSslConfig = new ActiveInventorySslConfig(props, new Encryptor());
87 taskProcessorConfig = new TaskProcessorConfig();
89 .initializeFromProperties(ConfigHelper.getConfigWithPrefix("aai.taskProcessor", props));
94 public TaskProcessorConfig getTaskProcessorConfig() {
95 return taskProcessorConfig;
98 public void setTaskProcessorConfig(TaskProcessorConfig taskProcessorConfig) {
99 this.taskProcessorConfig = taskProcessorConfig;
103 public ActiveInventoryRestConfig getAaiRestConfig() {
104 return aaiRestConfig;
107 public void setAaiRestConfig(ActiveInventoryRestConfig aaiRestConfig) {
108 this.aaiRestConfig = aaiRestConfig;
111 public ActiveInventorySslConfig getAaiSslConfig() {
115 public void setAaiSslConfig(ActiveInventorySslConfig aaiSslConfig) {
116 this.aaiSslConfig = aaiSslConfig;
119 public String repairSelfLink(String selflink) {
121 if (selflink == null) {
125 UriBuilder builder = UriBuilder.fromPath(selflink).host(aaiRestConfig.getHost())
126 .port(Integer.parseInt(aaiRestConfig.getPort()));
128 switch (aaiRestConfig.getAuthenticationMode()) {
132 builder.scheme(HTTPS_SCHEME);
137 builder.scheme(HTTP_SCHEME);
141 return builder.build().toString();
146 * @see java.lang.Object#toString()
149 public String toString() {
150 return "ActiveInventoryConfig [aaiRestConfig=" + aaiRestConfig + ", aaiSslConfig="
151 + aaiSslConfig + "]";
154 public URI getBaseUri() {
155 return UriBuilder.fromUri("https://" + aaiRestConfig.getHost() + ":" + aaiRestConfig.getPort()
156 + aaiRestConfig.getResourceBasePath()).build();