View Javadoc

1   /*
2    * Copyright 2006-2011 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  
17  package org.kuali.rice.test.lifecycles;
18  
19  import org.apache.log4j.Logger;
20  import org.kuali.rice.core.api.config.property.ConfigContext;
21  import org.kuali.rice.core.api.lifecycle.BaseLifecycle;
22  import org.kuali.rice.kew.batch.KEWXmlDataLoader;
23  
24  /**
25   * A lifecycle for loading KEW XML datasets.
26   * This lifecycle will not be run (even if it is listed in the lifecycles list)
27   * if the 'use.kewXmlmlDataLoaderLifecycle' configuration property is defined, and is
28   * not 'true'.  If the property is omitted the lifecycle runs as normal.
29   * 
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class KEWXmlDataLoaderLifecycle extends BaseLifecycle {
33      private static final Logger LOG = Logger.getLogger(KEWXmlDataLoaderLifecycle.class);
34  
35      private String filename;
36  
37      /**
38       * Specifies the XML resource to load.  The resource path should be in Spring resource notation.
39       * @param resource the XML resource to load
40       */
41      public KEWXmlDataLoaderLifecycle(String resource) {
42          this.filename = resource;
43      }
44  
45      public void start() throws Exception {
46          String useKewXmlDataLoaderLifecycle = ConfigContext.getCurrentContextConfig().getProperty("use.kewXmlmlDataLoaderLifecycle");
47  
48          if (useKewXmlDataLoaderLifecycle != null && !Boolean.valueOf(useKewXmlDataLoaderLifecycle)) {
49              LOG.debug("Skipping KEWXmlDataLoaderLifecycle due to property: use.kewXmlmlDataLoaderLifecycle=" + useKewXmlDataLoaderLifecycle);
50              return;
51          }
52  
53          LOG.info("################################");
54          LOG.info("#");
55          LOG.info("#  Begin Loading file '" + filename + "'");
56          LOG.info("#");
57          LOG.info("################################");
58          loadData();
59          super.start();
60      }
61  
62      /**
63       * Does the work of loading the data
64       * @throws Exception
65       */
66      protected void loadData() throws Exception {
67          KEWXmlDataLoader.loadXmlResource(filename);
68      }
69  }