001/**
002 * Copyright 2005-2017 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.sql.spring;
017
018import java.util.List;
019
020import com.google.common.collect.Lists;
021import org.kuali.common.jdbc.project.spring.JdbcPropertyLocationsConfig;
022import org.kuali.common.util.properties.Location;
023import org.kuali.common.util.properties.PropertiesService;
024import org.kuali.common.util.properties.spring.DefaultPropertiesServiceConfig;
025import org.kuali.common.util.spring.PropertySourceUtils;
026import org.kuali.common.util.spring.service.PropertySourceConfig;
027import org.springframework.beans.factory.annotation.Autowired;
028import org.springframework.context.annotation.Bean;
029import org.springframework.context.annotation.Configuration;
030import org.springframework.context.annotation.Import;
031import org.springframework.core.env.PropertySource;
032
033/**
034 * Holds the property source for all of the different properties needed for the database reset process.
035 * 
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 */
038@Configuration
039@Import({ SourceSqlProjectConfig.class, SourceSqlPropertyLocationsConfig.class, JdbcPropertyLocationsConfig.class, DefaultPropertiesServiceConfig.class })
040public class SourceSqlPSC implements PropertySourceConfig {
041
042    /**
043     * The general JDBC property locations.
044     */
045        @Autowired
046        JdbcPropertyLocationsConfig jdbcConfig;
047
048    /**
049     * The Rice property locations for the database reset process.
050     */
051        @Autowired
052        SourceSqlPropertyLocationsConfig sourceSqlConfig;
053
054    /**
055     * The property locator.
056     */
057        @Autowired
058        PropertiesService service;
059
060    /**
061     * {@inheritDoc}
062     *
063     * <p>
064     * Here we combine all properties, making sure that the Rice project properties go in last.
065     * </p>
066     */
067        @Override
068        @Bean
069        public PropertySource<?> propertySource() {
070                List<Location> locations = Lists.newArrayList();
071
072        locations.addAll(jdbcConfig.jdbcPropertyLocations());
073                locations.addAll(sourceSqlConfig.riceSourceSqlPropertyLocations());
074
075                return PropertySourceUtils.getPropertySource(service, locations);
076        }
077
078}