001/**
002 * Copyright 2005-2016 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.xml.spring;
017
018import org.kuali.common.util.execute.Executable;
019import org.kuali.common.util.spring.env.EnvironmentService;
020import org.kuali.common.util.spring.event.ApplicationEventListenerConfig;
021import org.kuali.common.util.spring.event.ExecutableApplicationEventListener;
022import org.kuali.common.util.spring.service.SpringServiceConfig;
023import org.springframework.beans.factory.annotation.Autowired;
024import org.springframework.context.annotation.Bean;
025import org.springframework.context.annotation.Configuration;
026import org.springframework.context.annotation.Import;
027import org.springframework.context.event.ContextRefreshedEvent;
028import org.springframework.context.event.SmartApplicationListener;
029import org.springframework.core.Ordered;
030
031/**
032 * Sets up a {@code SmartApplicationListener} that ingests workflow XML when it receives a
033 * {@code ContextRefreshedEvent}.
034 * 
035 * @author Kuali Rice Team (rice.collab@kuali.org)
036 */
037@Configuration
038@Import({ SpringServiceConfig.class })
039public class IngestXmlConfig implements ApplicationEventListenerConfig {
040
041    private static final String ORDER_KEY = "rice.ingest.order";
042
043    /**
044     * The ingestion executable.
045     */
046    @Autowired
047    IngestXmlExecConfig config;
048
049    /**
050     * The Spring environment.
051     */
052        @Autowired
053        EnvironmentService env;
054
055    /**
056     * {@inheritDoc}
057     */
058        @Override
059        @Bean
060        public SmartApplicationListener applicationEventListener() {
061                Executable executable = config.ingestXmlExecutable();
062        Integer order = env.getInteger(ORDER_KEY, Integer.valueOf(Ordered.LOWEST_PRECEDENCE));
063
064                return ExecutableApplicationEventListener.builder(executable, ContextRefreshedEvent.class).order(order.intValue()).build();
065        }
066
067}