Coverage Report - org.kuali.rice.kew.config.KEWConfigurer
 
Classes in this File Line Coverage Branch Coverage Complexity
KEWConfigurer
0%
0/46
0%
0/26
2.182
 
 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.kew.config;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.rice.core.api.config.module.RunMode;
 21  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 22  
 import org.kuali.rice.core.api.lifecycle.Lifecycle;
 23  
 import org.kuali.rice.core.api.resourceloader.ResourceLoader;
 24  
 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
 25  
 import org.kuali.rice.core.impl.config.module.ModuleConfigurer;
 26  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 27  
 import org.kuali.rice.core.api.resourceloader.ResourceLoader;
 28  
 import org.kuali.rice.core.impl.resourceloader.RiceResourceLoaderFactory;
 29  
 import org.kuali.rice.core.impl.resourceloader.RiceResourceLoaderFactory;
 30  
 import org.kuali.rice.kew.lifecycle.EmbeddedLifeCycle;
 31  
 import org.kuali.rice.kew.plugin.PluginRegistry;
 32  
 import org.kuali.rice.kew.plugin.PluginRegistryFactory;
 33  
 import org.kuali.rice.kew.resourceloader.CoreResourceLoader;
 34  
 import org.kuali.rice.kew.util.KEWConstants.ClientProtocol;
 35  
 
 36  
 import javax.sql.DataSource;
 37  
 import java.util.ArrayList;
 38  
 import java.util.Collection;
 39  
 import java.util.Collections;
 40  
 import java.util.LinkedList;
 41  
 import java.util.List;
 42  
 
 43  
 
 44  
 /**
 45  
  * Configures the KEW Rice module.  KEW module initiation proceeds as follows:
 46  
  *
 47  
  * <ol>
 48  
  *   <li>Parse and load configuration for:</li>
 49  
  *     <ul>
 50  
  *       <li>Client Protocol</li>
 51  
  *       <li>Database</li>
 52  
  *           </ul>
 53  
  *   </li>
 54  
  *   <li>Configure and startup KEW for "Thin Client" mode OR</li>
 55  
  *   <li>Configure and startup KEW for "Embedded Mode"</li>
 56  
  * </ol>
 57  
  *
 58  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 59  
  */
 60  0
 public class KEWConfigurer extends ModuleConfigurer {
 61  
 
 62  
         public static final String KEW_DATASOURCE_OBJ = "org.kuali.workflow.datasource";
 63  
 
 64  
         private DataSource dataSource;
 65  
         
 66  
         @Override
 67  
         public List<String> getPrimarySpringFiles() {
 68  
                 final List<String> springFileLocations;
 69  0
                 if (RunMode.REMOTE.equals(getRunMode()) || RunMode.THIN.equals(getRunMode()) ||
 70  
                                 ClientProtocol.WEBSERVICE.equals(getClientProtocol())) {
 71  0
                         springFileLocations = Collections.emptyList();
 72  
                 } else {
 73  0
                         springFileLocations = getEmbeddedSpringFileLocation();
 74  
                 }
 75  
 
 76  0
                 return springFileLocations;
 77  
         }
 78  
         
 79  
     private List<String> getEmbeddedSpringFileLocation(){
 80  0
             final List<String> springFileLocations = new ArrayList<String>();
 81  0
             springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWSpringBeans.xml");
 82  
 
 83  0
         if ( isExposeServicesOnBus() ) {
 84  0
                 if (isSetSOAPServicesAsDefault()) {
 85  0
                         springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWServiceBusSOAPDefaultSpringBeans.xml");
 86  
                 } else {
 87  0
                         springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWServiceBusSpringBeans.xml");
 88  
                 }
 89  
         }
 90  
         
 91  0
         if (OrmUtils.isJpaEnabled("rice.kew")) {
 92  0
                 springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWJPASpringBeans.xml");
 93  
         }
 94  
         else {
 95  0
                 springFileLocations.add("classpath:org/kuali/rice/kew/config/KEWOJBSpringBeans.xml");
 96  
         }
 97  
 
 98  0
             return springFileLocations;
 99  
     }
 100  
 
 101  
         @Override
 102  
         public List<Lifecycle> loadLifecycles() throws Exception {
 103  
                 
 104  0
                 List<Lifecycle> lifecycles = new LinkedList<Lifecycle>();
 105  0
                 if ( getRunMode().equals( RunMode.THIN ) ) {
 106  0
                         lifecycles.add(createThinClientLifecycle());
 107  0
                 } else if ( !getRunMode().equals( RunMode.REMOTE ) ) { // local or embedded
 108  0
                         lifecycles.add(createEmbeddedLifeCycle());
 109  
                 }
 110  0
                 return lifecycles;
 111  
         }
 112  
 
 113  
         /**
 114  
          * TODO Because a lot of our lifecycles live behind the embedded plugin and the KEWConfigurer does not, this is a simple
 115  
          * measure to load these without having to deal with the removal of the embedded plugin right away.
 116  
      * @return Life Cycle
 117  
      * @throws Exception if life cycle not created
 118  
      */
 119  
         private Lifecycle createEmbeddedLifeCycle() throws Exception {
 120  0
                 return new EmbeddedLifeCycle();
 121  
         }
 122  
 
 123  
         private Lifecycle createThinClientLifecycle() throws Exception {
 124  0
                 return new ThinClientLifecycle();
 125  
         }
 126  
 
 127  
         @Override
 128  
         public void addAdditonalToConfig() {
 129  0
                 configureDataSource();
 130  0
         }
 131  
 
 132  
         private void configureDataSource() {
 133  0
                 if (getDataSource() != null) {
 134  0
                         ConfigContext.getCurrentContextConfig().putObject(KEW_DATASOURCE_OBJ, getDataSource());
 135  
                 }
 136  0
         }
 137  
 
 138  
         @Override
 139  
         public Collection<ResourceLoader> getResourceLoadersToRegister() throws Exception {
 140  
                 // create the plugin registry
 141  0
                 PluginRegistry registry = null;
 142  0
                 String pluginRegistryEnabled = ConfigContext.getCurrentContextConfig().getProperty("plugin.registry.enabled");
 143  0
                 if (!StringUtils.isBlank(pluginRegistryEnabled) && Boolean.valueOf(pluginRegistryEnabled).booleanValue()) {
 144  0
                         registry = new PluginRegistryFactory().createPluginRegistry();
 145  
                 }
 146  
 
 147  0
                 final Collection<ResourceLoader> rls = new ArrayList<ResourceLoader>();
 148  0
                 for (ResourceLoader rl : RiceResourceLoaderFactory.getSpringResourceLoaders()) {
 149  0
                         CoreResourceLoader coreResourceLoader = 
 150  
                                 new CoreResourceLoader(rl, registry);
 151  0
                         coreResourceLoader.start();
 152  
 
 153  
                         //wait until core resource loader is started to attach to GRL;  this is so startup
 154  
                         //code can depend on other things hooked into GRL without incomplete KEW resources
 155  
                         //messing things up.
 156  
 
 157  0
                         GlobalResourceLoader.addResourceLoader(coreResourceLoader);
 158  
 
 159  
                         // now start the plugin registry if there is one
 160  0
                         if (registry != null) {
 161  0
                                 registry.start();
 162  
                                 // the registry resourceloader is now being handled by the CoreResourceLoader
 163  
                                 //GlobalResourceLoader.addResourceLoader(registry);
 164  
                         }
 165  0
                         rls.add(coreResourceLoader);
 166  0
                 }
 167  
 
 168  0
                 return rls;
 169  
         }
 170  
 
 171  
         private ClientProtocol getClientProtocol() {
 172  0
                 return ClientProtocol.valueOf(ConfigContext.getCurrentContextConfig().getProperty("client.protocol"));
 173  
         }
 174  
 
 175  
         public DataSource getDataSource() {
 176  0
                 return dataSource;
 177  
         }
 178  
 
 179  
         public void setDataSource(DataSource dataSource) {
 180  0
                 this.dataSource = dataSource;
 181  0
         }
 182  
 }