001/** 002 * Copyright 2005-2014 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.test.lifecycles; 017 018import org.apache.log4j.Logger; 019import org.kuali.rice.core.api.config.property.ConfigContext; 020import org.kuali.rice.core.api.lifecycle.BaseLifecycle; 021import org.kuali.rice.kew.batch.KEWXmlDataLoader; 022 023/** 024 * A lifecycle for loading KEW XML datasets. 025 * This lifecycle will not be run (even if it is listed in the lifecycles list) 026 * if the 'use.kewXmlmlDataLoaderLifecycle' configuration property is defined, and is 027 * not 'true'. If the property is omitted the lifecycle runs as normal. 028 * 029 * @author Kuali Rice Team (rice.collab@kuali.org) 030 */ 031public class KEWXmlDataLoaderLifecycle extends BaseLifecycle { 032 private static final Logger LOG = Logger.getLogger(KEWXmlDataLoaderLifecycle.class); 033 034 private String filename; 035 036 /** 037 * Specifies the XML resource to load. The resource path should be in Spring resource notation. 038 * @param resource the XML resource to load 039 */ 040 public KEWXmlDataLoaderLifecycle(String resource) { 041 this.filename = resource; 042 } 043 044 public void start() throws Exception { 045 String useKewXmlDataLoaderLifecycle = ConfigContext.getCurrentContextConfig().getProperty("use.kewXmlmlDataLoaderLifecycle"); 046 if (useKewXmlDataLoaderLifecycle != null && !Boolean.valueOf(useKewXmlDataLoaderLifecycle)) { 047 LOG.debug("Skipping KEWXmlDataLoaderLifecycle due to property: use.kewXmlmlDataLoaderLifecycle=" + useKewXmlDataLoaderLifecycle); 048 return; 049 } 050 051 LOG.info("################################"); 052 LOG.info("#"); 053 LOG.info("# Begin Loading file '" + filename + "'"); 054 LOG.info("#"); 055 LOG.info("################################"); 056 loadData(); 057 super.start(); 058 } 059 060 /** 061 * Does the work of loading the data 062 * @throws Exception 063 */ 064 protected void loadData() throws Exception { 065 KEWXmlDataLoader.loadXmlResource(filename); 066 } 067}