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