1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.config; |
17 | |
|
18 | |
import javax.sql.DataSource; |
19 | |
|
20 | |
import org.apache.commons.lang.StringUtils; |
21 | |
import org.kuali.rice.core.config.Config; |
22 | |
import org.kuali.rice.core.config.ConfigurationException; |
23 | |
import org.kuali.rice.core.config.ModuleConfigurer; |
24 | |
import org.kuali.rice.core.config.event.AfterStartEvent; |
25 | |
import org.kuali.rice.core.config.event.RiceConfigEvent; |
26 | |
import org.kuali.rice.core.resourceloader.RiceResourceLoaderFactory; |
27 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
28 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
29 | |
import org.kuali.rice.kns.util.KNSConstants; |
30 | |
|
31 | |
public class KNSConfigurer extends ModuleConfigurer { |
32 | |
|
33 | 0 | private boolean loadDataDictionary = true; |
34 | 0 | private boolean validateDataDictionary = false; |
35 | 0 | private boolean validateDataDictionaryEboReferences = true; |
36 | |
|
37 | |
private DataSource applicationDataSource; |
38 | |
private DataSource serverDataSource; |
39 | |
private String applicationDataSourceJndiName; |
40 | |
private String serverDataSourceJndiName; |
41 | |
|
42 | |
private static final String KNS_SPRING_BEANS_PATH = "classpath:org/kuali/rice/kns/config/KNSSpringBeans.xml"; |
43 | |
private static final String KNS_KSB_SPRING_BEANS_PATH = "classpath:org/kuali/rice/kns/config/KNSServiceBusSpringBeans.xml"; |
44 | |
|
45 | |
public KNSConfigurer() { |
46 | 0 | super(); |
47 | 0 | setModuleName( "KR" ); |
48 | 0 | setHasWebInterface(true); |
49 | |
|
50 | 0 | VALID_RUN_MODES.remove( REMOTE_RUN_MODE ); |
51 | 0 | VALID_RUN_MODES.remove( THIN_RUN_MODE ); |
52 | 0 | } |
53 | |
|
54 | |
public Config loadConfig(Config parentConfig) throws Exception { |
55 | 0 | Config currentConfig = super.loadConfig(parentConfig); |
56 | 0 | configureDataSource(currentConfig); |
57 | 0 | return currentConfig; |
58 | |
} |
59 | |
|
60 | |
@Override |
61 | |
public String getSpringFileLocations(){ |
62 | 0 | if ( exposeServicesOnBus ) { |
63 | 0 | return KNS_SPRING_BEANS_PATH + "," + KNS_KSB_SPRING_BEANS_PATH; |
64 | |
} |
65 | 0 | return KNS_SPRING_BEANS_PATH; |
66 | |
} |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
@Override |
74 | |
public boolean shouldRenderWebInterface() { |
75 | 0 | return true; |
76 | |
} |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
@Override |
84 | |
public boolean hasWebInterface() { |
85 | 0 | return true; |
86 | |
} |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
@Override |
95 | |
public void onEvent(RiceConfigEvent event) throws Exception { |
96 | 0 | if (event instanceof AfterStartEvent) { |
97 | 0 | if (isLoadDataDictionary()) { |
98 | 0 | LOG.info("KNS Configurer - Loading DD"); |
99 | 0 | DataDictionaryService dds = KNSServiceLocator.getDataDictionaryService(); |
100 | 0 | if ( dds == null ) { |
101 | 0 | dds = (DataDictionaryService)RiceResourceLoaderFactory.getSpringResourceLoader().getContext().getBean( KNSServiceLocator.DATA_DICTIONARY_SERVICE ); |
102 | |
} |
103 | 0 | dds.getDataDictionary().parseDataDictionaryConfigurationFiles(false); |
104 | |
|
105 | 0 | if ( isValidateDataDictionary() ) { |
106 | 0 | LOG.info("KNS Configurer - Validating DD"); |
107 | 0 | dds.getDataDictionary().validateDD( validateDataDictionaryEboReferences ); |
108 | |
} |
109 | |
|
110 | 0 | dds.getDataDictionary().performBeanOverrides(); |
111 | |
} |
112 | 0 | KNSServiceLocator.getDateTimeService().initializeDateTimeService(); |
113 | |
} |
114 | 0 | } |
115 | |
|
116 | |
|
117 | |
protected void configureDataSource(Config config) { |
118 | 0 | if (getApplicationDataSource() != null && getServerDataSource() == null) { |
119 | 0 | throw new ConfigurationException("An application data source was defined but a server data source was not defined. Both must be specified."); |
120 | |
} |
121 | 0 | if (getApplicationDataSource() == null && getServerDataSource() != null) { |
122 | 0 | throw new ConfigurationException("A server data source was defined but an application data source was not defined. Both must be specified."); |
123 | |
} |
124 | |
|
125 | 0 | if (getApplicationDataSource() != null) { |
126 | 0 | config.putObject(KNSConstants.KNS_APPLICATION_DATASOURCE, getApplicationDataSource()); |
127 | 0 | } else if (!StringUtils.isBlank(getApplicationDataSourceJndiName())) { |
128 | 0 | config.putProperty(KNSConstants.KNS_APPLICATION_DATASOURCE_JNDI, getApplicationDataSourceJndiName()); |
129 | |
} |
130 | 0 | if (getServerDataSource() != null) { |
131 | 0 | config.putObject(KNSConstants.KNS_SERVER_DATASOURCE, getServerDataSource()); |
132 | 0 | } else if (!StringUtils.isBlank(getServerDataSourceJndiName())) { |
133 | 0 | config.putProperty(KNSConstants.KNS_SERVER_DATASOURCE_JNDI, getServerDataSourceJndiName()); |
134 | |
} |
135 | 0 | } |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
public boolean isLoadDataDictionary() { |
141 | 0 | return this.loadDataDictionary; |
142 | |
} |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
public void setLoadDataDictionary(boolean loadDataDictionary) { |
148 | 0 | this.loadDataDictionary = loadDataDictionary; |
149 | 0 | } |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
public boolean isValidateDataDictionary() { |
155 | 0 | return this.validateDataDictionary; |
156 | |
} |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
public void setValidateDataDictionary(boolean validateDataDictionary) { |
162 | 0 | this.validateDataDictionary = validateDataDictionary; |
163 | 0 | } |
164 | |
|
165 | |
public DataSource getApplicationDataSource() { |
166 | 0 | return this.applicationDataSource; |
167 | |
} |
168 | |
|
169 | |
public DataSource getServerDataSource() { |
170 | 0 | return this.serverDataSource; |
171 | |
} |
172 | |
|
173 | |
public void setApplicationDataSource(DataSource applicationDataSource) { |
174 | 0 | this.applicationDataSource = applicationDataSource; |
175 | 0 | } |
176 | |
|
177 | |
public void setServerDataSource(DataSource serverDataSource) { |
178 | 0 | this.serverDataSource = serverDataSource; |
179 | 0 | } |
180 | |
|
181 | |
public String getApplicationDataSourceJndiName() { |
182 | 0 | return this.applicationDataSourceJndiName; |
183 | |
} |
184 | |
|
185 | |
public String getServerDataSourceJndiName() { |
186 | 0 | return this.serverDataSourceJndiName; |
187 | |
} |
188 | |
|
189 | |
public void setApplicationDataSourceJndiName( |
190 | |
String applicationDataSourceJndiName) { |
191 | 0 | this.applicationDataSourceJndiName = applicationDataSourceJndiName; |
192 | 0 | } |
193 | |
|
194 | |
public void setServerDataSourceJndiName(String serverDataSourceJndiName) { |
195 | 0 | this.serverDataSourceJndiName = serverDataSourceJndiName; |
196 | 0 | } |
197 | |
|
198 | |
public void setValidateDataDictionaryEboReferences( |
199 | |
boolean validateDataDictionaryEboReferences) { |
200 | 0 | this.validateDataDictionaryEboReferences = validateDataDictionaryEboReferences; |
201 | 0 | } |
202 | |
|
203 | |
public boolean isValidateDataDictionaryEboReferences() { |
204 | 0 | return validateDataDictionaryEboReferences; |
205 | |
} |
206 | |
} |