package eu.etaxonomy.cdm.remote.controller;
import java.util.Map;
+import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
-import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
-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.servlet.ModelAndView;
+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.search.CdmMassIndexer;
-import eu.etaxonomy.cdm.search.ICdmMassIndexer;
+import eu.etaxonomy.cdm.remote.json.JsonpRedirect;
@Controller
@RequestMapping(value = {"/manage"})
private DataSourceReloader datasoucrceLoader;
@Autowired
- public ICdmMassIndexer indexer = new CdmMassIndexer();
+ public ICdmMassIndexer indexer;
+
+ @Autowired
+ public ProgressMonitorController progressMonitorController;
private static final int DEFAULT_PAGE_SIZE = 25;
* @throws Exception
*/
@RequestMapping(value = { "reindex" }, method = RequestMethod.GET)
- public ModelAndView doReindex(HttpServletRequest request, HttpServletResponse respone) throws Exception {
+ public ModelAndView doReindex(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView mv = new ModelAndView();
- indexer.reindex();
-
- mv.addObject("done!");
- mv.setViewName("text");
-
+ 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>");
+ }
+// mv.addObject(monitorPath);
+// mv.setViewName("text");
return mv;
}
ModelAndView mv = new ModelAndView();
- indexer.purge();
+ indexer.purge(null);
mv.addObject("done!");
mv.setViewName("text");
+
}