Coverage Report - org.kuali.rice.kns.config.KNSConfigurer
 
Classes in this File Line Coverage Branch Coverage Complexity
KNSConfigurer
0%
0/64
0%
0/26
1.762
 
 1  
 /*
 2  
  * Copyright 2007-2008 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  
 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  
             // KNS never runs in a remote or thin mode
 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  
      * Returns true - KNS UI should always be included.
 70  
      *
 71  
      * @see org.kuali.rice.core.config.ModuleConfigurer#shouldRenderWebInterface()
 72  
      */
 73  
     @Override
 74  
     public boolean shouldRenderWebInterface() {
 75  0
         return true;
 76  
     }
 77  
 
 78  
     /**
 79  
      * Returns true - KNS UI should always be included.
 80  
      *
 81  
      * @see org.kuali.rice.core.config.ModuleConfigurer#hasWebInterface()
 82  
      */
 83  
     @Override
 84  
     public boolean hasWebInterface() {
 85  0
         return true;
 86  
     }
 87  
 
 88  
         /**
 89  
      * Used to "poke" the Data Dictionary again after the Spring Context is initialized.  This is to
 90  
      * allow for modules loaded with KualiModule after the KNS has already been initialized to work.
 91  
      * 
 92  
      * Also initializes the DateTimeService
 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  
                             // KULRICE-4513 After the Data Dictionary is loaded and validated, perform Data Dictionary bean overrides.
 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  
          * @return the loadDataDictionary
 139  
          */
 140  
         public boolean isLoadDataDictionary() {
 141  0
                 return this.loadDataDictionary;
 142  
         }
 143  
 
 144  
         /**
 145  
          * @param loadDataDictionary the loadDataDictionary to set
 146  
          */
 147  
         public void setLoadDataDictionary(boolean loadDataDictionary) {
 148  0
                 this.loadDataDictionary = loadDataDictionary;
 149  0
         }
 150  
 
 151  
         /**
 152  
          * @return the validateDataDictionary
 153  
          */
 154  
         public boolean isValidateDataDictionary() {
 155  0
                 return this.validateDataDictionary;
 156  
         }
 157  
 
 158  
         /**
 159  
          * @param validateDataDictionary the validateDataDictionary to set
 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  
 }