1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 freemarker.core.Configurable;
21 import org.kuali.common.util.execute.Executable;
22 import org.kuali.common.util.metainf.model.ConfigurablePathComparator;
23 import org.kuali.common.util.metainf.model.PathComparator;
24 import org.kuali.common.util.metainf.service.MetaInfUtils;
25 import org.kuali.common.util.metainf.spring.MetaInfDataLocation;
26 import org.kuali.common.util.metainf.spring.MetaInfDataType;
27 import org.kuali.common.util.metainf.spring.RiceXmlConfig;
28 import org.kuali.common.util.spring.env.EnvironmentService;
29 import org.kuali.rice.xml.ingest.IngestXmlExecutable;
30 import org.kuali.rice.xml.project.XmlProjectConstants;
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
36 import java.io.File;
37 import java.util.ArrayList;
38 import java.util.Collections;
39 import java.util.EnumSet;
40 import java.util.Iterator;
41 import java.util.List;
42
43
44
45
46
47
48 @Configuration
49 @Import({ IngestXmlConfig.class })
50 public class IngestXmlExecConfig {
51
52 @Autowired
53 EnvironmentService env;
54
55 private static final String SKIP_KEY = "rice.ingest.skip";
56 private static final String RESOURCES_KEY = "rice.ingest.resources";
57
58 @Bean
59 public Executable ingestXmlExecutable() {
60 String qualifier = "upgrades" + File.separator + "*";
61 List<String> locations = new ArrayList<String>();
62
63 for (MetaInfDataType type : getTypes()) {
64 List<String> resources = MetaInfUtils.getPatternedClasspathResources(XmlProjectConstants.ID,
65 Optional.of(qualifier), Optional.<MetaInfDataLocation> absent(), Optional.of(type), RiceXmlConfig.INGEST_FILENAME);
66 locations.addAll(resources);
67 }
68
69 ConfigurablePathComparator comparator = ConfigurablePathComparator.builder().typeOrder(getTypes()).build();
70 Collections.sort(locations, comparator);
71
72
73 boolean skip = env.getBoolean(SKIP_KEY, false);
74 return new IngestXmlExecutable.Builder(locations).skip(skip).build();
75 }
76
77 private List<MetaInfDataType> getTypes() {
78 return Lists.newArrayList(MetaInfDataType.BOOTSTRAP, MetaInfDataType.DEMO, MetaInfDataType.TEST);
79 }
80
81 }