Coverage Report - org.kuali.rice.krad.config.KRADConfigurer
 
Classes in this File Line Coverage Branch Coverage Complexity
KRADConfigurer
0%
0/45
0%
0/22
1.867
 
 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  0
 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  0
         configureDataSource();
 46  0
     }
 47  
 
 48  
     @Override
 49  
     public List<String> getPrimarySpringFiles() {
 50  0
         final List<String> springFileLocations = new ArrayList<String>();
 51  0
         springFileLocations.add(KRAD_SPRING_BEANS_PATH);
 52  
 
 53  0
         if (isExposeServicesOnBus()) {
 54  0
             springFileLocations.add(KRAD_KSB_SPRING_BEANS_PATH);
 55  
         }
 56  
 
 57  0
         if (isIncludeKnsSpringBeans()) {
 58  0
             springFileLocations.add(KNS_SPRING_BEANS_PATH);
 59  
         }
 60  
 
 61  0
         return springFileLocations;
 62  
     }
 63  
 
 64  
     @Override
 65  
     public void doAdditionalContextStartedLogic() {
 66  0
         loadDataDictionary();
 67  0
     }
 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  0
         if (isLoadDataDictionary()) {
 77  0
             LOG.info("KRAD Configurer - Loading DD");
 78  0
             DataDictionaryService dds = KRADServiceLocatorWeb.getDataDictionaryService();
 79  0
             if (dds == null) {
 80  0
                 dds = (DataDictionaryService) GlobalResourceLoader
 81  
                         .getService(KRADServiceLocatorWeb.DATA_DICTIONARY_SERVICE);
 82  
             }
 83  0
             dds.getDataDictionary().parseDataDictionaryConfigurationFiles(false);
 84  
 
 85  0
             if (isValidateDataDictionary()) {
 86  0
                 LOG.info("KRAD Configurer - Validating DD");
 87  0
                 dds.getDataDictionary().validateDD(isValidateDataDictionaryEboReferences());
 88  
             }
 89  
             // KULRICE-4513 After the Data Dictionary is loaded and validated, perform Data Dictionary bean overrides.
 90  0
             dds.getDataDictionary().performBeanOverrides();
 91  
         }
 92  0
     }
 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  0
         return true;
 102  
     }
 103  
 
 104  
     public boolean isLoadDataDictionary() {
 105  0
         return Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty("load.data.dictionary"))
 106  
                 .booleanValue();
 107  
     }
 108  
 
 109  
     public boolean isValidateDataDictionary() {
 110  0
         return Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty("validate.data.dictionary"))
 111  
                 .booleanValue();
 112  
     }
 113  
 
 114  
     public boolean isValidateDataDictionaryEboReferences() {
 115  0
         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  0
         if (getApplicationDataSource() != null && getServerDataSource() == null) {
 128  0
             throw new ConfigurationException(
 129  
                     "An application data source was defined but a server data source was not defined.  Both must be specified.");
 130  
         }
 131  0
         if (getApplicationDataSource() == null && getServerDataSource() != null) {
 132  0
             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  0
         if (getApplicationDataSource() != null) {
 137  0
             ConfigContext.getCurrentContextConfig()
 138  
                     .putObject(KRADConstants.KRAD_APPLICATION_DATASOURCE, getApplicationDataSource());
 139  
         }
 140  0
         if (getServerDataSource() != null) {
 141  0
             ConfigContext.getCurrentContextConfig()
 142  
                     .putObject(KRADConstants.KRAD_SERVER_DATASOURCE, getServerDataSource());
 143  
         }
 144  0
     }
 145  
 
 146  
     public DataSource getApplicationDataSource() {
 147  0
         return this.applicationDataSource;
 148  
     }
 149  
 
 150  
     public DataSource getServerDataSource() {
 151  0
         return this.serverDataSource;
 152  
     }
 153  
 
 154  
     public void setApplicationDataSource(DataSource applicationDataSource) {
 155  0
         this.applicationDataSource = applicationDataSource;
 156  0
     }
 157  
 
 158  
     public void setServerDataSource(DataSource serverDataSource) {
 159  0
         this.serverDataSource = serverDataSource;
 160  0
     }
 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  0
         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  0
         this.includeKnsSpringBeans = includeKnsSpringBeans;
 179  0
     }
 180  
 }