diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/BasicAuthenticator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/BasicAuthenticator.java index 9f01a1c57..ff299596e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/BasicAuthenticator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/authenticate/BasicAuthenticator.java @@ -29,6 +29,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.jena.LoginEvent; import edu.cornell.mannlib.vitro.webapp.dao.jena.LogoutEvent; +import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; /** * The "standard" implementation of Authenticator. @@ -136,8 +137,7 @@ public class BasicAuthenticator extends Authenticator { if (IsRootUser.isRootUser(RequestIdentifiers .getIdBundleForRequest(request))) { - // Insert method call here. - } + IndexBuilder.checkIndexOnRootLogin(request); } } /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/IndexerIface.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/IndexerIface.java index d851e6b3e..24947f021 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/IndexerIface.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/beans/IndexerIface.java @@ -56,4 +56,6 @@ public interface IndexerIface { * This may be called instead of endIndexing() */ public void abortIndexingAndCleanUp(); + + public boolean isIndexEmpty(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java index 03568ee1e..b99fbe564 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/IndexBuilder.java @@ -11,6 +11,8 @@ import java.util.LinkedList; import java.util.List; import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -195,7 +197,20 @@ public class IndexBuilder extends Thread { } - /* ******************** non-public methods ************************* */ + public static void checkIndexOnRootLogin(HttpServletRequest req){ + HttpSession session = req.getSession(); + ServletContext context = session.getServletContext(); + IndexBuilder indexBuilder = (IndexBuilder)context.getAttribute(IndexBuilder.class.getName()); + + log.debug("Checking if the index is empty"); + if(indexBuilder.indexer.isIndexEmpty()){ + log.info("Index is empty. Running a full index rebuild!"); + indexBuilder.doIndexRebuild(); + } + } + + + /* ******************** non-public methods ************************* */ private List getAndEmptyChangedStatements(){ List localChangedStmt = null;