*/
package eu.etaxonomy.cdm.remote.controller;
+import java.io.IOException;
+import java.net.URL;
import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.http.protocol.HTTP;
import org.apache.log4j.Logger;
-import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.orm.hibernate3.HibernateTransactionManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
-import com.ibm.wsdl.extensions.http.HTTPConstants;
-
-import eu.etaxonomy.cdm.api.service.search.CdmMassIndexer;
import eu.etaxonomy.cdm.api.service.search.ICdmMassIndexer;
import eu.etaxonomy.cdm.common.monitor.RestServiceProgressMonitor;
import eu.etaxonomy.cdm.database.DataSourceInfo;
import eu.etaxonomy.cdm.database.DataSourceReloader;
+import eu.etaxonomy.cdm.remote.controller.util.ProgressMonitorUtil;
import eu.etaxonomy.cdm.remote.json.JsonpRedirect;
@Controller
public static final Logger logger = Logger.getLogger(ManagementController.class);
// @Autowired
- private DataSourceReloader datasoucrceLoader;
+ private DataSourceReloader datasoucrceLoader;
@Autowired
public ICdmMassIndexer indexer;
@Autowired
public ProgressMonitorController progressMonitorController;
+ /**
+ * There should only be one processes operating on the lucene index
+ * therefore the according progress monitor uuid is stored in
+ * this static field.
+ */
+ private static UUID indexMonitorUuid = null;
+
private static final int DEFAULT_PAGE_SIZE = 25;
/**
*
- * Reindex all cdm entities litest in {@link ICdmMassIndexer#indexedClasses()}.
+ * Reindex all cdm entities listed in {@link ICdmMassIndexer#indexedClasses()}.
* Re-indexing will not purge the index.
- *
+ * @param frontendBaseUrl if the CDM server is running behind a reverse proxy you need
+ * to supply the base URL of web service front-end which is
+ * provided by the proxy server.
* @param request
* @param respone
* @return
* @throws Exception
*/
@RequestMapping(value = { "reindex" }, method = RequestMethod.GET)
- public ModelAndView doReindex(HttpServletRequest request, HttpServletResponse response) throws Exception {
-
- ModelAndView mv = new ModelAndView();
-
- final RestServiceProgressMonitor monitor = new RestServiceProgressMonitor();
- UUID monitorUuid = progressMonitorController.registerMonitor(monitor);
- String monitorPath = progressMonitorController.pathFor(request, monitorUuid);
-
- Thread subThread = new Thread(){
- public void run(){
- indexer.reindex(monitor);
- }
- };
- subThread.start();
-
- // send redirect "see other"
- response.setHeader("Location", monitorPath);
-// response.sendError(303, null);
- boolean isJSONP = request.getParameter("callback") != null;
- if(isJSONP){
- JsonpRedirect jsonpRedirect = new JsonpRedirect(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + monitorPath);
- mv.addObject(jsonpRedirect);
-// response.sendError(303, "{\"redirect\": \""+ monitorPath + "\"}");
- } else {
- response.sendError(303, "Reindexing started, for progress information please see <a href=\"" + monitorPath + "\">" + monitorPath + "</a>");
+ public ModelAndView doReindex(
+ @RequestParam(value = "frontendBaseUrl", required = false) String frontendBaseUrl,
+ HttpServletRequest request, HttpServletResponse response) throws Exception {
+
+
+ String processLabel = "Re-indexing";
+ ProgressMonitorUtil progressUtil = new ProgressMonitorUtil(progressMonitorController);
+
+ if(!progressMonitorController.isMonitorRunning(indexMonitorUuid)) {
+ indexMonitorUuid = progressUtil.registerNewMonitor();
+ Thread subThread = new Thread(){
+ public void run(){
+ indexer.reindex(progressMonitorController.getMonitor(indexMonitorUuid));
+ }
+ };
+ subThread.start();
}
-// mv.addObject(monitorPath);
-// mv.setViewName("text");
- return mv;
+ // send redirect "see other"
+ return progressUtil.respondWithMonitor(frontendBaseUrl, request, response, processLabel, indexMonitorUuid);
}
/**
* @throws Exception
*/
@RequestMapping(value = { "purge" }, method = RequestMethod.GET)
- public ModelAndView doPurge(HttpServletRequest request, HttpServletResponse respone) throws Exception {
-
- ModelAndView mv = new ModelAndView();
-
- indexer.purge(null);
+ public ModelAndView doPurge(
+ @RequestParam(value = "frontendBaseUrl", required = false) String frontendBaseUrl,
+ HttpServletRequest request, HttpServletResponse response) throws Exception {
- mv.addObject("done!");
- mv.setViewName("text");
- return mv;
- }
+ String processLabel = "Purging";
+ ProgressMonitorUtil progressUtil = new ProgressMonitorUtil(progressMonitorController);
+ if(!progressMonitorController.isMonitorRunning(indexMonitorUuid)) {
+ indexMonitorUuid = progressUtil.registerNewMonitor();
+ Thread subThread = new Thread(){
+ public void run(){
+ indexer.purge(progressMonitorController.getMonitor(indexMonitorUuid));
+ }
+ };
+ subThread.start();
+ }
+ // send redirect "see other"
+ return progressUtil.respondWithMonitor(frontendBaseUrl, request, response, processLabel, indexMonitorUuid);
+ }
}