1 |
7542
|
tao
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Purpose: A class that gets Accession Number, check for uniqueness
|
4 |
|
|
* and register it into db
|
5 |
|
|
* Copyright: 2000 Regents of the University of California and the
|
6 |
|
|
* National Center for Ecological Analysis and Synthesis
|
7 |
|
|
* Authors: Jivka Bojilova, Matt Jones
|
8 |
|
|
*
|
9 |
|
|
* '$Author: leinfelder $'
|
10 |
|
|
* '$Date: 2011-11-02 20:40:12 -0700 (Wed, 02 Nov 2011) $'
|
11 |
|
|
* '$Revision: 6595 $'
|
12 |
|
|
*
|
13 |
|
|
* This program is free software; you can redistribute it and/or modify
|
14 |
|
|
* it under the terms of the GNU General Public License as published by
|
15 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
16 |
|
|
* (at your option) any later version.
|
17 |
|
|
*
|
18 |
|
|
* This program is distributed in the hope that it will be useful,
|
19 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
|
|
* GNU General Public License for more details.
|
22 |
|
|
*
|
23 |
|
|
* You should have received a copy of the GNU General Public License
|
24 |
|
|
* along with this program; if not, write to the Free Software
|
25 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
26 |
|
|
*/
|
27 |
|
|
package edu.ucsb.nceas.metacat.index;
|
28 |
|
|
|
29 |
|
|
import java.util.List;
|
30 |
|
|
|
31 |
|
|
import org.apache.commons.logging.Log;
|
32 |
|
|
import org.apache.commons.logging.LogFactory;
|
33 |
7589
|
leinfelder
|
import org.apache.solr.client.solrj.SolrServer;
|
34 |
7542
|
tao
|
import org.springframework.context.ApplicationContext;
|
35 |
|
|
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
36 |
|
|
|
37 |
|
|
/**
|
38 |
|
|
* The start class of the index.
|
39 |
|
|
* @author tao
|
40 |
|
|
*
|
41 |
|
|
*/
|
42 |
|
|
public class ApplicationController {
|
43 |
|
|
|
44 |
|
|
private static String SOLRINDEXES = "solrIndexes";
|
45 |
7589
|
leinfelder
|
|
46 |
7542
|
tao
|
private List<SolrIndex> solrIndexes = null;
|
47 |
|
|
private static ApplicationContext context = null;
|
48 |
|
|
private String springConfigFile = "src/main/resources/index-processor-context.xml";
|
49 |
|
|
Log log = LogFactory.getLog(ApplicationController.class);
|
50 |
|
|
|
51 |
|
|
/**
|
52 |
|
|
* Constructor
|
53 |
|
|
*/
|
54 |
|
|
public ApplicationController () {
|
55 |
|
|
init();
|
56 |
|
|
}
|
57 |
|
|
|
58 |
7552
|
tao
|
/**
|
59 |
|
|
* Set the Spring configuration file.
|
60 |
|
|
* @param springConfigFile the path of the Spring configuration file
|
61 |
|
|
*/
|
62 |
|
|
public ApplicationController(String springConfigFile) {
|
63 |
|
|
this.springConfigFile = springConfigFile;
|
64 |
|
|
init();
|
65 |
|
|
}
|
66 |
|
|
|
67 |
7560
|
leinfelder
|
/**
|
68 |
7589
|
leinfelder
|
* Initialize the list of the SolrIndex objects from the configuration file.
|
69 |
|
|
* Set the SolrServer implementation using the factory.
|
70 |
|
|
* Start listening for events on Hazelcast
|
71 |
7542
|
tao
|
*/
|
72 |
|
|
private void init() {
|
73 |
|
|
context = getContext();
|
74 |
|
|
solrIndexes = (List<SolrIndex>) context.getBean(SOLRINDEXES);
|
75 |
|
|
|
76 |
7591
|
leinfelder
|
// use factory to create the correct impl
|
77 |
7589
|
leinfelder
|
SolrServer solrServer = null;
|
78 |
7591
|
leinfelder
|
try {
|
79 |
|
|
solrServer = SolrServerFactory.createSolrServer();
|
80 |
|
|
} catch (Exception e) {
|
81 |
|
|
log.error("Could not create SolrServer form factory", e);
|
82 |
|
|
}
|
83 |
7589
|
leinfelder
|
|
84 |
7560
|
leinfelder
|
// start the SystemMetadata listener[s] (only expect there to be one)
|
85 |
|
|
for (SolrIndex solrIndex: solrIndexes) {
|
86 |
7589
|
leinfelder
|
// set the solr server to use
|
87 |
|
|
solrIndex.setSolrServer(solrServer);
|
88 |
|
|
|
89 |
|
|
// start listening for events
|
90 |
7560
|
leinfelder
|
SystemMetadataEventListener smel = new SystemMetadataEventListener();
|
91 |
|
|
smel.setSolrIndex(solrIndex);
|
92 |
|
|
smel.start();
|
93 |
|
|
}
|
94 |
|
|
|
95 |
7542
|
tao
|
}
|
96 |
|
|
|
97 |
7589
|
leinfelder
|
/**
|
98 |
7542
|
tao
|
* Get the ApplicaionContext of Spring.
|
99 |
|
|
*/
|
100 |
|
|
private ApplicationContext getContext() {
|
101 |
|
|
if (context == null) {
|
102 |
|
|
context = new FileSystemXmlApplicationContext(springConfigFile);
|
103 |
|
|
}
|
104 |
|
|
return context;
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
/**
|
108 |
|
|
* Get the path of the Spring configuration file.
|
109 |
|
|
* @return the path of the Spring configuration file.
|
110 |
|
|
*/
|
111 |
|
|
public String getSpringConfigFile() {
|
112 |
|
|
return this.springConfigFile;
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
/**
|
116 |
|
|
* Get the list of the solr index.
|
117 |
|
|
* @return the list of the solr index.
|
118 |
|
|
*/
|
119 |
|
|
public List<SolrIndex> getSolrIndexes() {
|
120 |
|
|
return this.solrIndexes;
|
121 |
|
|
}
|
122 |
|
|
}
|