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