View Javadoc

1   /**
2    * Copyright 2005-2012 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  package org.kuali.rice.kew.config;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.config.module.RunMode;
20  import org.kuali.rice.core.api.config.property.ConfigContext;
21  import org.kuali.rice.core.api.lifecycle.Lifecycle;
22  import org.kuali.rice.core.api.resourceloader.ResourceLoader;
23  import org.kuali.rice.core.framework.config.module.ModuleConfigurer;
24  import org.kuali.rice.core.framework.config.module.WebModuleConfiguration;
25  import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
26  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
27  import org.kuali.rice.core.framework.resourceloader.RiceResourceLoaderFactory;
28  import org.kuali.rice.kew.api.KewApiConstants;
29  import org.kuali.rice.kew.lifecycle.EmbeddedLifeCycle;
30  import org.kuali.rice.kew.plugin.PluginRegistry;
31  import org.kuali.rice.kew.plugin.PluginRegistryFactory;
32  import org.kuali.rice.kew.resourceloader.CoreResourceLoader;
33  import org.kuali.rice.kew.api.KewApiConstants.ClientProtocol;
34  
35  import javax.sql.DataSource;
36  import java.util.ArrayList;
37  import java.util.Arrays;
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  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      public KEWConfigurer() {
67          super(KewApiConstants.Namespaces.MODULE_NAME);
68          setValidRunModes(Arrays.asList(RunMode.THIN, RunMode.REMOTE, RunMode.EMBEDDED, RunMode.LOCAL));
69      }
70  
71  	@Override
72  	public List<String> getPrimarySpringFiles() {
73          List<String> springFileLocations = new ArrayList<String>();
74          if (RunMode.THIN == getRunMode()) {
75              springFileLocations.add(getDefaultConfigPackagePath() + "KewThinSpringBeans.xml");
76          } else if (RunMode.REMOTE == getRunMode()) {
77              springFileLocations.add(getDefaultConfigPackagePath() + "KewRemoteSpringBeans.xml");
78          } else if (RunMode.EMBEDDED == getRunMode()) {
79              springFileLocations.add(getDefaultConfigPackagePath() + "KewEmbeddedSpringBeans.xml");
80          } else if (RunMode.LOCAL == getRunMode()) {
81              springFileLocations.add(getDefaultConfigPackagePath() + "KewLocalSpringBeans.xml");
82          }
83  		return springFileLocations;
84  	}
85  	
86  	@Override
87  	public List<Lifecycle> loadLifecycles() throws Exception {
88  		
89  		List<Lifecycle> lifecycles = new LinkedList<Lifecycle>();
90          if ( !getRunMode().equals( RunMode.REMOTE ) ) { // local or embedded
91  			lifecycles.add(createEmbeddedLifeCycle());
92  		}
93  		return lifecycles;
94  	}
95  
96  	/**
97  	 * TODO Because a lot of our lifecycles live behind the embedded plugin and the KEWConfigurer does not, this is a simple
98  	 * measure to load these without having to deal with the removal of the embedded plugin right away.
99       * @return Life Cycle
100      * @throws Exception if life cycle not created
101      */
102 	private Lifecycle createEmbeddedLifeCycle() throws Exception {
103 		return new EmbeddedLifeCycle();
104 	}
105 
106 	@Override
107 	public void addAdditonalToConfig() {
108 		configureDataSource();
109 	}
110 
111 	private void configureDataSource() {
112 		if (getDataSource() != null) {
113 			ConfigContext.getCurrentContextConfig().putObject(KEW_DATASOURCE_OBJ, getDataSource());
114 		}
115 	}
116 
117 	@Override
118 	public Collection<ResourceLoader> getResourceLoadersToRegister() throws Exception {
119         List<ResourceLoader> resourceLoaders = new ArrayList<ResourceLoader>();
120 		String pluginRegistryEnabled = ConfigContext.getCurrentContextConfig().getProperty("plugin.registry.enabled");
121 		if (!StringUtils.isBlank(pluginRegistryEnabled) && Boolean.valueOf(pluginRegistryEnabled).booleanValue()) {
122     		// create the plugin registry
123 			PluginRegistry registry = new PluginRegistryFactory().createPluginRegistry();
124             registry.start();
125             resourceLoaders.add(registry);
126 		}
127         return resourceLoaders;
128 	}
129 
130 	public DataSource getDataSource() {
131 		return dataSource;
132 	}
133 
134 	public void setDataSource(DataSource dataSource) {
135 		this.dataSource = dataSource;
136 	}
137 
138     @Override
139     public boolean hasWebInterface() {
140         return true;
141     }
142 
143     @Override
144     protected WebModuleConfiguration loadWebModule() {
145         WebModuleConfiguration configuration = super.loadWebModule();
146         configuration.setWebSpringFiles(Arrays.asList(getDefaultConfigPackagePath() + "KewWebSpringBeans.xml"));
147         return configuration;
148     }
149 }