| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.datadictionary; |
| 17 | |
|
| 18 | |
import java.io.File; |
| 19 | |
import java.util.ArrayList; |
| 20 | |
import java.util.List; |
| 21 | |
|
| 22 | |
import no.geosoft.cc.io.FileListener; |
| 23 | |
import no.geosoft.cc.io.FileMonitor; |
| 24 | |
|
| 25 | |
import org.apache.commons.lang.StringUtils; |
| 26 | |
import org.apache.commons.logging.Log; |
| 27 | |
import org.apache.commons.logging.LogFactory; |
| 28 | |
import org.kuali.rice.core.api.config.property.ConfigurationService; |
| 29 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
| 30 | |
import org.springframework.core.io.FileSystemResource; |
| 31 | |
import org.springframework.core.io.Resource; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public class ReloadingDataDictionary extends DataDictionary implements FileListener { |
| 51 | 0 | private static final Log LOG = LogFactory.getLog(DataDictionary.class); |
| 52 | |
|
| 53 | |
private static final String CLASS_DIR_CONFIG_PARM = "reload.data.dictionary.classes.dir"; |
| 54 | |
private static final String SOURCE_DIR_CONFIG_PARM = "reload.data.dictionary.source.dir"; |
| 55 | |
private static final String INTERVAL_CONFIG_PARM = "reload.data.dictionary.interval"; |
| 56 | |
|
| 57 | |
public ReloadingDataDictionary() { |
| 58 | 0 | super(); |
| 59 | 0 | } |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
@Override |
| 68 | |
public void parseDataDictionaryConfigurationFiles(boolean allowConcurrentValidation) { |
| 69 | 0 | ConfigurationService configurationService = KNSServiceLocator.getKualiConfigurationService(); |
| 70 | |
|
| 71 | |
|
| 72 | 0 | String classesDir = configurationService.getPropertyString(CLASS_DIR_CONFIG_PARM); |
| 73 | |
|
| 74 | |
|
| 75 | 0 | String sourceDir = configurationService.getPropertyString(SOURCE_DIR_CONFIG_PARM); |
| 76 | |
|
| 77 | |
|
| 78 | 0 | int reloadInterval = Integer.parseInt(configurationService.getPropertyString(INTERVAL_CONFIG_PARM)); |
| 79 | |
|
| 80 | 0 | FileMonitor dictionaryFileMonitor = new FileMonitor(reloadInterval); |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | 0 | List<String> configLocations = new ArrayList<String>(configFileLocations); |
| 85 | |
|
| 86 | 0 | super.parseDataDictionaryConfigurationFiles(allowConcurrentValidation); |
| 87 | 0 | for (String configLocation : configLocations) { |
| 88 | 0 | Resource classFileResource = getFileResource(configLocation); |
| 89 | |
try { |
| 90 | 0 | String filePathClassesDir = classFileResource.getFile().getAbsolutePath(); |
| 91 | 0 | String sourceFilePath = StringUtils.replace(filePathClassesDir, classesDir, sourceDir); |
| 92 | |
|
| 93 | 0 | File dictionaryFile = new File(filePathClassesDir); |
| 94 | 0 | if (dictionaryFile.exists()) { |
| 95 | 0 | LOG.debug("Monitoring dictionary file: " + dictionaryFile.getName()); |
| 96 | 0 | dictionaryFileMonitor.addFile(dictionaryFile); |
| 97 | |
} |
| 98 | |
} |
| 99 | 0 | catch (Exception e) { |
| 100 | 0 | LOG.info("Exception in picking up dictionary file for monitoring: " + e.getMessage(), e); |
| 101 | 0 | } |
| 102 | 0 | } |
| 103 | |
|
| 104 | |
|
| 105 | 0 | dictionaryFileMonitor.addListener(this); |
| 106 | 0 | } |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
@Override |
| 116 | |
public void fileChanged(File file) { |
| 117 | 0 | LOG.info("reloading dictionary configuration for " + file.getName()); |
| 118 | |
try { |
| 119 | 0 | Resource resource = new FileSystemResource(file); |
| 120 | 0 | xmlReader.loadBeanDefinitions(resource); |
| 121 | |
|
| 122 | |
|
| 123 | 0 | ddIndex.run(); |
| 124 | |
} |
| 125 | 0 | catch (Exception e) { |
| 126 | 0 | LOG.info("Exception in dictionary hot deploy: " + e.getMessage(), e); |
| 127 | 0 | } |
| 128 | 0 | } |
| 129 | |
|
| 130 | |
} |