Change the header to SO
[so.git] / adapters / mso-sdnc-adapter / src / main / java / org / openecomp / mso / adapters / sdnc / sdncrest / SDNCAdapterProperties.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.mso.adapters.sdnc.sdncrest;
21
22 import org.openecomp.mso.logger.MessageEnum;
23 import org.openecomp.mso.logger.MsoLogger;
24 import org.openecomp.mso.properties.MsoJavaProperties;
25 import org.openecomp.mso.properties.MsoPropertiesException;
26 import org.openecomp.mso.properties.MsoPropertiesFactory;
27
28 /**
29  * Static methods to access SDNC adapter properties.
30  */
31 public final class SDNCAdapterProperties {
32         private static final String MSO_PROPERTIES_ID = "MSO_PROP_SDNC_ADAPTER";
33         private static final MsoPropertiesFactory MSO_PROPERTIES_FACTORY = new MsoPropertiesFactory();
34         private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
35
36         /**
37          * Gets the value of an SDNC adapter property.
38          * @param key the property key
39          * @param defaultValue the default value to use if the property does not
40          *        exist or if an error occurs
41          */
42         public static String getProperty(String key, String defaultValue) {
43                 MsoJavaProperties properties;
44
45                 try {
46                         properties = MSO_PROPERTIES_FACTORY.getMsoJavaProperties(MSO_PROPERTIES_ID);
47                 } catch (MsoPropertiesException e) {
48                         LOGGER.error (MessageEnum.NO_PROPERTIES, "Unknown. Mso Properties ID not found in cache: " + MSO_PROPERTIES_ID,
49                                 "SDNC", "", MsoLogger.ErrorCode.DataError, "Exception - Mso Properties ID not found in cache", e);
50                         return defaultValue;
51                 }
52
53                 String value = properties.getProperty(key, defaultValue);
54                 LOGGER.debug("Config read for " + MSO_PROPERTIES_ID + " - key:" + key + " value:" + value);
55                 return value;
56         }
57
58         /**
59          * Gets the value of an SDNC adapter property.
60          * @param key the property key
61          * @param defaultValue the default value to use if the property does not
62          *        exist or if an error occurs
63          */
64         public static String getEncryptedProperty(String key, String defaultValue, String encryptionKey) {
65                 MsoJavaProperties properties;
66
67                 try {
68                         properties = MSO_PROPERTIES_FACTORY.getMsoJavaProperties(MSO_PROPERTIES_ID);
69                 } catch (MsoPropertiesException e) {
70                         LOGGER.error (MessageEnum.NO_PROPERTIES, "Unknown. Mso Properties ID not found in cache: " + MSO_PROPERTIES_ID,
71                                 "SDNC", "", MsoLogger.ErrorCode.DataError, "Exception - Mso Properties ID not found in cache", e);
72                         return defaultValue;
73                 }
74
75                 String value = properties.getEncryptedProperty(key, defaultValue, encryptionKey);
76                 LOGGER.debug("Config read for " + MSO_PROPERTIES_ID + " - key:" + key);
77                 return value;
78         }
79
80         /**
81          * Instantiation is not allowed.
82          */
83         private SDNCAdapterProperties() {
84         }
85 }