View Javadoc

1   /*
2    * Copyright 2006-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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       * Used to "poke" the Data Dictionary again after the Spring Context is initialized.  This is to
71       * allow for modules loaded with KualiModule after the KNS has already been initialized to work.
72       *
73       * Also initializes the DateTimeService
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              // KULRICE-4513 After the Data Dictionary is loaded and validated, perform Data Dictionary bean overrides.
90              dds.getDataDictionary().performBeanOverrides();
91          }
92      }
93  
94      /**
95       * Returns true - KNS UI should always be included.
96       *
97       * @see org.kuali.rice.core.api.config.ModuleConfigurer#shouldRenderWebInterface()
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      * Used to "poke" the Data Dictionary again after the Spring Context is initialized.  This is to
122      * allow for modules loaded with KualiModule after the KNS has already been initialized to work.
123      *
124      * Also initializes the DateTimeService
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      * Indicates whether the legacy KNS module should be included which will include
164      * the KNS spring beans file
165      *
166      * @return boolean true if kns should be supported, false if not
167      */
168     public boolean isIncludeKnsSpringBeans() {
169         return includeKnsSpringBeans;
170     }
171 
172     /**
173      * Setter for the include kns support indicator
174      *
175      * @param includeKnsSpringBeans
176      */
177     public void setIncludeKnsSpringBeans(boolean includeKnsSpringBeans) {
178         this.includeKnsSpringBeans = includeKnsSpringBeans;
179     }
180 }