001/** 002 * Copyright 2005-2016 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.xml.spring; 017 018import com.google.common.base.Optional; 019import com.google.common.collect.Lists; 020import org.kuali.common.util.execute.Executable; 021import org.kuali.common.util.metainf.model.PathComparator; 022import org.kuali.common.util.metainf.service.MetaInfUtils; 023import org.kuali.common.util.metainf.spring.MetaInfDataLocation; 024import org.kuali.common.util.metainf.spring.MetaInfDataType; 025import org.kuali.common.util.metainf.spring.RiceXmlConfig; 026import org.kuali.common.util.spring.env.EnvironmentService; 027import org.kuali.rice.db.config.profile.MetaInfDataTypeProfileConfig; 028import org.kuali.rice.db.config.profile.RiceServerBootstrapConfig; 029import org.kuali.rice.db.config.profile.RiceServerDemoConfig; 030import org.kuali.rice.db.config.profile.RiceMasterConfig; 031import org.kuali.rice.xml.ingest.IngestXmlExecutable; 032import org.kuali.rice.xml.project.XmlProjectConstants; 033import org.springframework.beans.factory.annotation.Autowired; 034import org.springframework.context.annotation.Bean; 035import org.springframework.context.annotation.Configuration; 036import org.springframework.context.annotation.Import; 037 038import java.util.Collections; 039import java.util.List; 040 041/** 042 * Central configuration file for launching the workflow XML ingestion process. 043 * 044 * @author Kuali Rice Team (rice.collab@kuali.org) 045 */ 046@Configuration 047@Import({ IngestXmlConfig.class, RiceServerBootstrapConfig.class, RiceServerDemoConfig.class, RiceMasterConfig.class }) 048public class IngestXmlExecConfig { 049 050 private static final String SKIP_KEY = "rice.ingest.skip"; 051 052 // All paths must have the hardcoded separator to be consistent for deployment 053 private static final String PATH_SEPARATOR = "/"; 054 055 private static final String UPGRADE_SQL_PATH = "upgrades" + PATH_SEPARATOR + "*"; 056 057 /** 058 * The Spring environment. 059 */ 060 @Autowired 061 EnvironmentService env; 062 063 /** 064 * The {@link MetaInfDataType} profile. 065 */ 066 @Autowired 067 MetaInfDataTypeProfileConfig typeConfig; 068 069 /** 070 * Returns the executable for launching the workflow XML ingestion process. 071 * 072 * @return the executable for launching the workflow XML ingestion process 073 */ 074 @Bean 075 public Executable ingestXmlExecutable() { 076 List<String> locations = Lists.newArrayList(); 077 078 List<MetaInfDataType> types = getTypes(); 079 080 PathComparator comparator = new PathComparator(); 081 082 for (MetaInfDataType type : types) { 083 List<String> resources = MetaInfUtils.getPatternedClasspathResources(XmlProjectConstants.ID, 084 Optional.of(UPGRADE_SQL_PATH), Optional.<MetaInfDataLocation> absent(), Optional.of(type), RiceXmlConfig.INGEST_FILENAME); 085 Collections.sort(resources, comparator); 086 locations.addAll(resources); 087 } 088 089 Boolean skip = env.getBoolean(SKIP_KEY, Boolean.FALSE); 090 091 return IngestXmlExecutable.builder(locations).skip(skip.booleanValue()).build(); 092 } 093 094 /** 095 * Returns the list of {@link MetaInfDataType}s to be applied to the database, returning an empty list if no 096 * profiles are active. 097 * 098 * @return the list of {@link MetaInfDataType}s to be applied to the database (if any) 099 */ 100 protected List<MetaInfDataType> getTypes() { 101 return typeConfig != null ? typeConfig.getMetaInfDataTypes() : Lists.<MetaInfDataType> newArrayList(); 102 } 103 104}