diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/ABoxRecomputer.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/ABoxRecomputer.java index 5a687d379..80713e4a9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/ABoxRecomputer.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/ABoxRecomputer.java @@ -38,6 +38,7 @@ import com.hp.hpl.jena.vocabulary.RDFS; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph; import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames; +import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer; import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; @@ -46,6 +47,8 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; public class ABoxRecomputer { private static final Log log = LogFactory.getLog(ABoxRecomputer.class); + + private final SearchIndexer searchIndexer; private OntModel tboxModel; // asserted and inferred TBox axioms private OntModel aboxModel; @@ -67,11 +70,13 @@ public class ABoxRecomputer { public ABoxRecomputer(OntModel tboxModel, OntModel aboxModel, RDFService rdfService, - SimpleReasoner simpleReasoner) { + SimpleReasoner simpleReasoner, + SearchIndexer searchIndexer) { this.tboxModel = tboxModel; this.aboxModel = aboxModel; this.rdfService = rdfService; this.simpleReasoner = simpleReasoner; + this.searchIndexer = searchIndexer; recomputing = false; stopRequested = false; handleSameAs = simpleReasoner.getSameAsEnabled(); @@ -97,8 +102,14 @@ public class ABoxRecomputer { } } try { + if (searchIndexer != null) { + searchIndexer.pause(); + } recomputeABox(); } finally { + if (searchIndexer != null) { + searchIndexer.unpause(); + } synchronized (lock1) { recomputing = false; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasoner.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasoner.java index 6dc912724..524ab7d7f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasoner.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasoner.java @@ -43,6 +43,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.DifferenceGraph; import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.BulkUpdateEvent; import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames; +import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory; @@ -60,6 +61,8 @@ public class SimpleReasoner extends StatementListener { private static final Log log = LogFactory.getLog(SimpleReasoner.class); + private final SearchIndexer searchIndexer; + private OntModel tboxModel; // asserted and inferred TBox axioms private OntModel aboxModel; // ABox assertions private Model inferenceModel; // ABox inferences @@ -95,12 +98,17 @@ public class SimpleReasoner extends StatementListener { * whole ABox inference model is rebuilt * @param inferenceScratchpadModel - output. This the model is temporarily used when * the whole ABox inference model is rebuilt + * @param searchIndexer - output. If not null, the indexer will be paused before the + * ABox inference model is rebuilt and unpaused when the rebuild is complete. */ public SimpleReasoner(OntModel tboxModel, RDFService rdfService, Model inferenceModel, Model inferenceRebuildModel, - Model scratchpadModel) { + Model scratchpadModel, + SearchIndexer searchIndexer) { + + this.searchIndexer = searchIndexer; this.tboxModel = tboxModel; @@ -117,7 +125,7 @@ public class SimpleReasoner extends StatementListener { this.batchMode = 0; aBoxDeltaModeler1 = new CumulativeDeltaModeler(); aBoxDeltaModeler2 = new CumulativeDeltaModeler(); - recomputer = new ABoxRecomputer(tboxModel, aboxModel, rdfService, this); + recomputer = new ABoxRecomputer(tboxModel, aboxModel, rdfService, this, searchIndexer); stopRequested = false; if (rdfService == null) { @@ -140,6 +148,7 @@ public class SimpleReasoner extends StatementListener { * ABox statements are maintained (added or retracted). */ public SimpleReasoner(OntModel tboxModel, OntModel aboxModel, Model inferenceModel) { + this.searchIndexer = null; this.tboxModel = tboxModel; this.aboxModel = aboxModel; this.inferenceModel = inferenceModel; @@ -155,7 +164,7 @@ public class SimpleReasoner extends StatementListener { ds.addNamedModel(ModelNames.TBOX_ASSERTIONS, tboxModel); ds.setDefaultModel(ModelFactory.createUnion(fullModel, tboxModel)); - recomputer = new ABoxRecomputer(tboxModel, aboxModel, new RDFServiceModel(ds), this); + recomputer = new ABoxRecomputer(tboxModel, aboxModel, new RDFServiceModel(ds), this, searchIndexer); } public void setPluginList(List pluginList) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java index 8ad1730ac..533df0efa 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java @@ -23,8 +23,10 @@ import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.RDFNode; +import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess; import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames; +import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.reasoner.ReasonerPlugin; import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner; @@ -45,6 +47,7 @@ public class SimpleReasonerSetup implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent sce) { ServletContext ctx = sce.getServletContext(); + SearchIndexer searchIndexer = ApplicationUtils.instance().getSearchIndexer(); try { OntModel tboxAssertionsModel = ModelAccess.on(ctx).getOntModel(ModelNames.TBOX_ASSERTIONS); @@ -70,7 +73,7 @@ public class SimpleReasonerSetup implements ServletContextListener { // the simple reasoner will register itself as a listener to the ABox assertions SimpleReasoner simpleReasoner = new SimpleReasoner( - tboxUnionModel, rdfService, inferenceModel, rebuildModel, scratchModel); + tboxUnionModel, rdfService, inferenceModel, rebuildModel, scratchModel, searchIndexer); sce.getServletContext().setAttribute(SimpleReasoner.class.getName(),simpleReasoner); StartupStatus ss = StartupStatus.getBean(ctx); diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerInversePropertyTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerInversePropertyTest.java index 1494dc870..5201f8eca 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerInversePropertyTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerInversePropertyTest.java @@ -7,6 +7,10 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import stubs.edu.cornell.mannlib.vitro.webapp.modules.ApplicationStub; +import stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineStub; +import stubs.javax.servlet.ServletContextStub; + import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.ontology.OntProperty; @@ -29,6 +33,10 @@ public class SimpleReasonerInversePropertyTest extends SimpleReasonerTBoxHelper setLoggerLevel(SimpleReasonerTBoxListener.class, Level.OFF); setLoggerLevel(ABoxRecomputer.class, Level.OFF); } + + @Before public void setup() { + ApplicationStub.setup(new ServletContextStub(), new SearchEngineStub()); + } @Test public void addABoxAssertion1Test(){ diff --git a/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/ApplicationStub.java b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/ApplicationStub.java index 92bd80107..5845b91a8 100644 --- a/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/ApplicationStub.java +++ b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/ApplicationStub.java @@ -6,6 +6,7 @@ import java.lang.reflect.Field; import javax.servlet.ServletContext; +import stubs.edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexerStub; import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.application.VitroHomeDirectory; import edu.cornell.mannlib.vitro.webapp.modules.Application; @@ -42,10 +43,14 @@ public class ApplicationStub implements Application { private final ServletContext ctx; private final SearchEngine searchEngine; + private final SearchIndexer searchIndexer; public ApplicationStub(ServletContext ctx, SearchEngine searchEngine) { this.ctx = ctx; this.searchEngine = searchEngine; + + this.searchIndexer = new SearchIndexerStub(); + this.searchIndexer.unpause(); } // ---------------------------------------------------------------------- @@ -62,6 +67,11 @@ public class ApplicationStub implements Application { return searchEngine; } + @Override + public SearchIndexer getSearchIndexer() { + return searchIndexer; + } + // ---------------------------------------------------------------------- // Un-implemented methods // ---------------------------------------------------------------------- @@ -109,10 +119,4 @@ public class ApplicationStub implements Application { "ApplicationStub.getTBoxReasonerModule() not implemented."); } - @Override - public SearchIndexer getSearchIndexer() { - throw new RuntimeException( - "Application.getSearchIndexer() not implemented."); - } - } diff --git a/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchIndexer/SearchIndexerStub.java b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchIndexer/SearchIndexerStub.java new file mode 100644 index 000000000..e2b8670b6 --- /dev/null +++ b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/modules/searchIndexer/SearchIndexerStub.java @@ -0,0 +1,91 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package stubs.edu.cornell.mannlib.vitro.webapp.modules.searchIndexer; + +import java.util.Collection; +import java.util.List; + +import com.hp.hpl.jena.rdf.model.Statement; + +import edu.cornell.mannlib.vitro.webapp.modules.Application; +import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus; +import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer; +import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexerStatus; + +/** + * TODO + */ +public class SearchIndexerStub implements SearchIndexer { + // ---------------------------------------------------------------------- + // Stub infrastructure + // ---------------------------------------------------------------------- + + private boolean paused = true; + + // ---------------------------------------------------------------------- + // Stub methods + // ---------------------------------------------------------------------- + + @Override + public void pause() { + paused = true; + } + + @Override + public void unpause() { + paused = false; + } + + // ---------------------------------------------------------------------- + // Un-implemented methods + // ---------------------------------------------------------------------- + + @Override + public void startup(Application application, ComponentStartupStatus ss) { + throw new RuntimeException( + "SearchIndexerStub.startup() not implemented."); + } + + @Override + public void scheduleUpdatesForStatements(List changes) { + throw new RuntimeException( + "SearchIndexerStub.scheduleUpdatesForStatements() not implemented."); + } + + @Override + public void scheduleUpdatesForUris(Collection uris) { + throw new RuntimeException( + "SearchIndexerStub.scheduleUpdatesForUris() not implemented."); + } + + @Override + public void rebuildIndex() { + throw new RuntimeException( + "SearchIndexerStub.rebuildIndex() not implemented."); + } + + @Override + public SearchIndexerStatus getStatus() { + throw new RuntimeException( + "SearchIndexerStub.getStatus() not implemented."); + } + + @Override + public void addListener(Listener listener) { + throw new RuntimeException( + "SearchIndexerStub.addListener() not implemented."); + } + + @Override + public void removeListener(Listener listener) { + throw new RuntimeException( + "SearchIndexerStub.removeListener() not implemented."); + } + + @Override + public void shutdown(Application app) { + throw new RuntimeException( + "SearchIndexerStub.shutdown() not implemented."); + } + +}