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 org.kuali.common.util.execute.Executable;
22 import org.kuali.common.util.execute.spring.ExecutableConfig;
23 import org.kuali.common.util.properties.spring.EnvironmentPropertySourceConfig;
24 import org.kuali.common.util.runonce.smart.PropertiesFileRunOnce;
25 import org.kuali.common.util.runonce.smart.RunOnce;
26 import org.kuali.common.util.runonce.smart.RunOnceExecutable;
27 import org.kuali.common.util.spring.SpringExecUtils;
28 import org.kuali.common.util.spring.service.SpringService;
29 import org.kuali.common.util.spring.service.SpringServiceConfig;
30 import org.kuali.rice.core.api.config.property.ConfigContext;
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 import org.springframework.core.env.PropertySource;
36
37
38
39
40
41
42 @Configuration
43 @Import({ SpringServiceConfig.class, EnvironmentPropertySourceConfig.class })
44 public class SourceSqlRunOnceConfig implements ExecutableConfig {
45
46 @Autowired
47 SpringService service;
48
49 @Autowired
50 PropertySource<?> propertySource;
51
52 private static final String PROJECT_HOME_KEY = "project.home";
53 private static final String RUNONCE_FILENAME = "runonce.properties";
54 private static final String ENCODING = "UTF-8";
55 private static final String PROPERTY_KEY = "project.db.reset";
56
57 @Override
58 @Bean(initMethod = "execute")
59 public Executable executable() {
60
61
62 Properties properties = ConfigContext.getCurrentContextConfig().getProperties();
63 String projectHome = properties.getProperty(PROJECT_HOME_KEY);
64
65 File file = new File(projectHome, RUNONCE_FILENAME);
66 RunOnce runOnce = PropertiesFileRunOnce.builder(file, ENCODING, PROPERTY_KEY).build();
67 Executable executable = SpringExecUtils.getSpringExecutable(service, propertySource, SourceSqlExecConfig.class);
68
69 return RunOnceExecutable.builder(executable, runOnce).build();
70 }
71 }