OAM operations 2 - oam
[appc.git] / appc-oam / appc-oam-bundle / src / main / java / org / openecomp / appc / oam / util / ConfigurationHelper.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.appc.oam.util;
26
27 import com.att.eelf.configuration.EELFLogger;
28 import org.apache.commons.lang3.ArrayUtils;
29 import org.openecomp.appc.Constants;
30 import org.openecomp.appc.configuration.Configuration;
31 import org.openecomp.appc.configuration.ConfigurationFactory;
32
33 /**
34  * Utility class provides general configuration helps
35  */
36 public class ConfigurationHelper {
37     final static String PROP_KEY_APPC_NAME = Constants.PROPERTY_APPLICATION_NAME;
38     final static String PROP_KEY_METRIC_STATE = "metric.enabled";
39
40     private final EELFLogger logger;
41     private Configuration configuration = ConfigurationFactory.getConfiguration();
42
43     public ConfigurationHelper(EELFLogger eelfLogger) {
44         logger = eelfLogger;
45     }
46
47     public String getAppcName() {
48         return configuration.getProperty(PROP_KEY_APPC_NAME);
49     }
50
51     public boolean isMetricEnabled() {
52         return configuration.getBooleanProperty(PROP_KEY_METRIC_STATE, false);
53     }
54
55     public Configuration getConfig() {
56         return configuration;
57     }
58
59     /**
60      * Read property value of a specified proeprty key
61      *
62      * @param propertyKey string of the property key
63      * @return String[] of the property values associated with the propertyKey
64      */
65     String[] readProperty(String propertyKey) {
66         String propertyValue = configuration.getProperty(propertyKey);
67         if (propertyValue == null) {
68             return ArrayUtils.EMPTY_STRING_ARRAY;
69         }
70
71         if (logger.isDebugEnabled()) {
72             logger.debug(String.format("Property[%s] has value (%s).", propertyKey, propertyValue));
73         }
74
75         if (propertyValue.contains(",")) {
76             return propertyValue.split("\\s*,\\s*");
77         }
78         return new String[]{propertyValue};
79     }
80 }