Project

General

Profile

1
/**
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
import org.apache.solr.client.solrj.SolrServer;
34
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

    
46
    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
    /**
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
    /**
68
     * 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
     */
72
    private void init() {
73
        context = getContext();
74
        solrIndexes = (List<SolrIndex>) context.getBean(SOLRINDEXES);
75
        
76
        // TODO: use factory to create the correct impl
77
    	SolrServer solrServer = null;
78

    
79
        // start the SystemMetadata listener[s] (only expect there to be one)
80
        for (SolrIndex solrIndex: solrIndexes) {
81
        	// set the solr server to use
82
			solrIndex.setSolrServer(solrServer);
83
			
84
			// start listening for events
85
        	SystemMetadataEventListener smel = new SystemMetadataEventListener();
86
        	smel.setSolrIndex(solrIndex);
87
        	smel.start();
88
        }
89
        
90
    }
91
    
92
    /**
93
     * Get the ApplicaionContext of Spring.
94
     */
95
    private ApplicationContext getContext() {
96
        if (context == null) {
97
            context = new FileSystemXmlApplicationContext(springConfigFile);
98
        }
99
        return context;
100
    }
101

    
102
    /**
103
     * Get the path of the Spring configuration file.
104
     * @return the path of the Spring configuration file.
105
     */
106
    public String getSpringConfigFile() {
107
        return this.springConfigFile;
108
    }
109
    
110
    /**
111
     * Get the list of the solr index.
112
     * @return the list of the solr index.
113
     */
114
    public List<SolrIndex> getSolrIndexes() {
115
        return this.solrIndexes;
116
    }
117
}
(1-1/4)