Adding feedback from search IndexController instead of a blank screen, so user knows when indexing is finished. NIHVIVO-783
This commit is contained in:
parent
a85683d99b
commit
e05cc6e041
1 changed files with 91 additions and 49 deletions
|
@ -2,22 +2,23 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.search.controller;
|
package edu.cornell.mannlib.vitro.webapp.search.controller;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.JenaNetidPolicy.ContextSetup;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreeMarkerHttpServlet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
|
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
|
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
|
||||||
|
import freemarker.template.Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accepts requests to rebuild or update the search index. It uses
|
* Accepts requests to rebuild or update the search index. It uses
|
||||||
|
@ -32,41 +33,82 @@ import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
|
||||||
* @author bdc34
|
* @author bdc34
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class IndexController extends HttpServlet {
|
public class IndexController extends FreeMarkerHttpServlet {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(IndexController.class.getName());
|
private static final Log log = LogFactory.getLog(IndexController.class.getName());
|
||||||
|
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
// public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException,IOException {
|
// throws ServletException,IOException {
|
||||||
doGet(request, response);
|
// doGet(request, response);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void doGet( HttpServletRequest request, HttpServletResponse response )
|
// public void doGet( HttpServletRequest request, HttpServletResponse response )
|
||||||
throws IOException, ServletException {
|
// throws IOException, ServletException {
|
||||||
|
//
|
||||||
Object obj = request.getSession().getAttribute("loginHandler");
|
// Object obj = request.getSession().getAttribute("loginHandler");
|
||||||
LoginFormBean loginHandler = null;
|
// LoginFormBean loginHandler = null;
|
||||||
if( obj != null && obj instanceof LoginFormBean )
|
// if( obj != null && obj instanceof LoginFormBean )
|
||||||
loginHandler = ((LoginFormBean)obj);
|
// loginHandler = ((LoginFormBean)obj);
|
||||||
if( loginHandler == null ||
|
// if( loginHandler == null ||
|
||||||
! "authenticated".equalsIgnoreCase(loginHandler.getLoginStatus()) ||
|
// ! "authenticated".equalsIgnoreCase(loginHandler.getLoginStatus()) ||
|
||||||
Integer.parseInt(loginHandler.getLoginRole()) <= 5 ){
|
// Integer.parseInt(loginHandler.getLoginRole()) <= 5 ){
|
||||||
|
//
|
||||||
String redirectURL=request.getContextPath() + Controllers.SITE_ADMIN + "?login=block";
|
// String redirectURL=request.getContextPath() + Controllers.SITE_ADMIN + "?login=block";
|
||||||
response.sendRedirect(redirectURL);
|
// response.sendRedirect(redirectURL);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
try {
|
// long start = System.currentTimeMillis();
|
||||||
IndexBuilder builder = (IndexBuilder)getServletContext().getAttribute(IndexBuilder.class.getName());
|
// try {
|
||||||
if( request.getParameter("update") != null ){
|
// IndexBuilder builder = (IndexBuilder)getServletContext().getAttribute(IndexBuilder.class.getName());
|
||||||
builder.doUpdateIndex();
|
// if( request.getParameter("update") != null ){
|
||||||
}else{
|
// builder.doUpdateIndex();
|
||||||
builder.doIndexRebuild();
|
// }else{
|
||||||
}
|
// builder.doIndexRebuild();
|
||||||
|
// }
|
||||||
} catch (IndexingException e) {
|
//
|
||||||
log.error("IndexController -- Error building index: " + e);
|
// } catch (IndexingException e) {
|
||||||
}
|
// log.error("IndexController -- Error building index: " + e);
|
||||||
|
// }
|
||||||
|
// long delta = System.currentTimeMillis() - start;
|
||||||
|
// String msg = "Search index complete. Elapsed time " + delta + " msec.";
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
protected String getTitle(String siteName) {
|
||||||
|
return "Full Search Index Rebuild";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getBody(VitroRequest request, Map<String, Object> body, Configuration config) {
|
||||||
|
|
||||||
|
Object obj = request.getSession().getAttribute("loginHandler");
|
||||||
|
LoginFormBean loginHandler = null;
|
||||||
|
if( obj != null && obj instanceof LoginFormBean )
|
||||||
|
loginHandler = ((LoginFormBean)obj);
|
||||||
|
if( loginHandler == null ||
|
||||||
|
! "authenticated".equalsIgnoreCase(loginHandler.getLoginStatus()) ||
|
||||||
|
Integer.parseInt(loginHandler.getLoginRole()) <= 5 ){
|
||||||
|
|
||||||
|
body.put("message","You must login to rebuild the search index.");
|
||||||
|
return mergeBodyToTemplate("message.ftl", body, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
IndexBuilder builder = (IndexBuilder)getServletContext().getAttribute(IndexBuilder.class.getName());
|
||||||
|
if( request.getParameter("update") != null ){
|
||||||
|
builder.doUpdateIndex();
|
||||||
|
}else{
|
||||||
|
builder.doIndexRebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IndexingException e) {
|
||||||
|
log.error("Error rebuilding search index",e);
|
||||||
|
body.put("errorMessage", "There was an error while rebuilding the search index. " + e.getMessage());
|
||||||
|
return mergeBodyToTemplate("errorMessage.ftl", body, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
body.put("message","Search index complete. Elapsed time " + (System.currentTimeMillis() - start) + " msec.");
|
||||||
|
return mergeBodyToTemplate("message.ftl", body, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue