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 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
43
44
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
53 private static final String PATH_SEPARATOR = "/";
54
55 private static final String UPGRADE_SQL_PATH = "upgrades" + PATH_SEPARATOR + "*";
56
57
58
59
60 @Autowired
61 EnvironmentService env;
62
63
64
65
66 @Autowired
67 MetaInfDataTypeProfileConfig typeConfig;
68
69
70
71
72
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
96
97
98
99
100 protected List<MetaInfDataType> getTypes() {
101 return typeConfig != null ? typeConfig.getMetaInfDataTypes() : Lists.<MetaInfDataType> newArrayList();
102 }
103
104 }