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

    
25
import javax.servlet.ServletConfig;
26
import javax.servlet.ServletException;
27
import javax.servlet.http.HttpServlet;
28
import javax.servlet.http.HttpServletRequest;
29
import javax.servlet.http.HttpServletResponse;
30

    
31
import org.apache.commons.logging.Log;
32
import org.apache.commons.logging.LogFactory;
33

    
34

    
35
/**
36
 * A servlet class for the Metadata Index module. This class only does one thing - initialize the ApplicationController class.
37
 * @author tao
38
 *
39
 */
40
public class MetacatIndexServlet extends HttpServlet {
41
    
42
    // Use the file prefix to indicate this is a absolute path.
43
    // see http://www.docjar.com/docs/api/org/springframework/context/support/FileSystemXmlApplicationContext.html
44
    //private static final String FILEPREFIX = "file:";
45
    
46
	private static Log log = LogFactory.getLog(MetacatIndexServlet.class);
47

    
48
    /**
49
     * Initialize the servlet 
50
     */
51
    public void init(ServletConfig config) throws ServletException {
52
        //System.out.println("++++++++++++++++++++++++------------------- start the servlet");
53
    	//initializeSharedConfiguration(config);
54
    	// initialize the application using the configured application-context
55
        //URL url = getClass().getResource("/index-processor-context.xml");
56
        //find the sibling metacat.properties file
57
        String metacatPropertiesFilePath = config.getServletContext().getInitParameter("metacat.properties.path");
58
        File contextDeploymentDir = new File(config.getServletContext().getRealPath("/"));
59
        String fullMetacatPropertiesFilePath = contextDeploymentDir.getParent()  + metacatPropertiesFilePath;
60
        //System.out.println("the url is "+url);
61
        //System.out.println("the path is "+url.getPath());
62
        //System.out.println("the file is "+url.getPath());
63
        //ApplicationController controller = null;
64
        try {
65
             //ApplicationController controller = new ApplicationController(FILEPREFIX + url.getFile(), fullMetacatPropertiesFilePath);
66
            ApplicationController controller = new ApplicationController("/index-processor-context.xml", fullMetacatPropertiesFilePath);
67
             //Start the controller in other thread - SystemmetadataEventListener and to generate indexes for those haven't been indexed in another thread
68
             Thread controllerThread = new Thread(controller);
69
             controllerThread.start();
70
        } catch (Exception e) {
71
            throw new ServletException(e.getMessage());
72
        }
73
       
74
        //controller.startIndex();//Start to generate indexes for those haven't been indexed in another thread
75
        //List<SolrIndex> list = controller.getSolrIndexes();
76
        //System.out.println("++++++++++++++++++++++++------------------- the size is  "+list.size());
77
    }
78
    
79
    /**
80
     * Loads the metacat.prioerties into D1 Settings utility
81
     * this gives us access to all metacat properties as well as 
82
     * overriding any properties as needed.
83
     * 
84
     * Makes sure shared Hazelcast configuration file location is set
85
     * 
86
     * @param config the servlet config
87
     */
88
    /*private void initializeSharedConfiguration(ServletConfig config) {
89
    	
90
		try {
91
			// find the sibling metacat.properties file
92
			String metacatPropertiesFilePath = config.getServletContext().getInitParameter("metacat.properties.path");
93
			File contextDeploymentDir = new File(config.getServletContext().getRealPath("/"));
94
			String fullMetacatPropertiesFilePath = contextDeploymentDir.getParent()  + metacatPropertiesFilePath;
95
			Settings.augmentConfiguration(fullMetacatPropertiesFilePath);
96
		} catch (ConfigurationException e) {
97
			log.error("Could not initialize shared Metacat properties. " + e.getMessage(), e);
98
		}
99
		
100
		// make sure hazelcast configuration is defined so that
101
		String hzConfigFileName = Settings.getConfiguration().getString("dataone.hazelcast.configFilePath");
102
		if (hzConfigFileName == null) {
103
			// use default metacat hazelcast.xml file in metacat deployment
104
			hzConfigFileName = 
105
    				Settings.getConfiguration().getString("application.deployDir") +
106
    				"/" +
107
    				Settings.getConfiguration().getString("application.context") + 
108
    				"/WEB-INF/hazelcast.xml";
109
			// set it for other parts of the code
110
			Settings.getConfiguration().setProperty("dataone.hazelcast.configFilePath", hzConfigFileName);
111
			//set data.hazelcast.location.clientconfig. This property will be used in d1_cn_index_processor module.
112
			//if we don't set this property, d1_cn_index_processor will use the default location /etc/dataone/storage.
113
			Settings.getConfiguration().setProperty("dataone.hazelcast.location.clientconfig", hzConfigFileName);
114
		}
115
    }*/
116
    
117
    /**
118
     *Actions needed to be done before close the servlet
119
     */
120
    public void destroy() {
121
     //do nothing
122
    }
123
    
124
    /** Handle "GET" method requests from HTTP clients */
125
    public void doGet(HttpServletRequest request, HttpServletResponse response)
126
    throws ServletException, IOException {
127
        //do nothing
128
      
129
    }
130
    
131
    /** Handle "POST" method requests from HTTP clients */
132
    public void doPost(HttpServletRequest request, HttpServletResponse response)
133
    throws ServletException, IOException {
134
        //do nothing
135
      
136
    }
137
}
(4-4/6)