View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.config;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Properties;
21  
22  import javax.servlet.ServletContext;
23  
24  import org.kuali.common.jdbc.project.spring.JdbcPropertyLocationsConfig;
25  import org.kuali.common.util.log.LoggerUtils;
26  import org.kuali.common.util.properties.Location;
27  import org.kuali.common.util.properties.PropertiesService;
28  import org.kuali.common.util.properties.spring.DefaultPropertiesServiceConfig;
29  import org.kuali.common.util.spring.service.PropertySourceConfig;
30  import org.kuali.rice.core.api.config.property.Config;
31  import org.kuali.rice.core.api.config.property.ConfigContext;
32  import org.kuali.rice.core.api.config.property.ConfigPropertySource;
33  import org.kuali.rice.sql.spring.SourceSqlPropertyLocationsConfig;
34  import org.kuali.rice.xml.ingest.RiceConfigUtils;
35  import org.kuali.rice.xml.spring.IngestXmlPropertyLocationsConfig;
36  import org.slf4j.Logger;
37  import org.springframework.beans.factory.annotation.Autowired;
38  import org.springframework.context.annotation.Bean;
39  import org.springframework.context.annotation.Configuration;
40  import org.springframework.context.annotation.Import;
41  import org.springframework.core.env.PropertySource;
42  
43  /**
44   * Holds the property source for all of the different properties needed for starting up the KRAD
45   * Sample App.
46   * 
47   * @author Kuali Rice Team (rice.collab@kuali.org)
48   */
49  @Configuration
50  @Import({SampleAppProjectConfig.class, JdbcPropertyLocationsConfig.class, DefaultPropertiesServiceConfig.class,
51          SourceSqlPropertyLocationsConfig.class, IngestXmlPropertyLocationsConfig.class})
52  public class SampleAppPSC implements PropertySourceConfig {
53  
54      private static final String KR_SAMPLE_APP_CONFIG = "classpath:META-INF/sample-app-config.xml";
55  
56      private static final Logger logger = LoggerUtils.make();
57  
58      @Autowired
59      JdbcPropertyLocationsConfig jdbcConfig;
60  
61      @Autowired
62      SourceSqlPropertyLocationsConfig sourceSqlConfig;
63  
64      @Autowired
65      IngestXmlPropertyLocationsConfig ingestXmlConfig;
66  
67      @Autowired
68      PropertiesService service;
69  
70      @Autowired
71      ServletContext servletContext;
72  
73      @Override
74      @Bean
75      public PropertySource<?> propertySource() {
76          // Combine locations making sure Rice properties go in last
77          List<Location> locations = new ArrayList<Location>();
78          locations.addAll(jdbcConfig.jdbcPropertyLocations());
79          locations.addAll(sourceSqlConfig.riceSourceSqlPropertyLocations());
80          locations.addAll(ingestXmlConfig.riceIngestXmlPropertyLocations());
81  
82          // Default behavior is load->decrypt->resolve
83          // -Dproperties.resolve=false turns off placeholder resolution
84          Properties properties = service.getProperties(locations);
85          logger.info("Loaded {} regular properties", properties.size());
86  
87          // Combine normal properties with Rice properties using Rice's custom placeholder resolution logic to resolve everything
88          Config rootCfg = RiceConfigUtils.getRootConfig(properties, KR_SAMPLE_APP_CONFIG, servletContext);
89  
90          // Make sure ConfigContext.getCurrentContextConfig() return's the rootCfg object
91          ConfigContext.init(rootCfg);
92  
93          // Make Spring and Rice use the exact same source for obtaining property values
94          return new ConfigPropertySource("riceConfig", rootCfg);
95      }
96  
97  }