1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.core.impl.config.property; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
21 | |
import org.apache.log4j.Logger; |
22 | |
import org.kuali.rice.core.api.config.property.Config; |
23 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
24 | |
import org.kuali.rice.core.util.RiceUtilities; |
25 | |
|
26 | |
import java.io.IOException; |
27 | |
import java.util.ArrayList; |
28 | |
import java.util.Comparator; |
29 | |
import java.util.HashMap; |
30 | |
import java.util.Iterator; |
31 | |
import java.util.LinkedHashMap; |
32 | |
import java.util.List; |
33 | |
import java.util.Map; |
34 | |
import java.util.Properties; |
35 | |
import java.util.Set; |
36 | |
import java.util.SortedSet; |
37 | |
import java.util.TreeSet; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
public abstract class BaseConfig implements Config { |
49 | |
|
50 | 0 | private static final Logger LOG = Logger.getLogger(BaseConfig.class); |
51 | |
|
52 | 0 | private Map<String, Object> configs = new LinkedHashMap<String, Object>(); |
53 | |
|
54 | 0 | private List<String> fileLocs = new ArrayList<String>(); |
55 | |
|
56 | 0 | private Properties propertiesUsed = new Properties(); |
57 | |
|
58 | 0 | private Map<String, Object> objects = new LinkedHashMap<String, Object>(); |
59 | |
|
60 | 0 | public BaseConfig(String fileLoc) { |
61 | 0 | this.fileLocs.add(fileLoc); |
62 | 0 | } |
63 | |
|
64 | 0 | public BaseConfig(List<String> fileLocs) { |
65 | 0 | this.fileLocs = fileLocs; |
66 | 0 | } |
67 | |
|
68 | |
protected void parseWithConfigParserImpl() throws IOException { |
69 | 0 | ConfigParserImpl cp = new ConfigParserImpl(); |
70 | 0 | Map p = new Properties(); |
71 | 0 | p.putAll(propertiesUsed); |
72 | 0 | cp.parse(p, fileLocs.toArray(new String[fileLocs.size()])); |
73 | 0 | putPropertiesInPropsUsed(p, StringUtils.join(fileLocs, ", ")); |
74 | 0 | } |
75 | |
|
76 | |
protected void parseWithHierarchicalConfigParser() throws IOException { |
77 | 0 | for (String fileLoc : this.fileLocs) { |
78 | 0 | HierarchicalConfigParser configParser = new HierarchicalConfigParser(this.propertiesUsed); |
79 | 0 | this.configs.putAll(configParser.parse(fileLoc)); |
80 | |
|
81 | |
|
82 | |
|
83 | 0 | Set<String> keys = this.configs.keySet(); |
84 | |
|
85 | 0 | for (Map.Entry<String, Object> config : this.configs.entrySet()) { |
86 | 0 | if (config.getValue() instanceof Map) { |
87 | 0 | putPropertiesInPropsUsed((Map) config.getValue(), config.getKey()); |
88 | |
} else { |
89 | 0 | String configValue = (String) config.getValue(); |
90 | 0 | if ( LOG.isDebugEnabled() ) { |
91 | 0 | LOG.debug("-->Putting root config Prop " + config.getKey() + "=[" + configValue + "]"); |
92 | |
} |
93 | 0 | this.propertiesUsed.put(config.getKey(), configValue); |
94 | 0 | } |
95 | |
} |
96 | 0 | } |
97 | 0 | } |
98 | |
|
99 | |
public void parseConfig() throws IOException { |
100 | 0 | if ( LOG.isInfoEnabled() ) { |
101 | 0 | LOG.info("Loading Rice configs: " + StringUtils.join(fileLocs, ", ")); |
102 | |
} |
103 | 0 | Map<String, Object> baseObjects = getBaseObjects(); |
104 | 0 | if (baseObjects != null) { |
105 | 0 | this.objects.putAll(baseObjects); |
106 | |
} |
107 | 0 | configureBuiltIns(this.propertiesUsed); |
108 | 0 | Properties baseProperties = getBaseProperties(); |
109 | 0 | if (baseProperties != null) { |
110 | 0 | this.propertiesUsed.putAll(baseProperties); |
111 | |
} |
112 | |
|
113 | 0 | parseWithConfigParserImpl(); |
114 | |
|
115 | |
|
116 | |
|
117 | 0 | if ( LOG.isInfoEnabled() ) { |
118 | 0 | LOG.info(""); |
119 | 0 | LOG.info("####################################"); |
120 | 0 | LOG.info("#"); |
121 | 0 | LOG.info("# Properties used after config override/replacement"); |
122 | 0 | LOG.info("# " + StringUtils.join(fileLocs, ", ")); |
123 | 0 | LOG.info("#"); |
124 | 0 | LOG.info("####################################"); |
125 | 0 | LOG.info(""); |
126 | |
} |
127 | 0 | Map<String, String> safePropsUsed = ConfigLogger.getDisplaySafeConfig(this.propertiesUsed); |
128 | 0 | Set<Map.Entry<String,String>> entrySet = safePropsUsed.entrySet(); |
129 | |
|
130 | 0 | SortedSet<Map.Entry<String,String>> sorted = new TreeSet<Map.Entry<String,String>>(new Comparator<Map.Entry<String,String>>() { |
131 | |
public int compare(Map.Entry<String,String> a, Map.Entry<String,String> b) { |
132 | 0 | return a.getKey().compareTo(b.getKey()); |
133 | |
} |
134 | |
}); |
135 | 0 | sorted.addAll(entrySet); |
136 | |
|
137 | 0 | if ( LOG.isInfoEnabled() ) { |
138 | 0 | for (Map.Entry<String, String> propUsed: sorted) { |
139 | 0 | LOG.info("Using config Prop " + propUsed.getKey() + "=[" + propUsed.getValue() + "]"); |
140 | |
} |
141 | |
} |
142 | 0 | } |
143 | |
|
144 | |
protected void putPropertiesInPropsUsed(Map properties, String fileName) { |
145 | |
|
146 | 0 | Map<String, String> safeConfig = ConfigLogger.getDisplaySafeConfig(properties); |
147 | 0 | if ( LOG.isInfoEnabled() ) { |
148 | 0 | LOG.info("Loading properties for config " + fileName); |
149 | |
} |
150 | 0 | for (Iterator iterator2 = properties.entrySet().iterator(); iterator2.hasNext();) { |
151 | 0 | Map.Entry configProp = (Map.Entry) iterator2.next(); |
152 | 0 | String key = (String) configProp.getKey(); |
153 | 0 | String value = (String) configProp.getValue(); |
154 | 0 | String safeValue = safeConfig.get(key); |
155 | 0 | if ( LOG.isDebugEnabled() ) { |
156 | 0 | LOG.debug("---->Putting config Prop " + key + "=[" + safeValue + "]"); |
157 | |
} |
158 | 0 | this.propertiesUsed.put(key, value); |
159 | 0 | } |
160 | 0 | } |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
protected void configureBuiltIns(Properties properties) { |
166 | 0 | properties.put("host.ip", RiceUtilities.getIpNumber()); |
167 | 0 | properties.put("host.name", RiceUtilities.getHostName()); |
168 | 0 | } |
169 | |
|
170 | |
public abstract Properties getBaseProperties(); |
171 | |
|
172 | |
public abstract Map<String, Object> getBaseObjects(); |
173 | |
|
174 | |
public Properties getProperties() { |
175 | 0 | return this.propertiesUsed; |
176 | |
} |
177 | |
|
178 | |
public Map<String, String> getPropertiesWithPrefix(String prefix, boolean stripPrefix) { |
179 | 0 | Map<String, String> props = new HashMap<String, String>(); |
180 | 0 | for (Map.Entry entry : getProperties().entrySet()) { |
181 | 0 | String key = (String) entry.getKey(); |
182 | 0 | if (StringUtils.isNotBlank(key) && key.trim().startsWith(prefix)) { |
183 | 0 | props.put(stripPrefix ? key.substring(prefix.length()) : key, (String) entry.getValue()); |
184 | |
} |
185 | 0 | } |
186 | 0 | return props; |
187 | |
} |
188 | |
|
189 | |
public String getProperty(String key) { |
190 | 0 | return getProperties().getProperty(key); |
191 | |
} |
192 | |
|
193 | |
public boolean getBooleanProperty(String key, boolean defaultValue) { |
194 | 0 | return RiceUtilities.getBooleanValueForString(getProperty(key), defaultValue); |
195 | |
} |
196 | |
|
197 | |
public Map<String, Object> getObjects() { |
198 | 0 | return this.objects; |
199 | |
} |
200 | |
|
201 | |
public Object getObject(String key) { |
202 | 0 | return getObjects().get(key); |
203 | |
} |
204 | |
|
205 | |
public String getBaseWebServiceURL() { |
206 | 0 | return getProperty(BASE_WEB_SERVICE_URL_WORKFLOW_CLIENT_FILE); |
207 | |
} |
208 | |
|
209 | |
public String getBaseWebServiceWsdlPath() { |
210 | 0 | return getProperty(BASE_WEB_SERVICE_WSDL_PATH); |
211 | |
} |
212 | |
|
213 | |
public String getClientWSDLFullPathAndFileName() { |
214 | 0 | return getProperty(WSDL_LOCATION_WORKFLOW_CLIENT_FILE); |
215 | |
} |
216 | |
|
217 | |
public String getWebServicesConnectRetry() { |
218 | 0 | return getProperty(WEB_SERVICE_CONNECT_RETRY); |
219 | |
} |
220 | |
|
221 | |
public String getLog4jFileLocation() { |
222 | 0 | return getProperty(LOG4J_SETTINGS_PATH); |
223 | |
} |
224 | |
|
225 | |
public String getLog4jReloadInterval() { |
226 | 0 | return getProperty(LOG4J_SETTINGS_RELOADINTERVAL_MINS); |
227 | |
} |
228 | |
|
229 | |
public String getTransactionTimeout() { |
230 | 0 | return getProperty(TRANSACTION_TIMEOUT); |
231 | |
} |
232 | |
|
233 | |
public String getEmailConfigurationPath() { |
234 | 0 | return getProperty(EMAIL_SECURITY_PATH); |
235 | |
} |
236 | |
|
237 | |
public String getEnvironment() { |
238 | 0 | return getProperty(ENVIRONMENT); |
239 | |
} |
240 | |
|
241 | |
public String getEDLConfigLocation() { |
242 | 0 | return getProperty(EDL_CONFIG_LOCATION); |
243 | |
} |
244 | |
|
245 | |
public String getServiceNamespace() { |
246 | 0 | return getProperty(SERVICE_NAMESPACE); |
247 | |
} |
248 | |
|
249 | |
public String getDefaultKewNoteClass() { |
250 | 0 | return getProperty(DEFAULT_KEW_NOTE_CLASS); |
251 | |
} |
252 | |
|
253 | |
public String getEmbeddedPluginLocation() { |
254 | 0 | return getProperty(EMBEDDED_PLUGIN_LOCATIAON); |
255 | |
} |
256 | |
|
257 | |
public Integer getRefreshRate() { |
258 | 0 | return Integer.valueOf(ConfigContext.getCurrentContextConfig().getProperty(Config.REFRESH_RATE)); |
259 | |
} |
260 | |
|
261 | |
public String getEndPointUrl() { |
262 | 0 | return ConfigContext.getCurrentContextConfig().getProperty(Config.SERVICE_SERVLET_URL); |
263 | |
} |
264 | |
|
265 | |
public String getAlternateOJBFile() { |
266 | 0 | return getProperty(Config.ALT_OJB_FILE); |
267 | |
} |
268 | |
|
269 | |
public String getAlternateSpringFile() { |
270 | 0 | return getProperty(Config.ALT_SPRING_FILE); |
271 | |
} |
272 | |
|
273 | |
public String getKeystoreAlias() { |
274 | 0 | return getProperty(Config.KEYSTORE_ALIAS); |
275 | |
} |
276 | |
|
277 | |
public String getKeystorePassword() { |
278 | 0 | return getProperty(Config.KEYSTORE_PASSWORD); |
279 | |
} |
280 | |
|
281 | |
public String getKeystoreFile() { |
282 | 0 | return getProperty(Config.KEYSTORE_FILE); |
283 | |
} |
284 | |
|
285 | |
public String getDailyEmailFirstDeliveryDate() { |
286 | 0 | return getProperty(Config.FIRST_DAILY_EMAIL_DELIVERY_DATE); |
287 | |
} |
288 | |
|
289 | |
public String getWeeklyEmailFirstDeliveryDate() { |
290 | 0 | return getProperty(org.kuali.rice.core.api.config.property.Config.FIRST_WEEKLY_EMAIL_DELIVERY_DATE); |
291 | |
} |
292 | |
|
293 | |
public String getDocumentLockTimeout() { |
294 | 0 | return getProperty(Config.DOCUMENT_LOCK_TIMEOUT); |
295 | |
} |
296 | |
|
297 | |
public Boolean getEmailReminderLifecycleEnabled() { |
298 | 0 | return Boolean.valueOf(getProperty(ENABLE_EMAIL_REMINDER_LIFECYCLE)); |
299 | |
} |
300 | |
|
301 | |
public Boolean getXmlPipelineLifeCycleEnabled() { |
302 | 0 | return Boolean.valueOf(getProperty(ENABLE_XML_PIPELINE_LIFECYCLE)); |
303 | |
} |
304 | |
|
305 | |
public Boolean getDevMode() { |
306 | 0 | return Boolean.valueOf(getProperty(DEV_MODE)); |
307 | |
} |
308 | |
|
309 | |
public Boolean getBatchMode() { |
310 | 0 | return new Boolean(getProperty(BATCH_MODE)); |
311 | |
} |
312 | |
|
313 | |
public Boolean getStoreAndForward() { |
314 | 0 | return Boolean.valueOf(getProperty(Config.STORE_AND_FORWARD)); |
315 | |
} |
316 | |
|
317 | |
public Boolean getOutBoxOn() { |
318 | 0 | if (getProperty(Config.OUT_BOX_MODE) == null) { |
319 | 0 | return true; |
320 | |
} |
321 | 0 | return Boolean.valueOf(getProperty(Config.OUT_BOX_MODE)); |
322 | |
} |
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
public String getKEWBaseURL() { |
329 | 0 | return getProperty(Config.KEW_URL); |
330 | |
} |
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
public String getKIMBaseURL() { |
337 | 0 | return getProperty(Config.KIM_URL); |
338 | |
} |
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
public String getKRBaseURL() { |
345 | 0 | return getProperty(Config.KR_URL); |
346 | |
} |
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
public String getKENBaseURL() { |
353 | 0 | return getProperty(Config.KEN_URL); |
354 | |
} |
355 | |
|
356 | |
public String toString() { |
357 | 0 | return new ToStringBuilder(this).append("fileLocs", fileLocs).toString(); |
358 | |
} |
359 | |
|
360 | |
|
361 | |
public void putProperties(Properties properties) { |
362 | 0 | if (properties != null) { |
363 | 0 | getProperties().putAll(properties); |
364 | |
} |
365 | 0 | } |
366 | |
|
367 | |
public void putProperty(String key, String value) { |
368 | 0 | this.getProperties().put(key, value); |
369 | 0 | } |
370 | |
|
371 | |
public void putObject(String key, Object value) { |
372 | 0 | this.objects.put(key, value); |
373 | 0 | } |
374 | |
|
375 | |
public void putObjects(Map<String, Object> objects) { |
376 | 0 | if(objects != null){ |
377 | 0 | this.objects.putAll(objects); |
378 | |
} |
379 | |
|
380 | 0 | } |
381 | |
|
382 | |
public void removeObject(String key){ |
383 | 0 | this.objects.remove(key); |
384 | 0 | } |
385 | |
|
386 | |
public void removeProperty(String key){ |
387 | 0 | this.getProperties().remove(key); |
388 | 0 | } |
389 | |
|
390 | |
public void putConfig(Config config) { |
391 | 0 | putProperties(config.getProperties()); |
392 | 0 | putObjects(config.getObjects()); |
393 | 0 | } |
394 | |
} |