1 package org.kuali.ole;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.docstore.common.document.config.DocumentSearchConfig;
5 import org.kuali.ole.docstore.discovery.util.DiscoveryEnvUtil;
6 import org.kuali.ole.docstore.util.DocStoreEnvUtil;
7 import org.kuali.ole.docstore.utility.DocumentStoreMaintenance;
8 import org.kuali.ole.utility.Constants;
9 import org.kuali.rice.core.api.config.module.RunMode;
10 import org.kuali.rice.core.api.config.property.ConfigContext;
11 import org.kuali.rice.core.framework.config.module.ModuleConfigurer;
12
13 import java.io.File;
14 import java.io.FileOutputStream;
15 import java.io.IOException;
16 import java.util.Arrays;
17 import java.util.Properties;
18
19
20
21
22
23
24
25
26
27 public class OleDocstoreModuleConfigurer extends ModuleConfigurer {
28 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleDocstoreModuleConfigurer.class);
29
30 DocStoreEnvUtil docStoreEnvUtil = new DocStoreEnvUtil();
31 DiscoveryEnvUtil discoveryEnvUtil = new DiscoveryEnvUtil();
32 DocumentStoreMaintenance documentStoreMaintenance = new DocumentStoreMaintenance();
33
34 public OleDocstoreModuleConfigurer() {
35 super("OLE-DOCSTORE");
36 LOG.info("OLE-Docstore Configurer instantiated");
37 setValidRunModes(Arrays.asList(RunMode.LOCAL));
38 }
39
40 @Override
41 protected void doAdditionalModuleStartLogic() throws Exception {
42 LOG.info("*********************************************************");
43 LOG.info("OLE Docstore Starting Module");
44 LOG.info("*********************************************************");
45 super.doAdditionalModuleStartLogic();
46
47 try {
48 docStoreEnvUtil.initEnvironment();
49 discoveryEnvUtil.initEnvironment();
50 String fileSeparator = File.separator;
51 File file = new File(discoveryEnvUtil.getSolrConfigDirectoryPath()+fileSeparator+"bib"+fileSeparator+"conf"+fileSeparator+"solrcore.properties");
52 file.deleteOnExit();
53 try{
54 Properties props = new Properties();
55 FileOutputStream out = new FileOutputStream(file);
56 props.setProperty("db.driver", ConfigContext.getCurrentContextConfig().getProperty("jdbc.driver"));
57 props.setProperty("db.url", ConfigContext.getCurrentContextConfig().getProperty("jdbc.url"));
58 props.setProperty("db.username", ConfigContext.getCurrentContextConfig().getProperty("jdbc.username"));
59 props.setProperty("db.password", ConfigContext.getCurrentContextConfig().getProperty("jdbc.password"));
60 props.store(out, null);
61 out.close();
62 }catch(Exception e){
63 e.printStackTrace();
64 }
65 String docstoreHome = System.getProperty(Constants.OLE_DOCSTORE_HOME_SYSTEM_PROPERTY);
66 String discoveryHome = System.getProperty(Constants.OLE_DISCOVERY_HOME_SYSTEM_PROPERTY);
67 validate(docstoreHome, discoveryHome);
68 documentStoreMaintenance.docStoreMaintenance(docstoreHome, discoveryHome);
69 DocumentSearchConfig.getDocumentSearchConfig();
70 } catch (IOException e) {
71
72
73 throw new IllegalStateException(e);
74 }
75
76 }
77
78 protected void validate(String docstoreHome, String discoveryHome) {
79 StringBuilder sb = new StringBuilder();
80 if (StringUtils.isBlank(docstoreHome)) {
81 sb.append(Constants.OLE_DOCSTORE_HOME_SYSTEM_PROPERTY + " cannot be blank. ");
82 }
83 if (StringUtils.isBlank(docstoreHome)) {
84 sb.append(Constants.OLE_DISCOVERY_HOME_SYSTEM_PROPERTY + " cannot be blank.");
85 }
86 if (sb.length() != 0) {
87 throw new IllegalStateException(sb.toString());
88 }
89 }
90
91 @Override
92 protected void doAdditionalModuleStopLogic() throws Exception {
93 LOG.info("*********************************************************");
94 LOG.info("OLE Stopping Module");
95 LOG.info("*********************************************************");
96 super.doAdditionalModuleStopLogic();
97 }
98 }