001    /**
002     * Copyright 2004-2012 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     */
016    package org.kuali.rice.test.lifecycles;
017    
018    import org.apache.log4j.Logger;
019    import org.kuali.rice.core.api.config.property.ConfigContext;
020    import org.kuali.rice.core.api.lifecycle.BaseLifecycle;
021    import org.kuali.rice.kew.batch.KEWXmlDataLoader;
022    
023    
024    public class KPMEXmlDataLoaderLifecycle extends BaseLifecycle {
025        private static final Logger LOG = Logger.getLogger(KEWXmlDataLoaderLifecycle.class);
026    
027        private String filename;
028    
029        /**
030         * Specifies the XML resource to load.  The resource path should be in Spring resource notation.
031         * @param resource the XML resource to load
032         */
033        public KPMEXmlDataLoaderLifecycle(String resource) {
034            this.filename = resource;
035        }
036    
037        public void start() throws Exception {
038            String useKewXmlDataLoaderLifecycle = ConfigContext.getCurrentContextConfig().getProperty("use.kewXmlmlDataLoaderLifecycle");
039    
040            if (useKewXmlDataLoaderLifecycle != null && !Boolean.valueOf(useKewXmlDataLoaderLifecycle)) {
041                LOG.debug("Skipping KEWXmlDataLoaderLifecycle due to property: use.kewXmlmlDataLoaderLifecycle=" + useKewXmlDataLoaderLifecycle);
042                return;
043            }
044    
045            LOG.info("################################");
046            LOG.info("#");
047            LOG.info("#  Begin Loading file '" + filename + "'");
048            LOG.info("#");
049            LOG.info("################################");
050            loadData();
051            super.start();
052        }
053    
054        /**
055         * Does the work of loading the data
056         * @throws Exception
057         */
058        protected void loadData() throws Exception {
059            KEWXmlDataLoader.loadXmlFile(filename);
060        }
061    }