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.net.URISyntaxException;
30 import java.util.Properties;
32 import javax.ws.rs.core.UriBuilder;
34 import org.openecomp.cl.api.Logger;
35 import org.openecomp.cl.eelf.LoggerFactory;
36 import org.openecomp.sparky.logging.AaiUiMsgs;
37 import org.openecomp.sparky.synchronizer.config.TaskProcessorConfig;
38 import org.openecomp.sparky.util.ConfigHelper;
39 import org.openecomp.sparky.util.Encryptor;
40 import org.openecomp.sparky.viewandinspect.config.TierSupportUiConstants;
42 * The Class ActiveInventoryConfig.
44 public class ActiveInventoryConfig {
48 public static final String CONFIG_FILE =
49 TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "aai.properties";
50 private static ActiveInventoryConfig instance;
51 private static final Logger LOG = LoggerFactory.getInstance().getLogger(
52 ActiveInventoryConfig.class);
53 private static final String HTTP_SCHEME = "http";
54 private static final String HTTPS_SCHEME = "https";
56 public static ActiveInventoryConfig getConfig() throws Exception {
57 if (instance == null) {
58 instance = new ActiveInventoryConfig();
64 private ActiveInventoryRestConfig aaiRestConfig;
65 private ActiveInventorySslConfig aaiSslConfig;
66 private TaskProcessorConfig taskProcessorConfig;
69 * Instantiates a new active inventory config.
71 * @throws Exception the exception
73 protected ActiveInventoryConfig() throws Exception {
75 Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
76 aaiRestConfig = new ActiveInventoryRestConfig(props);
77 aaiSslConfig = new ActiveInventorySslConfig(props, new Encryptor());
79 taskProcessorConfig = new TaskProcessorConfig();
81 .initializeFromProperties(ConfigHelper.getConfigWithPrefix("aai.taskProcessor", props));
86 protected ActiveInventoryConfig(Properties props) throws Exception {
88 aaiRestConfig = new ActiveInventoryRestConfig(props);
89 aaiSslConfig = new ActiveInventorySslConfig(props, new Encryptor());
91 taskProcessorConfig = new TaskProcessorConfig();
93 .initializeFromProperties(ConfigHelper.getConfigWithPrefix("aai.taskProcessor", props));
98 public TaskProcessorConfig getTaskProcessorConfig() {
99 return taskProcessorConfig;
102 public void setTaskProcessorConfig(TaskProcessorConfig taskProcessorConfig) {
103 this.taskProcessorConfig = taskProcessorConfig;
107 public ActiveInventoryRestConfig getAaiRestConfig() {
108 return aaiRestConfig;
111 public void setAaiRestConfig(ActiveInventoryRestConfig aaiRestConfig) {
112 this.aaiRestConfig = aaiRestConfig;
115 public ActiveInventorySslConfig getAaiSslConfig() {
119 public void setAaiSslConfig(ActiveInventorySslConfig aaiSslConfig) {
120 this.aaiSslConfig = aaiSslConfig;
123 public String repairSelfLink(String selflink) {
125 if (selflink == null) {
129 UriBuilder builder = UriBuilder.fromPath(selflink).host(aaiRestConfig.getHost())
130 .port(Integer.parseInt(aaiRestConfig.getPort()));
132 switch (aaiRestConfig.getAuthenticationMode()) {
136 builder.scheme(HTTPS_SCHEME);
141 builder.scheme(HTTP_SCHEME);
145 return builder.build().toString();
149 public static String extractResourcePath(String selflink) {
151 return new URI(selflink).getPath();
152 } catch (URISyntaxException uriSyntaxException) {
153 LOG.error(AaiUiMsgs.ERROR_EXTRACTING_RESOURCE_PATH_FROM_LINK, uriSyntaxException.getMessage());
159 * @see java.lang.Object#toString()
162 public String toString() {
163 return "ActiveInventoryConfig [aaiRestConfig=" + aaiRestConfig + ", aaiSslConfig="
164 + aaiSslConfig + "]";
167 public URI getBaseUri() {
168 return UriBuilder.fromUri("https://" + aaiRestConfig.getHost() + ":" + aaiRestConfig.getPort()
169 + aaiRestConfig.getResourceBasePath()).build();