Project

General

Profile

1 7552 tao
/**
2 8138 tao
 *  Copyright: 2013 Regents of the University of California and the
3 7552 tao
 *             National Center for Ecological Analysis and Synthesis
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 2 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 */
18
package edu.ucsb.nceas.metacat.index;
19
20
21
22 7566 leinfelder
import java.io.File;
23 7552 tao
import java.io.IOException;
24
import java.net.URL;
25
import java.util.List;
26
27
import javax.servlet.ServletConfig;
28
import javax.servlet.ServletException;
29
import javax.servlet.http.HttpServlet;
30
import javax.servlet.http.HttpServletRequest;
31
import javax.servlet.http.HttpServletResponse;
32
33 7558 leinfelder
import org.apache.commons.configuration.ConfigurationException;
34
import org.apache.commons.logging.Log;
35
import org.apache.commons.logging.LogFactory;
36
import org.dataone.configuration.Settings;
37 7552 tao
38 7769 tao
import edu.ucsb.nceas.metacat.common.query.EnabledQueryEngines;
39 7552 tao
40 7769 tao
41 7552 tao
/**
42
 * A servlet class for the Metadata Index module. This class only does one thing - initialize the ApplicationController class.
43
 * @author tao
44
 *
45
 */
46
public class MetacatIndexServlet extends HttpServlet {
47
48 7588 leinfelder
    // Use the file prefix to indicate this is a absolute path.
49
    // see http://www.docjar.com/docs/api/org/springframework/context/support/FileSystemXmlApplicationContext.html
50 8128 tao
    //private static final String FILEPREFIX = "file:";
51 7558 leinfelder
52
	private static Log log = LogFactory.getLog(MetacatIndexServlet.class);
53
54 7552 tao
    /**
55
     * Initialize the servlet
56
     */
57
    public void init(ServletConfig config) throws ServletException {
58
        //System.out.println("++++++++++++++++++++++++------------------- start the servlet");
59 7783 tao
    	//initializeSharedConfiguration(config);
60 7588 leinfelder
    	// initialize the application using the configured application-context
61 8128 tao
        //URL url = getClass().getResource("/index-processor-context.xml");
62 7783 tao
        //find the sibling metacat.properties file
63
        String metacatPropertiesFilePath = config.getServletContext().getInitParameter("metacat.properties.path");
64
        File contextDeploymentDir = new File(config.getServletContext().getRealPath("/"));
65
        String fullMetacatPropertiesFilePath = contextDeploymentDir.getParent()  + metacatPropertiesFilePath;
66 7588 leinfelder
        //System.out.println("the url is "+url);
67
        //System.out.println("the path is "+url.getPath());
68
        //System.out.println("the file is "+url.getPath());
69 7783 tao
        //ApplicationController controller = null;
70 7613 tao
        try {
71 8128 tao
             //ApplicationController controller = new ApplicationController(FILEPREFIX + url.getFile(), fullMetacatPropertiesFilePath);
72
            ApplicationController controller = new ApplicationController("/index-processor-context.xml", fullMetacatPropertiesFilePath);
73 7783 tao
             //Start the controller in other thread - SystemmetadataEventListener and to generate indexes for those haven't been indexed in another thread
74
             Thread controllerThread = new Thread(controller);
75
             controllerThread.start();
76 7613 tao
        } catch (Exception e) {
77
            throw new ServletException(e.getMessage());
78
        }
79 7776 tao
80
        //controller.startIndex();//Start to generate indexes for those haven't been indexed in another thread
81 7613 tao
        //List<SolrIndex> list = controller.getSolrIndexes();
82 7588 leinfelder
        //System.out.println("++++++++++++++++++++++++------------------- the size is  "+list.size());
83
    }
84
85
    /**
86
     * Loads the metacat.prioerties into D1 Settings utility
87
     * this gives us access to all metacat properties as well as
88
     * overriding any properties as needed.
89
     *
90
     * Makes sure shared Hazelcast configuration file location is set
91
     *
92
     * @param config the servlet config
93
     */
94 7783 tao
    /*private void initializeSharedConfiguration(ServletConfig config) {
95 7588 leinfelder
96 7558 leinfelder
		try {
97
			// find the sibling metacat.properties file
98 7566 leinfelder
			String metacatPropertiesFilePath = config.getServletContext().getInitParameter("metacat.properties.path");
99
			File contextDeploymentDir = new File(config.getServletContext().getRealPath("/"));
100
			String fullMetacatPropertiesFilePath = contextDeploymentDir.getParent()  + metacatPropertiesFilePath;
101 7558 leinfelder
			Settings.augmentConfiguration(fullMetacatPropertiesFilePath);
102
		} catch (ConfigurationException e) {
103
			log.error("Could not initialize shared Metacat properties. " + e.getMessage(), e);
104
		}
105 7588 leinfelder
106
		// make sure hazelcast configuration is defined so that
107 7584 leinfelder
		String hzConfigFileName = Settings.getConfiguration().getString("dataone.hazelcast.configFilePath");
108
		if (hzConfigFileName == null) {
109
			// use default metacat hazelcast.xml file in metacat deployment
110
			hzConfigFileName =
111
    				Settings.getConfiguration().getString("application.deployDir") +
112
    				"/" +
113
    				Settings.getConfiguration().getString("application.context") +
114
    				"/WEB-INF/hazelcast.xml";
115
			// set it for other parts of the code
116
			Settings.getConfiguration().setProperty("dataone.hazelcast.configFilePath", hzConfigFileName);
117 7754 tao
			//set data.hazelcast.location.clientconfig. This property will be used in d1_cn_index_processor module.
118
			//if we don't set this property, d1_cn_index_processor will use the default location /etc/dataone/storage.
119
			Settings.getConfiguration().setProperty("dataone.hazelcast.location.clientconfig", hzConfigFileName);
120 7584 leinfelder
		}
121 7783 tao
    }*/
122 7552 tao
123
    /**
124
     *Actions needed to be done before close the servlet
125
     */
126
    public void destroy() {
127
     //do nothing
128
    }
129
130
    /** Handle "GET" method requests from HTTP clients */
131
    public void doGet(HttpServletRequest request, HttpServletResponse response)
132
    throws ServletException, IOException {
133
        //do nothing
134
135
    }
136
137
    /** Handle "POST" method requests from HTTP clients */
138
    public void doPost(HttpServletRequest request, HttpServletResponse response)
139
    throws ServletException, IOException {
140
        //do nothing
141
142
    }
143
}