9ab1c387b5a73ea1ea484ce734091a745e255b1a
[appc.git] / appc-common / src / main / java / org / openecomp / appc / configuration / Configuration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.configuration;
24
25 import java.util.Properties;
26
27 import org.slf4j.Logger;
28
29
30
31 /**
32  * This interface defines the common configuration support that is available to the application.
33  * <p>
34  * Where properties are common to all CDP components (server, coordinator, and EPM), the property symbolic values are
35  * defined as part of this interface. Where they are unique to each component, they must be defined within that
36  * component.
37  * </p>
38  */
39 public interface Configuration {
40
41     String PROPERTY_BOOTSTRAP_FILE_NAME = "org_openecomp_appc_bootstrap_file"; //
42     String DEFAULT_BOOTSTRAP_FILE_NAME = "appc.properties"; 
43     String PROPERTY_BOOTSTRAP_FILE_PATH = "org_openecomp_appc_bootstrap_path"; //
44     String DEFAULT_BOOTSTRAP_FILE_PATH = "/opt/openecomp/appc/data/properties,${user.home},etc,../etc";
45     String PROPERTY_RESOURCE_BUNDLES = "org.openecomp.appc.resources"; 
46     String DEFAULT_RESOURCE_BUNDLES = "org/openecomp/appc/i18n/MessageResources";
47
48    /**
49      * This method is called to obtain a property expressed as a boolean value (true or false). The standard rules for
50      * {@link Boolean#valueOf(String)} are used.
51      * 
52      * @param key
53      *            The property key
54      * @return The value of the property expressed as a boolean, or false if it does not exist.
55      */
56     boolean getBooleanProperty(String key);
57
58     /**
59      * This method is called to obtain a property expressed as a boolean value (true or false). The standard rules for
60      * {@link Boolean#valueOf(String)} are used.
61      * 
62      * @param key
63      *            The property key
64      * @param defaultValue
65      *            The default value to be returned if the property does not exist
66      * @return The value of the property expressed as a boolean, or false if it does not exist.
67      */
68     boolean getBooleanProperty(String key, boolean defaultValue);
69
70     /**
71      * Returns the indicated property value expressed as a floating point double-precision value (double). The standard
72      * rules for {@link Double#valueOf(String)} are used.
73      * 
74      * @param key
75      *            The property to retrieve
76      * @return The value of the property, or 0.0 if not found or invalid
77      */
78     double getDoubleProperty(String key);
79
80     /**
81      * Returns the indicated property value expressed as a floating point double-precision value (double). The standard
82      * rules for {@link Double#valueOf(String)} are used.
83      * 
84      * @param key
85      *            The property to retrieve
86      * @param defaultValue
87      *            The default value to be returned if the property does not exist
88      * @return The value of the property, or 0.0 if not found or invalid
89      */
90     double getDoubleProperty(String key, double defaultValue);
91
92     /**
93      * Returns the property indicated expressed as an integer. The standard rules for
94      * {@link Integer#parseInt(String, int)} using a radix of 10 are used.
95      * 
96      * @param key
97      *            The property name to retrieve.
98      * @return The value of the property, or 0 if it does not exist or is invalid.
99      */
100     int getIntegerProperty(String key);
101
102     /**
103      * Returns the property indicated expressed as an integer. The standard rules for
104      * {@link Integer#parseInt(String, int)} using a radix of 10 are used.
105      * 
106      * @param key
107      *            The property name to retrieve.
108      * @param defaultValue
109      *            The default value to be returned if the property does not exist
110      * @return The value of the property, or 0 if it does not exist or is invalid.
111      */
112     int getIntegerProperty(String key, int defaultValue);
113
114     /**
115      * Returns the specified property as a long integer value, if it exists, or zero if it does not.
116      * 
117      * @param key
118      *            The key of the property desired.
119      * @return The value of the property expressed as an integer long value, or zero if the property does not exist or
120      *         is not a valid integer long.
121      */
122     long getLongProperty(String key);
123
124     /**
125      * Returns the specified property as a long integer value, if it exists, or the default value if it does not exist
126      * or is invalid.
127      * 
128      * @param key
129      *            The key of the property desired.
130      * @param defaultValue
131      *            the value to be returned if the property is not valid or does not exist.
132      * @return The value of the property expressed as an integer long value, or the default value if the property does
133      *         not exist or is not a valid integer long.
134      */
135     long getLongProperty(String key, long defaultValue);
136
137     /**
138      * This method can be called to retrieve a properties object that is immutable. Any attempt to modify the properties
139      * object returned will result in an exception. This allows a caller to view the current configuration as a set of
140      * properties.
141      * 
142      * @return An unmodifiable properties object.
143      */
144     Properties getProperties();
145
146     /**
147      * This method is called to obtain a property as a string value
148      * 
149      * @param key
150      *            The key of the property
151      * @return The string value, or null if it does not exist.
152      */
153     String getProperty(String key);
154
155     /**
156      * This method is called to obtain a property as a string value
157      * 
158      * @param key
159      *            The key of the property
160      * @param defaultValue
161      *            The default value to be returned if the property does not exist
162      * @return The string value, or null if it does not exist.
163      */
164     String getProperty(String key, String defaultValue);
165
166     /**
167      * Returns true if the named property is defined, false otherwise.
168      * 
169      * @param key
170      *            The key of the property we are interested in
171      * @return True if the property exists.
172      */
173     boolean isPropertyDefined(String key);
174
175     /**
176      * Returns an indication of the validity of the boolean property. A boolean property is considered to be valid only
177      * if it has the value "true" or "false" (ignoring case).
178      * 
179      * @param key
180      *            The property to be checked
181      * @return True if the value is a boolean constant, or false if it does not exist or is not a correct string
182      */
183     boolean isValidBoolean(String key);
184
185     /**
186      * Returns an indication if the indicated property represents a valid double-precision floating point number.
187      * 
188      * @param key
189      *            The property to be examined
190      * @return True if the property is a valid representation of a double, or false if it does not exist or contains
191      *         illegal characters.
192      */
193     boolean isValidDouble(String key);
194
195     /**
196      * Returns an indication if the property is a valid integer value or not.
197      * 
198      * @param key
199      *            The key of the property to check
200      * @return True if the value is a valid integer string, or false if it does not exist or contains illegal
201      *         characters.
202      */
203     boolean isValidInteger(String key);
204
205     /**
206      * Determines is the specified property exists and is a valid representation of an integer long value.
207      * 
208      * @param key
209      *            The property to be checked
210      * @return True if the property is a valid representation of an integer long value, and false if it either does not
211      *         exist or is not valid.
212      */
213     boolean isValidLong(String key);
214
215     /**
216      * This method allows the caller to set all properties from a provided properties object into the configuration
217      * property set.
218      * <p>
219      * The primary difference between this method and the factory method
220      * {@link ConfigurationFactory#getConfiguration(Properties)} is that this method does not clear and reload the
221      * configuration. Rather, this method merges the provided properties object contents into the existing properties,
222      * replacing any same-named keys with the values from this object.
223      * </p>
224      * 
225      * @param properties
226      *            The properties object to copy all properties from
227      */
228     void setProperties(Properties properties);
229
230     /**
231      * This method allows a caller to insert a new property definition into the configuration object. This allows the
232      * application to adjust or add to the current configuration. If the property already exists, it is replaced with
233      * the new value.
234      * 
235      * @param key
236      *            The key of the property to be defined
237      * @param value
238      *            The value of the property to be defined
239      */
240     void setProperty(String key, String value);
241 }