View Javadoc
1   /**
2    * Copyright 2005-2015 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 com.google.common.base.Optional;
19  import com.google.common.collect.Lists;
20  import org.kuali.common.util.execute.Executable;
21  import org.kuali.common.util.metainf.model.PathComparator;
22  import org.kuali.common.util.metainf.service.MetaInfUtils;
23  import org.kuali.common.util.metainf.spring.MetaInfDataLocation;
24  import org.kuali.common.util.metainf.spring.MetaInfDataType;
25  import org.kuali.common.util.metainf.spring.RiceXmlConfig;
26  import org.kuali.common.util.spring.env.EnvironmentService;
27  import org.kuali.rice.db.config.profile.MetaInfDataTypeProfileConfig;
28  import org.kuali.rice.db.config.profile.RiceServerBootstrapConfig;
29  import org.kuali.rice.db.config.profile.RiceServerDemoConfig;
30  import org.kuali.rice.db.config.profile.RiceMasterConfig;
31  import org.kuali.rice.xml.ingest.IngestXmlExecutable;
32  import org.kuali.rice.xml.project.XmlProjectConstants;
33  import org.springframework.beans.factory.annotation.Autowired;
34  import org.springframework.context.annotation.Bean;
35  import org.springframework.context.annotation.Configuration;
36  import org.springframework.context.annotation.Import;
37  
38  import java.util.Collections;
39  import java.util.List;
40  
41  /**
42   * Central configuration file for launching the workflow XML ingestion process.
43   * 
44   * @author Kuali Rice Team (rice.collab@kuali.org)
45   */
46  @Configuration
47  @Import({ IngestXmlConfig.class, RiceServerBootstrapConfig.class, RiceServerDemoConfig.class, RiceMasterConfig.class })
48  public class IngestXmlExecConfig {
49  
50      private static final String SKIP_KEY = "rice.ingest.skip";
51  
52      // All paths must have the hardcoded separator to be consistent for deployment
53      private static final String PATH_SEPARATOR = "/";
54  
55      private static final String UPGRADE_SQL_PATH = "upgrades" + PATH_SEPARATOR + "*";
56  
57      /**
58       * The Spring environment.
59       */
60  	@Autowired
61  	EnvironmentService env;
62  
63      /**
64       * The {@link MetaInfDataType} profile.
65       */
66      @Autowired
67      MetaInfDataTypeProfileConfig typeConfig;
68  
69      /**
70       * Returns the executable for launching the workflow XML ingestion process.
71       *
72       * @return the executable for launching the workflow XML ingestion process
73       */
74  	@Bean
75  	public Executable ingestXmlExecutable() {
76          List<String> locations = Lists.newArrayList();
77  
78          List<MetaInfDataType> types = getTypes();
79  
80          PathComparator comparator = new PathComparator();
81  
82          for (MetaInfDataType type : types) {
83              List<String> resources = MetaInfUtils.getPatternedClasspathResources(XmlProjectConstants.ID,
84                      Optional.of(UPGRADE_SQL_PATH), Optional.<MetaInfDataLocation> absent(), Optional.of(type), RiceXmlConfig.INGEST_FILENAME);
85              Collections.sort(resources, comparator);
86              locations.addAll(resources);
87          }
88  
89  		Boolean skip = env.getBoolean(SKIP_KEY, Boolean.FALSE);
90  
91  		return IngestXmlExecutable.builder(locations).skip(skip.booleanValue()).build();
92  	}
93  
94      /**
95       * Returns the list of {@link MetaInfDataType}s to be applied to the database, returning an empty list if no
96       * profiles are active.
97       *
98       * @return the list of {@link MetaInfDataType}s to be applied to the database (if any)
99       */
100     protected List<MetaInfDataType> getTypes() {
101         return typeConfig != null ? typeConfig.getMetaInfDataTypes() : Lists.<MetaInfDataType> newArrayList();
102     }
103 
104 }