View Javadoc
1   /**
2    * Copyright 2005-2014 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.kew.api.KewApiConstants;
26  import org.kuali.rice.kew.lifecycle.StandaloneLifeCycle;
27  import org.kuali.rice.kew.plugin.PluginRegistry;
28  import org.kuali.rice.kew.plugin.PluginRegistryFactory;
29  
30  import javax.sql.DataSource;
31  import java.util.ArrayList;
32  import java.util.Arrays;
33  import java.util.Collection;
34  import java.util.LinkedList;
35  import java.util.List;
36  
37  /**
38   * Configures the KEW Rice module.  KEW module initiation proceeds as follows:
39   *
40   * <ol>
41   * <li>Parse and load configuration for:</li>
42   * <ul>
43   * <li>Client Protocol</li>
44   * <li>Database</li>
45   * </ul>
46   * </li>
47   * <li>Configure and startup KEW for "Thin Client" mode OR</li>
48   * <li>Configure and startup KEW for "Embedded Mode"</li>
49   * </ol>
50   *
51   * @author Kuali Rice Team (rice.collab@kuali.org)
52   */
53  public class KEWConfigurer extends ModuleConfigurer {
54  
55      public static final String KEW_DATASOURCE_OBJ = "org.kuali.workflow.datasource";
56  
57      private DataSource dataSource;
58  
59      public KEWConfigurer() {
60          super(KewApiConstants.Namespaces.MODULE_NAME);
61          setValidRunModes(Arrays.asList(RunMode.THIN, RunMode.REMOTE, RunMode.EMBEDDED, RunMode.LOCAL));
62      }
63  
64      @Override
65      public List<String> getPrimarySpringFiles() {
66          LOG.info("KEWConfigurer:getPrimarySpringFiles: getRunMode => " + getRunMode());
67          List<String> springFileLocations = new ArrayList<String>();
68          if (RunMode.THIN == getRunMode()) {
69              springFileLocations.add(getDefaultConfigPackagePath() + "KewThinSpringBeans.xml");
70          } else if (RunMode.REMOTE == getRunMode()) {
71              springFileLocations.add(getDefaultConfigPackagePath() + "KewRemoteSpringBeans.xml");
72          } else if (RunMode.EMBEDDED == getRunMode()) {
73              springFileLocations.add(getDefaultConfigPackagePath() + "KewEmbeddedSpringBeans.xml");
74          } else if (RunMode.LOCAL == getRunMode()) {
75              springFileLocations.add(getDefaultConfigPackagePath() + "KewLocalSpringBeans.xml");
76          }
77          return springFileLocations;
78      }
79  
80      @Override
81      public List<Lifecycle> loadLifecycles() throws Exception {
82          List<Lifecycle> lifecycles = new LinkedList<Lifecycle>();
83          if (getRunMode().equals(RunMode.LOCAL)) { // local or embedded
84              lifecycles.add(createStandaloneLifeCycle());
85          }
86          return lifecycles;
87      }
88  
89      /**
90       * TODO Because a lot of our lifecycles live behind the embedded plugin and the KEWConfigurer does not, this is a
91       * simple
92       * measure to load these without having to deal with the removal of the embedded plugin right away.
93       *
94       * @return Life Cycle
95       * @throws Exception if life cycle not created
96       */
97      private Lifecycle createStandaloneLifeCycle() throws Exception {
98          return new StandaloneLifeCycle();
99      }
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 }