001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kew.config; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.core.api.config.module.RunMode; 020import org.kuali.rice.core.api.config.property.ConfigContext; 021import org.kuali.rice.core.api.lifecycle.Lifecycle; 022import org.kuali.rice.core.api.resourceloader.ResourceLoader; 023import org.kuali.rice.core.framework.config.module.ModuleConfigurer; 024import org.kuali.rice.core.framework.config.module.WebModuleConfiguration; 025import org.kuali.rice.kew.api.KewApiConstants; 026import org.kuali.rice.kew.lifecycle.StandaloneLifeCycle; 027import org.kuali.rice.kew.plugin.PluginRegistry; 028import org.kuali.rice.kew.plugin.PluginRegistryFactory; 029 030import javax.sql.DataSource; 031import java.util.ArrayList; 032import java.util.Arrays; 033import java.util.Collection; 034import java.util.LinkedList; 035import java.util.List; 036 037 038/** 039 * Configures the KEW Rice module. KEW module initiation proceeds as follows: 040 * 041 * <ol> 042 * <li>Parse and load configuration for:</li> 043 * <ul> 044 * <li>Client Protocol</li> 045 * <li>Database</li> 046 * </ul> 047 * </li> 048 * <li>Configure and startup KEW for "Thin Client" mode OR</li> 049 * <li>Configure and startup KEW for "Embedded Mode"</li> 050 * </ol> 051 * 052 * @author Kuali Rice Team (rice.collab@kuali.org) 053 */ 054public class KEWConfigurer extends ModuleConfigurer { 055 056 public static final String KEW_DATASOURCE_OBJ = "org.kuali.workflow.datasource"; 057 058 private DataSource dataSource; 059 060 public KEWConfigurer() { 061 super(KewApiConstants.Namespaces.MODULE_NAME); 062 setValidRunModes(Arrays.asList(RunMode.THIN, RunMode.REMOTE, RunMode.EMBEDDED, RunMode.LOCAL)); 063 } 064 065 @Override 066 public List<String> getPrimarySpringFiles() { 067 List<String> springFileLocations = new ArrayList<String>(); 068 if (RunMode.THIN == getRunMode()) { 069 springFileLocations.add(getDefaultConfigPackagePath() + "KewThinSpringBeans.xml"); 070 } else if (RunMode.REMOTE == getRunMode()) { 071 springFileLocations.add(getDefaultConfigPackagePath() + "KewRemoteSpringBeans.xml"); 072 } else if (RunMode.EMBEDDED == getRunMode()) { 073 springFileLocations.add(getDefaultConfigPackagePath() + "KewEmbeddedSpringBeans.xml"); 074 } else if (RunMode.LOCAL == getRunMode()) { 075 springFileLocations.add(getDefaultConfigPackagePath() + "KewLocalSpringBeans.xml"); 076 } 077 return springFileLocations; 078 } 079 080 @Override 081 public List<Lifecycle> loadLifecycles() throws Exception { 082 083 List<Lifecycle> lifecycles = new LinkedList<Lifecycle>(); 084 if ( getRunMode().equals( RunMode.LOCAL ) ) { // local or embedded 085 lifecycles.add(createStandaloneLifeCycle()); 086 } 087 return lifecycles; 088 } 089 090 /** 091 * TODO Because a lot of our lifecycles live behind the embedded plugin and the KEWConfigurer does not, this is a simple 092 * measure to load these without having to deal with the removal of the embedded plugin right away. 093 * @return Life Cycle 094 * @throws Exception if life cycle not created 095 */ 096 private Lifecycle createStandaloneLifeCycle() throws Exception { 097 return new StandaloneLifeCycle(); 098 } 099 100 @Override 101 public void addAdditonalToConfig() { 102 configureDataSource(); 103 } 104 105 private void configureDataSource() { 106 if (getDataSource() != null) { 107 ConfigContext.getCurrentContextConfig().putObject(KEW_DATASOURCE_OBJ, getDataSource()); 108 } 109 } 110 111 @Override 112 public Collection<ResourceLoader> getResourceLoadersToRegister() throws Exception { 113 List<ResourceLoader> resourceLoaders = new ArrayList<ResourceLoader>(); 114 String pluginRegistryEnabled = ConfigContext.getCurrentContextConfig().getProperty("plugin.registry.enabled"); 115 if (!StringUtils.isBlank(pluginRegistryEnabled) && Boolean.valueOf(pluginRegistryEnabled).booleanValue()) { 116 // create the plugin registry 117 PluginRegistry registry = new PluginRegistryFactory().createPluginRegistry(); 118 registry.start(); 119 resourceLoaders.add(registry); 120 } 121 return resourceLoaders; 122 } 123 124 public DataSource getDataSource() { 125 return dataSource; 126 } 127 128 public void setDataSource(DataSource dataSource) { 129 this.dataSource = dataSource; 130 } 131 132 @Override 133 public boolean hasWebInterface() { 134 return true; 135 } 136 137 @Override 138 protected WebModuleConfiguration loadWebModule() { 139 WebModuleConfiguration configuration = super.loadWebModule(); 140 configuration.setWebSpringFiles(Arrays.asList(getDefaultConfigPackagePath() + "KewWebSpringBeans.xml")); 141 return configuration; 142 } 143}