001/** 002 * Copyright 2005-2015 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.config; 017 018import java.util.ArrayList; 019import java.util.List; 020import java.util.Properties; 021 022import javax.servlet.ServletContext; 023 024import org.apache.logging.log4j.LogManager; 025import org.kuali.common.jdbc.project.spring.JdbcPropertyLocationsConfig; 026import org.kuali.common.util.properties.Location; 027import org.kuali.common.util.properties.PropertiesLocationService; 028import org.kuali.common.util.properties.PropertiesService; 029import org.kuali.common.util.properties.spring.DefaultPropertiesServiceConfig; 030import org.kuali.common.util.properties.spring.PropertiesLocationServiceConfig; 031import org.kuali.common.util.spring.service.PropertySourceConfig; 032import org.kuali.rice.core.api.config.property.Config; 033import org.kuali.rice.core.api.config.property.ConfigContext; 034import org.kuali.rice.core.api.config.property.ConfigPropertySource; 035import org.kuali.rice.sql.spring.SourceSqlPropertyLocationsConfig; 036import org.kuali.rice.xml.ingest.RiceConfigUtils; 037import org.kuali.rice.xml.spring.IngestXmlPropertyLocationsConfig; 038import org.apache.logging.log4j.Logger; 039import org.springframework.beans.factory.annotation.Autowired; 040import org.springframework.context.annotation.Bean; 041import org.springframework.context.annotation.Configuration; 042import org.springframework.context.annotation.Import; 043import org.springframework.core.env.PropertySource; 044 045/** 046 * Holds the property source for all of the different properties needed for starting up the KRAD Sample App. 047 * 048 * @author Kuali Rice Team (rice.collab@kuali.org) 049 */ 050@Configuration 051@Import({ KradSampleAppProjectConfig.class, JdbcPropertyLocationsConfig.class, SourceSqlPropertyLocationsConfig.class, IngestXmlPropertyLocationsConfig.class, 052 PropertiesLocationServiceConfig.class, DefaultPropertiesServiceConfig.class }) 053public class KradSampleAppPSC implements PropertySourceConfig { 054 055 private static final String KRAD_SAMPLE_APP_CONFIG = "classpath:META-INF/krad-sampleapp-config.xml"; 056 057 private static final Logger logger = LogManager.getLogger(KradSampleAppPSC.class); 058 059 @Autowired 060 JdbcPropertyLocationsConfig jdbcConfig; 061 062 @Autowired 063 SourceSqlPropertyLocationsConfig sourceSqlConfig; 064 065 @Autowired 066 IngestXmlPropertyLocationsConfig ingestXmlConfig; 067 068 @Autowired 069 PropertiesLocationService locationService; 070 071 @Autowired 072 PropertiesService service; 073 074 @Autowired 075 ServletContext servletContext; 076 077 @Override 078 @Bean 079 public PropertySource<?> propertySource() { 080 // Combine locations making sure Rice properties go in last 081 List<Location> locations = new ArrayList<Location>(); 082 locations.addAll(jdbcConfig.jdbcPropertyLocations()); 083 locations.addAll(sourceSqlConfig.riceSourceSqlPropertyLocations()); 084 locations.addAll(ingestXmlConfig.riceIngestXmlPropertyLocations()); 085 086 // Default behavior is load->decrypt->resolve 087 // -Dproperties.resolve=false turns off resolve 088 Properties properties = service.getProperties(locations); 089 logger.info("Loaded {} regular properties", properties.size()); 090 091 // Combine normal properties with Rice properties using Rice's custom placeholder resolution logic to resolve everything 092 Config rootCfg = RiceConfigUtils.getRootConfig(properties, KRAD_SAMPLE_APP_CONFIG, servletContext); 093 094 // Make sure ConfigContext.getCurrentContextConfig() return's this rootCfg object 095 ConfigContext.init(rootCfg); 096 097 // Make Spring and Rice use the exact same source for obtaining property values 098 return new ConfigPropertySource("riceConfig", rootCfg); 099 } 100 101}