Updating Dockerfile
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / dal / aai / config / ActiveInventoryConfig.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.onap.aai.sparky.dal.aai.config;
24
25 import java.net.URI;
26 import java.net.URISyntaxException;
27 import java.util.Properties;
28
29 import org.onap.aai.cl.api.Logger;
30 import org.onap.aai.cl.eelf.LoggerFactory;
31 import org.onap.aai.sparky.logging.AaiUiMsgs;
32 import org.onap.aai.sparky.util.ConfigHelper;
33 import org.onap.aai.sparky.util.Encryptor;
34 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
35
36 /**
37  * The Class ActiveInventoryConfig.
38  */
39 public class ActiveInventoryConfig {
40
41   public static final String CONFIG_FILE =
42       TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION + "aai.properties";
43   private static ActiveInventoryConfig instance;
44
45   private static final Logger LOG =
46       LoggerFactory.getInstance().getLogger(ActiveInventoryConfig.class);
47
48
49   public static ActiveInventoryConfig getConfig() throws Exception {
50     if (instance == null) {
51       instance = new ActiveInventoryConfig();
52     }
53
54     return instance;
55   }
56
57   private ActiveInventoryRestConfig aaiRestConfig;
58   private ActiveInventorySslConfig aaiSslConfig;
59
60   /**
61    * Instantiates a new active inventory config.
62    *
63    * @throws Exception the exception
64    */
65   protected ActiveInventoryConfig() throws Exception {
66
67     Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE);
68     initialize(props);
69   }
70
71   public ActiveInventoryConfig(Properties props) throws Exception {
72     initialize(props);
73   }
74
75   private void initialize(Properties props) {
76     aaiRestConfig = new ActiveInventoryRestConfig(props);
77     aaiSslConfig = new ActiveInventorySslConfig(props, new Encryptor());
78   }
79
80   public ActiveInventoryRestConfig getAaiRestConfig() {
81     return aaiRestConfig;
82   }
83
84   public void setAaiRestConfig(ActiveInventoryRestConfig aaiRestConfig) {
85     this.aaiRestConfig = aaiRestConfig;
86   }
87
88   public ActiveInventorySslConfig getAaiSslConfig() {
89     return aaiSslConfig;
90   }
91
92   public void setAaiSslConfig(ActiveInventorySslConfig aaiSslConfig) {
93     this.aaiSslConfig = aaiSslConfig;
94   }
95
96
97
98   public static String extractResourcePath(String selflink) {
99     try {
100       return new URI(selflink).getRawPath();
101     } catch (URISyntaxException uriSyntaxException) {
102       LOG.error(AaiUiMsgs.ERROR_EXTRACTING_RESOURCE_PATH_FROM_LINK,
103           uriSyntaxException.getMessage());
104       return selflink;
105     }
106   }
107
108   /*
109    * (non-Javadoc)
110    * 
111    * @see java.lang.Object#toString()
112    */
113   @Override
114   public String toString() {
115     return "ActiveInventoryConfig [aaiRestConfig=" + aaiRestConfig + ", aaiSslConfig="
116         + aaiSslConfig + "]";
117   }
118
119
120
121 }