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 java.util.Properties;
19
20 import com.google.common.collect.Lists;
21 import org.kuali.common.util.execute.Executable;
22 import org.kuali.common.util.properties.spring.EnvironmentPropertySourceConfig;
23 import org.kuali.common.util.runonce.smart.RunOnce;
24 import org.kuali.common.util.runonce.smart.RunOnceExecutable;
25 import org.kuali.common.util.spring.SpringExecUtils;
26 import org.kuali.common.util.spring.event.ApplicationEventListenerConfig;
27 import org.kuali.common.util.spring.event.ExecutableApplicationEventListener;
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.CoreConstants;
31 import org.kuali.rice.core.api.config.property.ConfigContext;
32 import org.kuali.rice.xml.ingest.ParameterServiceRunOnce;
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 import org.springframework.context.event.ContextRefreshedEvent;
38 import org.springframework.context.event.SmartApplicationListener;
39 import org.springframework.core.Ordered;
40 import org.springframework.core.env.PropertySource;
41
42
43
44
45
46
47 @Configuration
48 @Import({ SpringServiceConfig.class, EnvironmentPropertySourceConfig.class })
49 public class IngestXmlRunOnceConfig implements ApplicationEventListenerConfig {
50
51 private static final String ORDER_KEY = "rice.ingest.order";
52 private static final String NAMESPACE_KEY = "rice.ingest.param.namespace";
53 private static final String COMPONENT_KEY = "rice.ingest.param.component";
54 private static final String NAME_KEY = "rice.ingest.param.name";
55 private static final String DESCRIPTION_KEY = "rice.ingest.param.description";
56 private static final String RUN_ON_MISSING_PARAMETER_KEY = "rice.ingest.runOnMissingParameter";
57
58 private static final String NAMESPACE = "KR-WKFLW";
59 private static final String COMPONENT = "All";
60 private static final String NAME = "INGEST_XML_AT_STARTUP_IND";
61 private static final String DESCRIPTION = "Set this to 'Y' to ingest XML documents at application startup";
62 private static final Boolean RUN_ON_MISSING_PARAMETER = Boolean.FALSE;
63
64
65
66
67 @Autowired
68 SpringService service;
69
70
71
72
73 @Autowired
74 PropertySource<?> propertySource;
75
76
77
78
79
80
81
82
83
84
85 @Override
86 @Bean
87 public SmartApplicationListener applicationEventListener() {
88 Properties properties = ConfigContext.getCurrentContextConfig().getProperties();
89 String applicationId = properties.getProperty(CoreConstants.Config.APPLICATION_ID);
90 String namespace = properties.getProperty(NAMESPACE_KEY, NAMESPACE);
91 String component = properties.getProperty(COMPONENT_KEY, COMPONENT);
92 String name = properties.getProperty(NAME_KEY, NAME);
93 String description = properties.getProperty(DESCRIPTION_KEY, DESCRIPTION);
94 boolean runOnMissingParameter = Boolean.parseBoolean(properties.getProperty(RUN_ON_MISSING_PARAMETER_KEY, RUN_ON_MISSING_PARAMETER.toString()));
95 int order = Integer.parseInt(properties.getProperty(ORDER_KEY, String.valueOf(Ordered.LOWEST_PRECEDENCE)));
96
97 RunOnce runOnce = ParameterServiceRunOnce.builder(applicationId, namespace, component, name)
98 .description(description).runOnMissingParameter(runOnMissingParameter).build();
99 Executable springExecutable = SpringExecUtils.getSpringExecutable(service, propertySource, IngestXmlExecConfig.class,
100 Lists.newArrayList("master"));
101 Executable executable = RunOnceExecutable.builder(springExecutable, runOnce).build();
102
103 return ExecutableApplicationEventListener.builder(executable, ContextRefreshedEvent.class).order(order).build();
104 }
105
106 }