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.xml.spring;
17  
18  import java.util.List;
19  import java.util.Properties;
20  
21  import com.google.common.collect.Lists;
22  import org.kuali.common.jdbc.project.spring.JdbcPropertyLocationsConfig;
23  import org.kuali.common.util.project.ProjectUtils;
24  import org.kuali.common.util.properties.Location;
25  import org.kuali.common.util.properties.PropertiesService;
26  import org.kuali.common.util.properties.spring.DefaultPropertiesServiceConfig;
27  import org.kuali.common.util.spring.service.PropertySourceConfig;
28  import org.kuali.rice.core.api.config.property.Config;
29  import org.kuali.rice.sql.spring.SourceSqlPropertyLocationsConfig;
30  import org.kuali.rice.xml.ingest.RiceConfigUtils;
31  import org.springframework.beans.factory.annotation.Autowired;
32  import org.springframework.context.annotation.Bean;
33  import org.springframework.context.annotation.Configuration;
34  import org.springframework.context.annotation.Import;
35  import org.springframework.core.env.PropertiesPropertySource;
36  import org.springframework.core.env.PropertySource;
37  
38  /**
39   * Holds the property source for all of the different properties needed for the workflow XML ingestion process.
40   * 
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   */
43  @Configuration
44  @Import({ JdbcPropertyLocationsConfig.class, DefaultPropertiesServiceConfig.class, SourceSqlPropertyLocationsConfig.class, IngestXmlPropertyLocationsConfig.class })
45  public class IngestXmlPSC implements PropertySourceConfig {
46  
47      /**
48       * The general JDBC property locations.
49       */
50  	@Autowired
51  	JdbcPropertyLocationsConfig jdbcConfig;
52  
53      /**
54       * The Rice property locations for the database reset process.
55       */
56  	@Autowired
57  	SourceSqlPropertyLocationsConfig sourceSqlConfig;
58  
59      /**
60       * The Rice property locations for the workflow XML ingestion process.
61       */
62  	@Autowired
63  	IngestXmlPropertyLocationsConfig ingestXmlConfig;
64  
65      /**
66       * The property locator.
67       */
68  	@Autowired
69  	PropertiesService service;
70  
71      /**
72       * {@inheritDoc}
73       *
74       * <p>
75       * Here we combine all properties, making sure that the Rice project properties go in last.
76       * </p>
77       */
78  	@Override
79  	@Bean
80  	public PropertySource<?> propertySource() {
81  		List<Location> locations = Lists.newArrayList();
82  
83  		locations.addAll(jdbcConfig.jdbcPropertyLocations());
84  		locations.addAll(sourceSqlConfig.riceSourceSqlPropertyLocations());
85  		locations.addAll(ingestXmlConfig.riceIngestXmlPropertyLocations());
86  
87  		Properties properties = service.getProperties(locations);
88  
89  		String location = ProjectUtils.getPath(RiceXmlProperties.APP.getResource());
90  		Config riceConfig = RiceConfigUtils.parseAndInit(location);
91  		RiceConfigUtils.putProperties(riceConfig, properties);
92  
93  		return new PropertiesPropertySource("properties", riceConfig.getProperties());
94  	}
95  
96  }