1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.config; |
17 | |
|
18 | |
import org.kuali.rice.core.api.config.ConfigurationException; |
19 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
20 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
21 | |
import org.kuali.rice.core.impl.config.module.ModuleConfigurer; |
22 | |
import org.kuali.rice.krad.service.DataDictionaryService; |
23 | |
import org.kuali.rice.krad.service.KRADServiceLocatorInternal; |
24 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
25 | |
import org.kuali.rice.krad.util.KRADConstants; |
26 | |
import org.kuali.rice.ksb.api.KsbApiServiceLocator; |
27 | |
|
28 | |
import javax.sql.DataSource; |
29 | |
import java.util.ArrayList; |
30 | |
import java.util.List; |
31 | |
import java.util.concurrent.Executors; |
32 | |
import java.util.concurrent.ScheduledExecutorService; |
33 | |
import java.util.concurrent.TimeUnit; |
34 | |
|
35 | 0 | public class KRADConfigurer extends ModuleConfigurer { |
36 | |
|
37 | |
private DataSource applicationDataSource; |
38 | |
private DataSource serverDataSource; |
39 | |
|
40 | |
private boolean includeKnsSpringBeans; |
41 | |
|
42 | |
private static final String KRAD_SPRING_BEANS_PATH = "classpath:org/kuali/rice/krad/config/KRADSpringBeans.xml"; |
43 | |
private static final String KNS_SPRING_BEANS_PATH = "classpath:org/kuali/rice/kns/config/KNSSpringBeans.xml"; |
44 | |
|
45 | |
@Override |
46 | |
public void addAdditonalToConfig() { |
47 | 0 | configureDataSource(); |
48 | 0 | } |
49 | |
|
50 | |
@Override |
51 | |
public List<String> getPrimarySpringFiles() { |
52 | 0 | final List<String> springFileLocations = new ArrayList<String>(); |
53 | 0 | springFileLocations.add(KRAD_SPRING_BEANS_PATH); |
54 | |
|
55 | 0 | if (isExposeServicesOnBus()) { |
56 | |
|
57 | 0 | springFileLocations.add("classpath:org/kuali/rice/core/config/COREServiceBusSpringBeans.xml"); |
58 | |
} |
59 | |
|
60 | 0 | if (isIncludeKnsSpringBeans()) { |
61 | 0 | springFileLocations.add(KNS_SPRING_BEANS_PATH); |
62 | |
} |
63 | |
|
64 | 0 | return springFileLocations; |
65 | |
} |
66 | |
|
67 | |
@Override |
68 | |
public void doAdditionalContextStartedLogic() { |
69 | 0 | loadDataDictionary(); |
70 | 0 | publishDataDictionaryComponents(); |
71 | 0 | } |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
protected void loadDataDictionary() { |
80 | 0 | if (isLoadDataDictionary()) { |
81 | 0 | LOG.info("KRAD Configurer - Loading DD"); |
82 | 0 | DataDictionaryService dds = KRADServiceLocatorWeb.getDataDictionaryService(); |
83 | 0 | if (dds == null) { |
84 | 0 | dds = (DataDictionaryService) GlobalResourceLoader |
85 | |
.getService(KRADServiceLocatorWeb.DATA_DICTIONARY_SERVICE); |
86 | |
} |
87 | 0 | dds.getDataDictionary().parseDataDictionaryConfigurationFiles(false); |
88 | |
|
89 | 0 | if (isValidateDataDictionary()) { |
90 | 0 | LOG.info("KRAD Configurer - Validating DD"); |
91 | 0 | dds.getDataDictionary().validateDD(isValidateDataDictionaryEboReferences()); |
92 | |
} |
93 | |
|
94 | |
|
95 | 0 | dds.getDataDictionary().performBeanOverrides(); |
96 | |
} |
97 | 0 | } |
98 | |
|
99 | |
protected void publishDataDictionaryComponents() { |
100 | 0 | if (isComponentPublishingEnabled()) { |
101 | 0 | long delay = getComponentPublishingDelay(); |
102 | 0 | LOG.info("Publishing of Data Dictionary components is enabled, scheduling publish after " + delay + " millisecond delay"); |
103 | 0 | ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); |
104 | |
try { |
105 | 0 | scheduler.schedule(new Runnable() { |
106 | |
@Override |
107 | |
public void run() { |
108 | 0 | long s = System.currentTimeMillis(); |
109 | 0 | LOG.info("Executing scheduled Data Dictionary component publishing..."); |
110 | |
try { |
111 | 0 | KRADServiceLocatorInternal.getDataDictionaryComponentPublisherService().publishAllComponents(); |
112 | 0 | } catch (RuntimeException e) { |
113 | 0 | LOG.error("Failed to publish data dictionary components.", e); |
114 | 0 | throw e; |
115 | |
} finally { |
116 | 0 | long e = System.currentTimeMillis(); |
117 | 0 | LOG.info("... finished scheduled execution of Data Dictionary component publishing. Took " + (e-s) + " milliseconds"); |
118 | 0 | } |
119 | 0 | } |
120 | |
}, delay, TimeUnit.MILLISECONDS); |
121 | |
} finally { |
122 | 0 | scheduler.shutdown(); |
123 | 0 | } |
124 | |
} |
125 | 0 | } |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
@Override |
133 | |
public boolean shouldRenderWebInterface() { |
134 | 0 | return true; |
135 | |
} |
136 | |
|
137 | |
public boolean isLoadDataDictionary() { |
138 | 0 | return ConfigContext.getCurrentContextConfig().getBooleanProperty("load.data.dictionary", true); |
139 | |
} |
140 | |
|
141 | |
public boolean isValidateDataDictionary() { |
142 | 0 | return ConfigContext.getCurrentContextConfig().getBooleanProperty("validate.data.dictionary", false); |
143 | |
} |
144 | |
|
145 | |
public boolean isValidateDataDictionaryEboReferences() { |
146 | 0 | return ConfigContext.getCurrentContextConfig().getBooleanProperty("validate.data.dictionary.ebo.references", |
147 | |
false); |
148 | |
} |
149 | |
|
150 | |
public boolean isComponentPublishingEnabled() { |
151 | 0 | return ConfigContext.getCurrentContextConfig().getBooleanProperty(KRADConstants.Config.COMPONENT_PUBLISHING_ENABLED, false); |
152 | |
} |
153 | |
|
154 | |
public long getComponentPublishingDelay() { |
155 | 0 | return ConfigContext.getCurrentContextConfig().getNumericProperty(KRADConstants.Config.COMPONENT_PUBLISHING_DELAY, 0); |
156 | |
} |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
protected void configureDataSource() { |
165 | 0 | if (getApplicationDataSource() != null && getServerDataSource() == null) { |
166 | 0 | throw new ConfigurationException( |
167 | |
"An application data source was defined but a server data source was not defined. Both must be specified."); |
168 | |
} |
169 | 0 | if (getApplicationDataSource() == null && getServerDataSource() != null) { |
170 | 0 | throw new ConfigurationException( |
171 | |
"A server data source was defined but an application data source was not defined. Both must be specified."); |
172 | |
} |
173 | |
|
174 | 0 | if (getApplicationDataSource() != null) { |
175 | 0 | ConfigContext.getCurrentContextConfig() |
176 | |
.putObject(KRADConstants.KRAD_APPLICATION_DATASOURCE, getApplicationDataSource()); |
177 | |
} |
178 | 0 | if (getServerDataSource() != null) { |
179 | 0 | ConfigContext.getCurrentContextConfig() |
180 | |
.putObject(KRADConstants.KRAD_SERVER_DATASOURCE, getServerDataSource()); |
181 | |
} |
182 | 0 | } |
183 | |
|
184 | |
public DataSource getApplicationDataSource() { |
185 | 0 | return this.applicationDataSource; |
186 | |
} |
187 | |
|
188 | |
public DataSource getServerDataSource() { |
189 | 0 | return this.serverDataSource; |
190 | |
} |
191 | |
|
192 | |
public void setApplicationDataSource(DataSource applicationDataSource) { |
193 | 0 | this.applicationDataSource = applicationDataSource; |
194 | 0 | } |
195 | |
|
196 | |
public void setServerDataSource(DataSource serverDataSource) { |
197 | 0 | this.serverDataSource = serverDataSource; |
198 | 0 | } |
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
public boolean isIncludeKnsSpringBeans() { |
207 | 0 | return includeKnsSpringBeans; |
208 | |
} |
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
public void setIncludeKnsSpringBeans(boolean includeKnsSpringBeans) { |
216 | 0 | this.includeKnsSpringBeans = includeKnsSpringBeans; |
217 | 0 | } |
218 | |
} |