Removed EntityChangeListener, it was no longer in use. Moved ModelListener registration from JenaDatasourceSetup to LuceneSetup. NIHVIVO-643

This commit is contained in:
bdc34 2010-06-25 15:59:04 +00:00
parent 3527b1c948
commit 2ada3b7c35
6 changed files with 48 additions and 84 deletions

View file

@ -21,14 +21,12 @@ import org.joda.time.DateTime;
import edu.cornell.mannlib.vedit.beans.LoginFormBean; import edu.cornell.mannlib.vedit.beans.LoginFormBean;
import edu.cornell.mannlib.vedit.controller.BaseEditController; import edu.cornell.mannlib.vedit.controller.BaseEditController;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.Property;
import edu.cornell.mannlib.vitro.webapp.beans.PropertyInstance; import edu.cornell.mannlib.vitro.webapp.beans.PropertyInstance;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao; import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.utils.EntityChangeListener;
/** /**
* NOTE:does not work yet under semweb-align - gets tricky here * NOTE:does not work yet under semweb-align - gets tricky here
@ -169,19 +167,6 @@ throws ServletException, IOException {
doPost(request,response); doPost(request,response);
} }
private void addIndividualToLuceneIndex( ServletContext context, String uri ){
try{
Object obj = context.getAttribute(EntityChangeListener.class.getName());
if(obj != null && obj instanceof EntityChangeListener ){
EntityChangeListener listener = (EntityChangeListener) obj;
listener.entityUpdated( uri );
}
}catch(Throwable t){
log.error("GenericDBUpdate.checkForEntityChange() error:" + t);
}
}
/** /**
* Attempts to clone a tab. * Attempts to clone a tab.
* This will check for the parameter 'tabId' and if it exists * This will check for the parameter 'tabId' and if it exists

View file

@ -20,7 +20,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.search.IndexingException; import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface; import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface;
import edu.cornell.mannlib.vitro.webapp.utils.EntityChangeListener;
/** /**
* The IndexBuilder is used to rebuild or update a search index. * The IndexBuilder is used to rebuild or update a search index.
@ -39,7 +38,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.EntityChangeListener;
* @author bdc34 * @author bdc34
* *
*/ */
public class IndexBuilder implements Runnable, EntityChangeListener{ public class IndexBuilder implements Runnable {
List<ObjectSourceIface> sourceList = new LinkedList<ObjectSourceIface>(); List<ObjectSourceIface> sourceList = new LinkedList<ObjectSourceIface>();
IndexerIface indexer = null; IndexerIface indexer = null;
ServletContext context = null; ServletContext context = null;
@ -60,10 +59,6 @@ public class IndexBuilder implements Runnable, EntityChangeListener{
this.context = context; this.context = context;
changedUris = new LinkedList<String>(); changedUris = new LinkedList<String>();
//add this to the context as a EntityChangeListener so that we can
//be notified of entity changes.
context.setAttribute(EntityChangeListener.class.getName(), this);
} }
public void addObjectSource(ObjectSourceIface osi) { public void addObjectSource(ObjectSourceIface osi) {
@ -263,14 +258,6 @@ public class IndexBuilder implements Runnable, EntityChangeListener{
return ; return ;
} }
/* These methods are so that the IndexBuilder may register for entity changes */
public void entityAdded(String entityURI) {
if( log.isDebugEnabled())
log.debug("IndexBuilder.entityAdded() " + entityURI);
addToChangedUris(entityURI);
(new Thread(this)).start();
}
public void entityDeleted(String entityURI) { public void entityDeleted(String entityURI) {
if( log.isDebugEnabled()) if( log.isDebugEnabled())
log.debug("IndexBuilder.entityDeleted() " + entityURI); log.debug("IndexBuilder.entityDeleted() " + entityURI);
@ -282,13 +269,6 @@ public class IndexBuilder implements Runnable, EntityChangeListener{
} }
} }
public void entityUpdated(String entityURI) {
if( log.isDebugEnabled())
log.debug("IndexBuilder.entityUpdate() " + entityURI);
addToChangedUris(entityURI);
(new Thread(this)).start();
}
public synchronized void addToChangedUris(String uri){ public synchronized void addToChangedUris(String uri){
changedUris.add(uri); changedUris.add(uri);
} }

View file

@ -16,12 +16,16 @@ import org.apache.commons.logging.LogFactory;
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BooleanQuery;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Model;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering; import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener;
import edu.cornell.mannlib.vitro.webapp.search.beans.Searcher; import edu.cornell.mannlib.vitro.webapp.search.beans.Searcher;
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
@ -108,6 +112,13 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
// to the servlet context so we can access it later in the webapp. // to the servlet context so we can access it later in the webapp.
context.setAttribute(IndexBuilder.class.getName(),builder); context.setAttribute(IndexBuilder.class.getName(),builder);
//set up listeners so search index builder is notified of changes to model
OntModel baseOntModel = (OntModel)sce.getServletContext().getAttribute("baseOntModel");
OntModel jenaOntModel = (OntModel)sce.getServletContext().getAttribute("jenaOntModel");
SearchReindexingListener srl = new SearchReindexingListener(baseOntModel, sce.getServletContext());
baseOntModel.getBaseModel().register(srl);
jenaOntModel.getBaseModel().register(srl);
log.debug("**** End of "+this.getClass().getName()+".contextInitialized()"); log.debug("**** End of "+this.getClass().getName()+".contextInitialized()");
} catch (Throwable t) { } catch (Throwable t) {
log.error(t); log.error(t);

View file

@ -17,12 +17,15 @@ import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.cjk.CJKAnalyzer; import org.apache.lucene.analysis.cjk.CJKAnalyzer;
import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BooleanQuery;
import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering; import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener;
import edu.cornell.mannlib.vitro.webapp.search.beans.Searcher; import edu.cornell.mannlib.vitro.webapp.search.beans.Searcher;
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
@ -105,6 +108,14 @@ public class LuceneSetupCJK implements javax.servlet.ServletContextListener {
// here we add the IndexBuilder with the LuceneIndexer // here we add the IndexBuilder with the LuceneIndexer
// to the servlet context so we can access it later in the webapp. // to the servlet context so we can access it later in the webapp.
context.setAttribute(IndexBuilder.class.getName(),builder); context.setAttribute(IndexBuilder.class.getName(),builder);
//set up listeners so search index builder is notified of changes to model
OntModel baseOntModel = (OntModel)sce.getServletContext().getAttribute("baseOntModel");
OntModel jenaOntModel = (OntModel)sce.getServletContext().getAttribute("jenaOntModel");
SearchReindexingListener srl = new SearchReindexingListener(baseOntModel, sce.getServletContext());
baseOntModel.getBaseModel().register(srl);
jenaOntModel.getBaseModel().register(srl);
}catch(Exception ex){ }catch(Exception ex){
log.error("Could not setup lucene full text search." , ex); log.error("Could not setup lucene full text search." , ex);
} }

View file

@ -96,10 +96,6 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
ensureEssentialInterfaceData(memModel, sce, wadf); ensureEssentialInterfaceData(memModel, sce, wadf);
SearchReindexingListener srl = new SearchReindexingListener(memModel, sce.getServletContext());
unionModel.getBaseModel().register(srl);
memModel.getBaseModel().register(srl);
NamespaceMapper namespaceMapper = new NamespaceMapperJena(unionModel, unionModel, defaultNamespace); NamespaceMapper namespaceMapper = new NamespaceMapperJena(unionModel, unionModel, defaultNamespace);
sce.getServletContext().setAttribute("NamespaceMapper", namespaceMapper); sce.getServletContext().setAttribute("NamespaceMapper", namespaceMapper);
memModel.getBaseModel().register(namespaceMapper); memModel.getBaseModel().register(namespaceMapper);

View file

@ -1,19 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.utils;
/**
* This interface is to be implemented by classes that want to know
* when entities change. A class that imeplements this will be able
* to register with classes that change entities.
*
* These can be thought of as callbacks.
*
* @author bdc34
*
*/
public interface EntityChangeListener {
public void entityAdded(String entityURI );
public void entityDeleted(String entityURI);
public void entityUpdated(String entityURI);
}