blob: 2dbd103275b25a96491c68a28f39a1543bde35a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
/*******************************************************************************
* =============LICENSE_START=========================================================
*
* =================================================================================
* Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*******************************************************************************/
package org.onap.oom.dashboard.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
/**
* Publishes a list of constants and methods to access the properties that are
* read by Spring from the specified configuration file(s).
*
* Should be used like this (and never in a constructor):
*
* <pre>
* @Autowired
* DashboardProperties properties;
* </pre>
*/
@Configuration
@PropertySource(value = { "${container.classpath:}/WEB-INF/conf/dashboard.properties" })
public class DashboardProperties {
/**
* Key for property that indicates if test data should be used
*/
public static final String CONTROLLER_MOCK_DATA = "controller.mock.data";
/**
* Key for property with list of controllers
*/
public static final String CONTROLLER_KEY_LIST = "controller.key.list";
/**
* Subkey for property with Controller name (description)
*/
public static final String CONTROLLER_SUBKEY_NAME = "name";
/**
* Subkey for property with Controller URL
*/
public static final String CONTROLLER_SUBKEY_URL = "url";
/**
* Subkey for property with Controller user name for authentication
*/
public static final String CONTROLLER_SUBKEY_USERNAME = "username";
/**
* Subkey for property with Controller password
*/
public static final String CONTROLLER_SUBKEY_PASSWORD = "password";
/**
* Subkey for property with Controller password encryption status
*/
public static final String CONTROLLER_SUBKEY_ENCRYPTED = "is_encrypted";
private Environment environment;
/**
* No-arg constructor
*/
public DashboardProperties() {
}
protected Environment getEnvironment() {
return environment;
}
/**
* @param environment
* Environment
*/
@Autowired
public void setEnvironment(final Environment environment) {
this.environment = environment;
}
/**
* @param key
* Property key
* @return True or false
*/
public boolean containsProperty(final String key) {
return environment.containsProperty(key);
}
/**
* @param key
* Property key
* @return String value; throws unchecked exception if key is not found
*/
public String getProperty(final String key) {
return environment.getRequiredProperty(key);
}
/**
* @param key
* Property key
* @return True or False; null if key is not found
*/
public Boolean getBooleanProperty(final String key) {
final String value = getProperty(key);
return Boolean.parseBoolean(value);
}
/**
* Gets the values for a comma-separated list property value as a String
* array.
*
* @param key
* Property key
* @return Array of values with leading and trailing whitespace removed;
* null if key is not found.
*/
public String[] getCsvListProperty(final String key) {
String listVal = getProperty(key);
if (listVal == null)
return null;
String[] vals = listVal.split("\\s*,\\s*");
return vals;
}
/**
* Convenience method to get a property from the fake hierarchical key-value
* set.
*
* @param controllerKey
* First part of key
* @param propKey
* Second part of key
* @return Property value for key "controllerKey.propKey"
*/
public String getControllerProperty(final String controllerKey, final String propKey) {
final String key = controllerKey + '.' + propKey;
return getProperty(key);
}
}
|