Change the header to SO
[so.git] / adapters / mso-workflow-message-adapter / src / main / java / org / openecomp / mso / adapters / workflowmessage / WMAdapterProperties.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.workflowmessage;
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 Workflow Message Adapter properties.
30  */
31 public final class WMAdapterProperties {
32         private static final MsoPropertiesFactory MSO_PROPERTIES_FACTORY = new MsoPropertiesFactory();
33         private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
34
35         /**
36          * Gets the value of a Workflow Message Adapter property.
37          * @param key the property key
38          * @param defaultValue the default value to use if the property does not
39          *        exist or if an error occurs
40          */
41         public static String getProperty(String key, String defaultValue) {
42                 MsoJavaProperties properties;
43
44                 try {
45                         properties = MSO_PROPERTIES_FACTORY.getMsoJavaProperties(WMAdapterConstants.MSO_PROPERTIES_ID);
46                 } catch (MsoPropertiesException e) {
47                         LOGGER.error (MessageEnum.NO_PROPERTIES,
48                                 "Unknown. MSO Properties ID not found in cache: " + WMAdapterConstants.MSO_PROPERTIES_ID,
49                                 "WorkflowMessageAdatper", "", MsoLogger.ErrorCode.DataError,
50                                 "Exception - MSO Properties ID not found in cache", e);
51                         return defaultValue;
52                 }
53
54                 String value = properties.getProperty(key, defaultValue);
55                 LOGGER.debug("Config read for " + WMAdapterConstants.MSO_PROPERTIES_ID
56                         + " - key:" + key + " value:" + value);
57                 return value;
58         }
59
60         /**
61          * Gets the value of an Workflow Message Adapter property.
62          * @param key the property key
63          * @param defaultValue the default value to use if the property does not
64          *        exist or if an error occurs
65          */
66         public static String getEncryptedProperty(String key, String defaultValue, String encryptionKey) {
67                 MsoJavaProperties properties;
68
69                 try {
70                         properties = MSO_PROPERTIES_FACTORY.getMsoJavaProperties(WMAdapterConstants.MSO_PROPERTIES_ID);
71                 } catch (MsoPropertiesException e) {
72                         LOGGER.error (MessageEnum.NO_PROPERTIES,
73                                 "Unknown. MSO Properties ID not found in cache: " + WMAdapterConstants.MSO_PROPERTIES_ID,
74                                 "WorkflowMessageAdatper", "", MsoLogger.ErrorCode.DataError,
75                                 "Exception - MSO Properties ID not found in cache", e);
76                         return defaultValue;
77                 }
78
79                 String value = properties.getEncryptedProperty(key, defaultValue, encryptionKey);
80                 LOGGER.debug("Config read for " + WMAdapterConstants.MSO_PROPERTIES_ID + " - key:" + key);
81                 return value;
82         }
83
84         /**
85          * Instantiation is not allowed.
86          */
87         private WMAdapterProperties() {
88         }
89 }