1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.krad.config;
18
19 import org.kuali.rice.core.api.config.ConfigurationException;
20 import org.kuali.rice.core.api.config.property.ConfigContext;
21 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
22 import org.kuali.rice.core.impl.config.module.ModuleConfigurer;
23 import org.kuali.rice.krad.service.DataDictionaryService;
24 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
25 import org.kuali.rice.krad.util.KRADConstants;
26
27 import javax.sql.DataSource;
28 import java.util.ArrayList;
29 import java.util.List;
30
31 public class KRADConfigurer extends ModuleConfigurer {
32
33 private DataSource applicationDataSource;
34 private DataSource serverDataSource;
35
36 private boolean includeKnsSpringBeans;
37
38 private static final String KRAD_SPRING_BEANS_PATH = "classpath:org/kuali/rice/krad/config/KRADSpringBeans.xml";
39 private static final String KRAD_KSB_SPRING_BEANS_PATH =
40 "classpath:org/kuali/rice/krad/config/KRADServiceBusSpringBeans.xml";
41 private static final String KNS_SPRING_BEANS_PATH = "classpath:org/kuali/rice/kns/config/KNSSpringBeans.xml";
42
43 @Override
44 public void addAdditonalToConfig() {
45 configureDataSource();
46 }
47
48 @Override
49 public List<String> getPrimarySpringFiles() {
50 final List<String> springFileLocations = new ArrayList<String>();
51 springFileLocations.add(KRAD_SPRING_BEANS_PATH);
52
53 if (isExposeServicesOnBus()) {
54 springFileLocations.add(KRAD_KSB_SPRING_BEANS_PATH);
55 }
56
57 if (isIncludeKnsSpringBeans()) {
58 springFileLocations.add(KNS_SPRING_BEANS_PATH);
59 }
60
61 return springFileLocations;
62 }
63
64 @Override
65 public void doAdditionalContextStartedLogic() {
66 loadDataDictionary();
67 }
68
69
70
71
72
73
74
75 private void loadDataDictionary() {
76 if (isLoadDataDictionary()) {
77 LOG.info("KRAD Configurer - Loading DD");
78 DataDictionaryService dds = KRADServiceLocatorWeb.getDataDictionaryService();
79 if (dds == null) {
80 dds = (DataDictionaryService) GlobalResourceLoader
81 .getService(KRADServiceLocatorWeb.DATA_DICTIONARY_SERVICE);
82 }
83 dds.getDataDictionary().parseDataDictionaryConfigurationFiles(false);
84
85 if (isValidateDataDictionary()) {
86 LOG.info("KRAD Configurer - Validating DD");
87 dds.getDataDictionary().validateDD(isValidateDataDictionaryEboReferences());
88 }
89
90 dds.getDataDictionary().performBeanOverrides();
91 }
92 }
93
94
95
96
97
98
99 @Override
100 public boolean shouldRenderWebInterface() {
101 return true;
102 }
103
104 public boolean isLoadDataDictionary() {
105 return Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty("load.data.dictionary"))
106 .booleanValue();
107 }
108
109 public boolean isValidateDataDictionary() {
110 return Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty("validate.data.dictionary"))
111 .booleanValue();
112 }
113
114 public boolean isValidateDataDictionaryEboReferences() {
115 return Boolean
116 .valueOf(ConfigContext.getCurrentContextConfig().getProperty("validate.data.dictionary.ebo.references"))
117 .booleanValue();
118 }
119
120
121
122
123
124
125
126 protected void configureDataSource() {
127 if (getApplicationDataSource() != null && getServerDataSource() == null) {
128 throw new ConfigurationException(
129 "An application data source was defined but a server data source was not defined. Both must be specified.");
130 }
131 if (getApplicationDataSource() == null && getServerDataSource() != null) {
132 throw new ConfigurationException(
133 "A server data source was defined but an application data source was not defined. Both must be specified.");
134 }
135
136 if (getApplicationDataSource() != null) {
137 ConfigContext.getCurrentContextConfig()
138 .putObject(KRADConstants.KRAD_APPLICATION_DATASOURCE, getApplicationDataSource());
139 }
140 if (getServerDataSource() != null) {
141 ConfigContext.getCurrentContextConfig()
142 .putObject(KRADConstants.KRAD_SERVER_DATASOURCE, getServerDataSource());
143 }
144 }
145
146 public DataSource getApplicationDataSource() {
147 return this.applicationDataSource;
148 }
149
150 public DataSource getServerDataSource() {
151 return this.serverDataSource;
152 }
153
154 public void setApplicationDataSource(DataSource applicationDataSource) {
155 this.applicationDataSource = applicationDataSource;
156 }
157
158 public void setServerDataSource(DataSource serverDataSource) {
159 this.serverDataSource = serverDataSource;
160 }
161
162
163
164
165
166
167
168 public boolean isIncludeKnsSpringBeans() {
169 return includeKnsSpringBeans;
170 }
171
172
173
174
175
176
177 public void setIncludeKnsSpringBeans(boolean includeKnsSpringBeans) {
178 this.includeKnsSpringBeans = includeKnsSpringBeans;
179 }
180 }