Coverage Report - org.kuali.rice.kns.config.KNSConfigurer
 
Classes in this File Line Coverage Branch Coverage Complexity
KNSConfigurer
0%
0/39
0%
0/20
1.923
 
 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.kns.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.core.api.resourceloader.GlobalResourceLoader;
 24  
 import org.kuali.rice.kns.service.DataDictionaryService;
 25  
 import org.kuali.rice.kns.service.KNSServiceLocatorWeb;
 26  
 import org.kuali.rice.kns.util.KNSConstants;
 27  
 
 28  
 import javax.sql.DataSource;
 29  
 import java.util.ArrayList;
 30  
 import java.util.List;
 31  
 
 32  0
 public class KNSConfigurer extends ModuleConfigurer {
 33  
 
 34  
         private DataSource applicationDataSource;
 35  
         private DataSource serverDataSource;
 36  
 
 37  
         private static final String KNS_SPRING_BEANS_PATH = "classpath:org/kuali/rice/kns/config/KNSSpringBeans.xml";
 38  
         private static final String KNS_KSB_SPRING_BEANS_PATH = "classpath:org/kuali/rice/kns/config/KNSServiceBusSpringBeans.xml";
 39  
 
 40  
         @Override
 41  
         public void addAdditonalToConfig() {
 42  0
                 configureDataSource();
 43  0
         }
 44  
 
 45  
         @Override
 46  
         public List<String> getPrimarySpringFiles() {
 47  0
                 final List<String> springFileLocations = new ArrayList<String>();
 48  
                 //springFileLocations.add(KNS_SPRING_BEANS_PATH);
 49  
 
 50  0
                 if ( isExposeServicesOnBus() ) {
 51  0
                         springFileLocations.add(KNS_KSB_SPRING_BEANS_PATH);
 52  
                 }
 53  0
                 return springFileLocations;
 54  
         }
 55  
         
 56  
         @Override
 57  
         public void doAdditionalContextStartedLogic() {
 58  0
                 loadDataDictionary();
 59  0
         }
 60  
         
 61  
         /**
 62  
      * Used to "poke" the Data Dictionary again after the Spring Context is initialized.  This is to
 63  
      * allow for modules loaded with KualiModule after the KNS has already been initialized to work.
 64  
      * 
 65  
      * Also initializes the DateTimeService
 66  
      */
 67  
     private void loadDataDictionary() {
 68  0
                 if (isLoadDataDictionary()) {
 69  0
             LOG.info("KNS Configurer - Loading DD");
 70  0
                         DataDictionaryService dds = KNSServiceLocatorWeb.getDataDictionaryService();
 71  0
                         if ( dds == null ) {
 72  0
                                 dds = (DataDictionaryService) GlobalResourceLoader.getService(KNSServiceLocatorWeb.DATA_DICTIONARY_SERVICE);
 73  
                         }
 74  0
                         dds.getDataDictionary().parseDataDictionaryConfigurationFiles(false);
 75  
 
 76  0
                         if ( isValidateDataDictionary() ) {
 77  0
                 LOG.info("KNS Configurer - Validating DD");
 78  0
                                 dds.getDataDictionary().validateDD( isValidateDataDictionaryEboReferences() );
 79  
                         }
 80  
                         // KULRICE-4513 After the Data Dictionary is loaded and validated, perform Data Dictionary bean overrides.
 81  0
                         dds.getDataDictionary().performBeanOverrides();
 82  
                 }                
 83  0
         }
 84  
 
 85  
    /**
 86  
      * Returns true - KNS UI should always be included.
 87  
      *
 88  
      * @see org.kuali.rice.core.api.config.ModuleConfigurer#shouldRenderWebInterface()
 89  
      */
 90  
     @Override
 91  
     public boolean shouldRenderWebInterface() {
 92  0
         return true;
 93  
     }
 94  
     
 95  
         public boolean isLoadDataDictionary() {
 96  0
                 return Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty("load.data.dictionary")).booleanValue();
 97  
         }
 98  
 
 99  
         public boolean isValidateDataDictionary() {
 100  0
                 return Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty("validate.data.dictionary")).booleanValue();
 101  
         }
 102  
 
 103  
         public boolean isValidateDataDictionaryEboReferences() {
 104  0
                 return Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty("validate.data.dictionary.ebo.references")).booleanValue();
 105  
         }
 106  
 
 107  
         /**
 108  
      * Used to "poke" the Data Dictionary again after the Spring Context is initialized.  This is to
 109  
      * allow for modules loaded with KualiModule after the KNS has already been initialized to work.
 110  
      * 
 111  
      * Also initializes the DateTimeService
 112  
      */
 113  
     protected void configureDataSource() {
 114  0
         if (getApplicationDataSource() != null && getServerDataSource() == null) {
 115  0
             throw new ConfigurationException("An application data source was defined but a server data source was not defined.  Both must be specified.");
 116  
         }
 117  0
         if (getApplicationDataSource() == null && getServerDataSource() != null) {
 118  0
             throw new ConfigurationException("A server data source was defined but an application data source was not defined.  Both must be specified.");
 119  
         }
 120  
 
 121  0
         if (getApplicationDataSource() != null) {
 122  0
                 ConfigContext.getCurrentContextConfig().putObject(KNSConstants.KNS_APPLICATION_DATASOURCE, getApplicationDataSource());
 123  
         }
 124  0
         if (getServerDataSource() != null) {
 125  0
                 ConfigContext.getCurrentContextConfig().putObject(KNSConstants.KNS_SERVER_DATASOURCE, getServerDataSource());
 126  
         }
 127  0
     }
 128  
         
 129  
     public DataSource getApplicationDataSource() {
 130  0
         return this.applicationDataSource;
 131  
     }
 132  
 
 133  
     public DataSource getServerDataSource() {
 134  0
         return this.serverDataSource;
 135  
     }
 136  
 
 137  
     public void setApplicationDataSource(DataSource applicationDataSource) {
 138  0
         this.applicationDataSource = applicationDataSource;
 139  0
     }
 140  
 
 141  
     public void setServerDataSource(DataSource serverDataSource) {
 142  0
         this.serverDataSource = serverDataSource;
 143  0
     }
 144  
 }