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 org.kuali.common.util.execute.Executable;
21 import org.kuali.common.util.properties.spring.EnvironmentPropertySourceConfig;
22 import org.kuali.common.util.runonce.smart.RunOnce;
23 import org.kuali.common.util.runonce.smart.RunOnceExecutable;
24 import org.kuali.common.util.spring.SpringExecUtils;
25 import org.kuali.common.util.spring.event.ApplicationEventListenerConfig;
26 import org.kuali.common.util.spring.event.ExecutableApplicationEventListener;
27 import org.kuali.common.util.spring.service.SpringService;
28 import org.kuali.common.util.spring.service.SpringServiceConfig;
29 import org.kuali.rice.core.api.CoreConstants;
30 import org.kuali.rice.core.api.config.property.ConfigContext;
31 import org.kuali.rice.sql.spring.SourceSqlExecConfig;
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 @Autowired
52 SpringService service;
53
54 @Autowired
55 PropertySource<?> propertySource;
56
57 private static final String ORDER_KEY = "rice.ingest.order";
58 private static final String NAMESPACE_KEY = "rice.ingest.param.namespace";
59 private static final String COMPONENT_KEY = "rice.ingest.param.component";
60 private static final String NAME_KEY = "rice.ingest.param.name";
61 private static final String DESCRIPTION_KEY = "rice.ingest.param.description";
62 private static final String RUN_ON_MISSING_PARAMETER_KEY = "rice.ingest.runOnMissingParameter";
63
64 private static final String NAMESPACE = "KR-WKFLW";
65 private static final String COMPONENT = "All";
66 private static final String NAME = "INGEST_XML_AT_STARTUP_IND";
67 private static final String DESCRIPTION = "Set this to 'Y' to ingest XML documents at application startup";
68 private static final Boolean RUN_ON_MISSING_PARAMETER = Boolean.FALSE;
69
70 @Override
71 @Bean
72 public SmartApplicationListener applicationEventListener() {
73
74
75 Properties properties = ConfigContext.getCurrentContextConfig().getProperties();
76 String applicationId = properties.getProperty(CoreConstants.Config.APPLICATION_ID);
77 String namespace = properties.getProperty(NAMESPACE_KEY, NAMESPACE);
78 String component = properties.getProperty(COMPONENT_KEY, COMPONENT);
79 String name = properties.getProperty(NAME_KEY, NAME);
80 String description = properties.getProperty(DESCRIPTION_KEY, DESCRIPTION);
81 boolean runOnMissingParameter = Boolean.parseBoolean(properties.getProperty(RUN_ON_MISSING_PARAMETER_KEY, RUN_ON_MISSING_PARAMETER.toString()));
82
83 RunOnce runOnce = ParameterServiceRunOnce.builder().applicationId(applicationId).namespace(namespace).component(component).name(name).description(description)
84 .runOnMissingParameter(runOnMissingParameter).build();
85 Executable springExecutable = SpringExecUtils.getSpringExecutable(service, propertySource, IngestXmlExecConfig.class);
86 Executable executable = RunOnceExecutable.builder(springExecutable, runOnce).build();
87
88
89 int order = Integer.parseInt(properties.getProperty(ORDER_KEY, Ordered.LOWEST_PRECEDENCE + ""));
90 return ExecutableApplicationEventListener.builder(executable, ContextRefreshedEvent.class).order(order).build();
91 }
92 }