1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.sql.spring;
17
18 import java.io.File;
19 import java.util.Properties;
20
21 import com.google.common.collect.Lists;
22 import org.kuali.common.util.execute.Executable;
23 import org.kuali.common.util.execute.spring.ExecutableConfig;
24 import org.kuali.common.util.properties.spring.EnvironmentPropertySourceConfig;
25 import org.kuali.common.util.runonce.smart.PropertiesFileRunOnce;
26 import org.kuali.common.util.runonce.smart.RunOnce;
27 import org.kuali.common.util.runonce.smart.RunOnceExecutable;
28 import org.kuali.common.util.spring.SpringExecUtils;
29 import org.kuali.common.util.spring.service.SpringService;
30 import org.kuali.common.util.spring.service.SpringServiceConfig;
31 import org.kuali.rice.core.api.config.property.ConfigContext;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.context.annotation.Bean;
34 import org.springframework.context.annotation.Configuration;
35 import org.springframework.context.annotation.Import;
36 import org.springframework.core.env.PropertySource;
37
38
39
40
41
42
43 @Configuration
44 @Import({ SpringServiceConfig.class, EnvironmentPropertySourceConfig.class })
45 public class SourceSqlRunOnceConfig implements ExecutableConfig {
46
47 private static final String PROJECT_HOME_KEY = "project.home";
48 private static final String RUNONCE_FILENAME = "runonce.properties";
49 private static final String ENCODING = "UTF-8";
50 private static final String PROPERTY_KEY = "project.db.reset";
51
52
53
54
55 @Autowired
56 SpringService service;
57
58
59
60
61 @Autowired
62 PropertySource<?> propertySource;
63
64
65
66
67
68
69
70
71
72
73 @Override
74 @Bean(initMethod = "execute")
75 public Executable executable() {
76 Properties properties = ConfigContext.getCurrentContextConfig().getProperties();
77 String projectHome = properties.getProperty(PROJECT_HOME_KEY);
78
79 File file = new File(projectHome, RUNONCE_FILENAME);
80 RunOnce runOnce = PropertiesFileRunOnce.builder(file, ENCODING, PROPERTY_KEY).build();
81 Executable executable = SpringExecUtils.getSpringExecutable(service, propertySource, SourceSqlExecConfig.class,
82 Lists.newArrayList("master"));
83
84 return RunOnceExecutable.builder(executable, runOnce).build();
85 }
86
87 }