View Javadoc
1   /*
2    * Copyright 2008 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.ole.sys.context;
17  
18  import java.util.*;
19  
20  import org.kuali.ole.LoadDefaultWorkflowsBean;
21  import org.kuali.rice.core.api.config.module.RunMode;
22  import org.kuali.rice.core.api.config.property.ConfigContext;
23  import org.kuali.rice.core.api.lifecycle.Lifecycle;
24  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
25  import org.kuali.rice.core.framework.config.module.ModuleConfigurer;
26  import org.kuali.rice.core.framework.config.module.WebModuleConfiguration;
27  
28  public class OLEConfigurer extends ModuleConfigurer {
29      private OlePollingStandaloneLifeCycle olePollingStandaloneLifeCycle;
30      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OLEConfigurer.class);
31  
32      protected boolean testMode = false;
33  
34      public OLEConfigurer() {
35          super("OLE");
36          LOG.info( "OLEConfigurer instantiated" );
37          setValidRunModes(Arrays.asList(RunMode.LOCAL));
38      }
39  
40      @Override
41      public List<Lifecycle> loadLifecycles() throws Exception {
42          List<Lifecycle> lifecycles = new LinkedList<Lifecycle>();
43          lifecycles.add(getOlePollingStandaloneLifeCycle());
44          return lifecycles;
45      }
46  
47      @Override
48      protected void doAdditionalModuleStartLogic() throws Exception {
49          LOG.info("*********************************************************");
50          LOG.info("OLE Starting Module");
51          LOG.info("*********************************************************");
52          super.doAdditionalModuleStartLogic();
53  
54          try {
55              LoadDefaultWorkflowsBean loadDefaultWorkflowsBean =
56                      GlobalResourceLoader.getService("loadDefaultWorkflowsBean");
57              loadDefaultWorkflowsBean.unpackWorkflows(false);
58          } catch (Exception e) {
59              LOG.error("Error loading workflow.", e);
60          }
61      }
62  
63      @Override
64      protected void doAdditionalModuleStopLogic() throws Exception {
65          LOG.info("*********************************************************");
66          LOG.info("OLE Stopping Module");
67          LOG.info("*********************************************************");
68          super.doAdditionalModuleStopLogic();
69      }
70  
71      @Override
72      public List<String> getPrimarySpringFiles() {
73          String files = ConfigContext.getCurrentContextConfig().getProperty("spring.source.files");
74          if (testMode) {
75              files = files + "," + ConfigContext.getCurrentContextConfig().getProperty("spring.test.files");
76          }
77          if (LOG.isInfoEnabled()) {
78              LOG.info("OLE Spring Files Requested.  Returning: " + files);
79          }
80          return files == null ? Collections.<String>emptyList() : parseFileList(files);
81      }
82  
83      protected List<String> parseFileList(String files) {
84          List<String> parsedFiles = new ArrayList<String>();
85          for (String file : Arrays.asList(files.split(","))) {
86              String trimmedFile = file.trim();
87              if (!trimmedFile.isEmpty()) {
88                  parsedFiles.add(trimmedFile);
89              }
90          }
91  
92          return parsedFiles;
93      }
94  
95      @Override
96      protected WebModuleConfiguration loadWebModule() {
97          return new OleWebModuleConfiguration();
98      }
99  
100     @Override
101     public boolean hasWebInterface() {
102         return true;
103     }
104 
105     public boolean isTestMode() {
106         return testMode;
107     }
108 
109     public void setTestMode(boolean testMode) {
110         this.testMode = testMode;
111     }
112 
113     public void setOlePollingStandaloneLifeCycle(OlePollingStandaloneLifeCycle olePollingStandaloneLifeCycle) {
114         this.olePollingStandaloneLifeCycle = olePollingStandaloneLifeCycle;
115     }
116 
117     public OlePollingStandaloneLifeCycle getOlePollingStandaloneLifeCycle() {
118         return olePollingStandaloneLifeCycle;
119     }
120 }