diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/FileGraphSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/FileGraphSetup.java index 3b8265338..8a390b005 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/FileGraphSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/FileGraphSetup.java @@ -45,10 +45,13 @@ public class FileGraphSetup implements ServletContextListener { return; } + boolean aboxChanged = false; // indicates whether any ABox filegraph model has changed + boolean tboxChanged = false; // indicates whether any TBox filegraph model has changed + try { OntModelSelectorImpl baseOms = (OntModelSelectorImpl) sce.getServletContext().getAttribute("baseOntModelSelector"); Store kbStore = (Store) sce.getServletContext().getAttribute("kbStore"); - + // ABox files Set pathSet = sce.getServletContext().getResourcePaths(PATH_ROOT + ABOX); @@ -56,7 +59,7 @@ public class FileGraphSetup implements ServletContextListener { if (pathSet != null) { OntModel aboxBaseModel = baseOms.getABoxModel(); - readGraphs(sce, pathSet, kbStore, ABOX, aboxBaseModel); + aboxChanged = readGraphs(sce, pathSet, kbStore, ABOX, aboxBaseModel); } // TBox files @@ -66,7 +69,7 @@ public class FileGraphSetup implements ServletContextListener { if (pathSet != null) { OntModel tboxBaseModel = baseOms.getTBoxModel(); - readGraphs(sce, pathSet, kbStore, TBOX, tboxBaseModel); + tboxChanged = readGraphs(sce, pathSet, kbStore, TBOX, tboxBaseModel); } } catch (ClassCastException cce) { String errMsg = "Unable to cast servlet context attribute to the appropriate type " + cce.getLocalizedMessage(); @@ -77,6 +80,10 @@ public class FileGraphSetup implements ServletContextListener { log.error(t); t.printStackTrace(); } + + if (aboxChanged | tboxChanged) { + SimpleReasonerSetup.setRecomputeRequired(sce.getServletContext()); + } } /* @@ -88,10 +95,12 @@ public class FileGraphSetup implements ServletContextListener { * Note: no connection needs to be maintained between the in-memory copy of the * graph and the DB copy. */ - public void readGraphs(ServletContextEvent sce, Set pathSet, Store kbStore, String type, OntModel baseModel) { + public boolean readGraphs(ServletContextEvent sce, Set pathSet, Store kbStore, String type, OntModel baseModel) { int count = 0; + boolean modelChanged = false; + // For each file graph in the target directory update or add that graph to // the Jena SDB, and attach the graph as a submodel of the base model for ( String p : pathSet ) { @@ -116,7 +125,7 @@ public class FileGraphSetup implements ServletContextListener { log.info("Attached file graph as " + type + " submodel " + p); } - updateGraphInDB(kbStore, model, type, p); + modelChanged = modelChanged | updateGraphInDB(kbStore, model, type, p); } catch (Exception ioe) { log.error("Unable to process file graph " + p, ioe); @@ -137,7 +146,7 @@ public class FileGraphSetup implements ServletContextListener { System.out.println("Read " + count + " " + type + " file graph" + ((count == 1) ? "" : "s") + " from " + PATH_ROOT + type); - return; + return modelChanged; } /* @@ -150,19 +159,22 @@ public class FileGraphSetup implements ServletContextListener { * Otherwise, if a graph with the given name is in the DB and is isomorphic with * the graph that was read from the files system, then do nothing. */ - public void updateGraphInDB(Store kbStore, Model fileModel, String type, String path) { + public boolean updateGraphInDB(Store kbStore, Model fileModel, String type, String path) { String graphURI = pathToURI(path,type); Model dbModel = SDBFactory.connectNamedModel(kbStore, graphURI); + boolean modelChanged = false; if (dbModel.isEmpty() ) { dbModel.add(fileModel); + modelChanged = true; } else if (!dbModel.isIsomorphicWith(fileModel)) { dbModel.removeAll(); dbModel.add(fileModel); + modelChanged = true; } - return; + return modelChanged; } /*