Project

General

Profile

1
/**
2
 *  Copyright: 2013 Regents of the University of California and the
3
 *             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
import java.io.File;
23
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
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

    
38
import edu.ucsb.nceas.metacat.common.query.EnabledQueryEngines;
39

    
40

    
41
/**
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
    // 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
    //private static final String FILEPREFIX = "file:";
51
    
52
	private static Log log = LogFactory.getLog(MetacatIndexServlet.class);
53

    
54
    /**
55
     * Initialize the servlet 
56
     */
57
    public void init(ServletConfig config) throws ServletException {
58
        //System.out.println("++++++++++++++++++++++++------------------- start the servlet");
59
    	//initializeSharedConfiguration(config);
60
    	// initialize the application using the configured application-context
61
        //URL url = getClass().getResource("/index-processor-context.xml");
62
        //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
        //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
        //ApplicationController controller = null;
70
        try {
71
             //ApplicationController controller = new ApplicationController(FILEPREFIX + url.getFile(), fullMetacatPropertiesFilePath);
72
            ApplicationController controller = new ApplicationController("/index-processor-context.xml", fullMetacatPropertiesFilePath);
73
             //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
        } catch (Exception e) {
77
            throw new ServletException(e.getMessage());
78
        }
79
       
80
        //controller.startIndex();//Start to generate indexes for those haven't been indexed in another thread
81
        //List<SolrIndex> list = controller.getSolrIndexes();
82
        //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
    /*private void initializeSharedConfiguration(ServletConfig config) {
95
    	
96
		try {
97
			// find the sibling metacat.properties file
98
			String metacatPropertiesFilePath = config.getServletContext().getInitParameter("metacat.properties.path");
99
			File contextDeploymentDir = new File(config.getServletContext().getRealPath("/"));
100
			String fullMetacatPropertiesFilePath = contextDeploymentDir.getParent()  + metacatPropertiesFilePath;
101
			Settings.augmentConfiguration(fullMetacatPropertiesFilePath);
102
		} catch (ConfigurationException e) {
103
			log.error("Could not initialize shared Metacat properties. " + e.getMessage(), e);
104
		}
105
		
106
		// make sure hazelcast configuration is defined so that
107
		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
			//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
		}
121
    }*/
122
    
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
}
(4-4/6)