001/** 002 * Copyright 2005-2017 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 * Configures the KEW Rice module. KEW module initiation proceeds as follows: 039 * 040 * <ol> 041 * <li>Parse and load configuration for:</li> 042 * <ul> 043 * <li>Client Protocol</li> 044 * <li>Database</li> 045 * </ul> 046 * </li> 047 * <li>Configure and startup KEW for "Thin Client" mode OR</li> 048 * <li>Configure and startup KEW for "Embedded Mode"</li> 049 * </ol> 050 * 051 * @author Kuali Rice Team (rice.collab@kuali.org) 052 */ 053public class KEWConfigurer extends ModuleConfigurer { 054 055 public static final String KEW_DATASOURCE_OBJ = "org.kuali.workflow.datasource"; 056 057 private DataSource dataSource; 058 059 public KEWConfigurer() { 060 super(KewApiConstants.Namespaces.MODULE_NAME); 061 setValidRunModes(Arrays.asList(RunMode.THIN, RunMode.REMOTE, RunMode.EMBEDDED, RunMode.LOCAL)); 062 } 063 064 @Override 065 public List<String> getPrimarySpringFiles() { 066 LOG.info("KEWConfigurer:getPrimarySpringFiles: getRunMode => " + getRunMode()); 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 List<Lifecycle> lifecycles = new LinkedList<Lifecycle>(); 083 if (getRunMode().equals(RunMode.LOCAL)) { // local or embedded 084 lifecycles.add(createStandaloneLifeCycle()); 085 } 086 return lifecycles; 087 } 088 089 /** 090 * TODO Because a lot of our lifecycles live behind the embedded plugin and the KEWConfigurer does not, this is a 091 * simple 092 * measure to load these without having to deal with the removal of the embedded plugin right away. 093 * 094 * @return Life Cycle 095 * @throws Exception if life cycle not created 096 */ 097 private Lifecycle createStandaloneLifeCycle() throws Exception { 098 return new StandaloneLifeCycle(); 099 } 100 101 @Override 102 public void addAdditonalToConfig() { 103 configureDataSource(); 104 } 105 106 private void configureDataSource() { 107 if (getDataSource() != null) { 108 ConfigContext.getCurrentContextConfig().putObject(KEW_DATASOURCE_OBJ, getDataSource()); 109 } 110 } 111 112 @Override 113 public Collection<ResourceLoader> getResourceLoadersToRegister() throws Exception { 114 List<ResourceLoader> resourceLoaders = new ArrayList<ResourceLoader>(); 115 String pluginRegistryEnabled = ConfigContext.getCurrentContextConfig().getProperty("plugin.registry.enabled"); 116 if (!StringUtils.isBlank(pluginRegistryEnabled) && Boolean.valueOf(pluginRegistryEnabled).booleanValue()) { 117 // create the plugin registry 118 PluginRegistry registry = new PluginRegistryFactory().createPluginRegistry(); 119 registry.start(); 120 resourceLoaders.add(registry); 121 } 122 return resourceLoaders; 123 } 124 125 public DataSource getDataSource() { 126 return dataSource; 127 } 128 129 public void setDataSource(DataSource dataSource) { 130 this.dataSource = dataSource; 131 } 132 133 @Override 134 public boolean hasWebInterface() { 135 return true; 136 } 137 138 @Override 139 protected WebModuleConfiguration loadWebModule() { 140 WebModuleConfiguration configuration = super.loadWebModule(); 141 configuration.setWebSpringFiles(Arrays.asList(getDefaultConfigPackagePath() + "KewWebSpringBeans.xml")); 142 return configuration; 143 } 144}