diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoJena.java index 1d168eb63..67dc61ea4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoJena.java @@ -2,7 +2,6 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena; -import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -61,7 +60,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent; -import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener; +import edu.cornell.mannlib.vitro.webapp.web.URLEncoder; public class VClassDaoJena extends JenaBaseDao implements VClassDao { @@ -148,8 +147,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { labelStr += getLabelForClass(ccls.getOperand(),withPrefix,forPickList); } else if (cls.isIntersectionClass()) { IntersectionClass icls = cls.as(IntersectionClass.class); - for (Iterator operandIt = icls.listOperands(); operandIt.hasNext();) { - OntClass operand = (OntClass) operandIt.next(); + for (Iterator operandIt = + icls.listOperands(); operandIt.hasNext();) { + OntClass operand = operandIt.next(); labelStr += getLabelForClass(operand,withPrefix,forPickList); if (operandIt.hasNext()) { labelStr += " and "; @@ -157,8 +157,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { } } else if (cls.isUnionClass()) { UnionClass icls = cls.as(UnionClass.class); - for (Iterator operandIt = icls.listOperands(); operandIt.hasNext();) { - OntClass operand = (OntClass) operandIt.next(); + for (Iterator operandIt = + icls.listOperands(); operandIt.hasNext();) { + OntClass operand = operandIt.next(); labelStr += getLabelForClass(operand,withPrefix,forPickList); if (operandIt.hasNext()) { labelStr += " or "; @@ -170,7 +171,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { // BJL23 2009-02-19 // I'm putting the link markup in because I need it, // but obviously we need to factor this out into the display layer. - return "[anonymous class]"; + return "[anonymous class]"; } } else { if (withPrefix || forPickList) { @@ -244,8 +247,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { List uriList = new ArrayList(); getOntModel().enterCriticalSection(Lock.READ); try { - for (Iterator i = ontClass.listDisjointWith(); i.hasNext(); ) { - OntClass disjointClass = (OntClass) i.next(); + for (Iterator i = + ontClass.listDisjointWith(); i.hasNext(); ) { + OntClass disjointClass = i.next(); uriList.add(getClassURIStr(disjointClass)); } } catch (ProfileException pe) { @@ -288,10 +292,11 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { getOntModel().enterCriticalSection(Lock.READ); try { OntClass ontClass = getOntClass(getOntModel(), classURI); - ClosableIterator equivalentOntClassIt = ontClass.listEquivalentClasses(); + ClosableIterator equivalentOntClassIt = ontClass.listEquivalentClasses(); try { - for (Iterator eqOntClassIt = equivalentOntClassIt; eqOntClassIt.hasNext(); ) { - OntClass eqClass = (OntClass) eqOntClassIt.next(); + for (Iterator eqOntClassIt = + equivalentOntClassIt; eqOntClassIt.hasNext(); ) { + OntClass eqClass = eqOntClassIt.next(); equivalentClassURIs.add(getClassURIStr(eqClass)); } } finally { @@ -482,10 +487,6 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { return classes; } - private Iterator smarterListHierarchyRootClasses(OntModel ontModel) { - return smarterListHierarchyRootClasses(ontModel, null); - } - /** * The basic idea here is that we ignore anonymous superclasses for the purpose * of determining whether something is a root class. @@ -569,16 +570,21 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { OntModel ontModel = getOntModel(); ontModel.enterCriticalSection(Lock.READ); try { - Iterator ontClassIt = ontModel.listClasses(); + Iterator ontClassIt = ontModel.listResourcesWithProperty( + RDF.type, OWL.Class); while (ontClassIt.hasNext()) { - OntClass ontClass = ontClassIt.next(); + Resource ontClass = ontClassIt.next(); if (ontologyURI.equals(ontClass.getNameSpace())) { boolean root = true; - StmtIterator superStmtIt = ontModel.listStatements(ontClass, RDFS.subClassOf, (RDFNode) null); + StmtIterator superStmtIt = ontModel.listStatements( + ontClass, RDFS.subClassOf, (RDFNode) null); try { while (superStmtIt.hasNext()) { Statement superStmt = superStmtIt.nextStatement(); - if ( superStmt.getObject().isResource() && ontologyURI.equals(((Resource) superStmt.getObject()).getNameSpace()) ) { + if ( superStmt.getObject().isResource() + && ontologyURI.equals( + ((Resource) superStmt.getObject()) + .getNameSpace()) ) { root = false; break; } @@ -586,8 +592,10 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { } finally { superStmtIt.close(); } - if (root) { - ontologyRootClasses.add(new VClassJena(ontClass,getWebappDaoFactory())); + if (root && ontClass.canAs(OntClass.class)) { + ontologyRootClasses.add(new VClassJena( + (OntClass) ontClass.as(OntClass.class), + getWebappDaoFactory())); } } } @@ -598,12 +606,12 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { } public List getSubClassURIs(String classURI) { - List subURIs = new ArrayList(); + List subURIs = new ArrayList(); OntClass superClass = getOntClass(getOntModel(),classURI); try { - Iterator subIt = superClass.listSubClasses(true); + Iterator subIt = superClass.listSubClasses(true); while (subIt.hasNext()) { - OntClass cls = (OntClass) subIt.next(); + OntClass cls = subIt.next(); subURIs.add(getClassURIStr(cls)); } } catch (Exception e) { @@ -617,10 +625,10 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { } public List getSuperClassURIs(String classURI, boolean direct) { - List supURIs = new ArrayList(); + List supURIs = new ArrayList(); OntClass subClass = getOntClass(getOntModel(), classURI); try { - Iterator supIt = subClass.listSuperClasses(direct); + Iterator supIt = subClass.listSuperClasses(direct); while (supIt.hasNext()) { OntClass cls = (OntClass) supIt.next(); supURIs.add(getClassURIStr(cls)); @@ -717,12 +725,16 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { OntResource superclass = null; if (vclassURI != null) { // TODO need a getAllSuperPropertyURIs method in ObjectPropertyDao - List superproperties = getWebappDaoFactory().getObjectPropertyDao().getSuperPropertyURIs(propertyURI,false); + List superproperties = getWebappDaoFactory() + .getObjectPropertyDao() + .getSuperPropertyURIs(propertyURI, false); superproperties.add(propertyURI); - HashSet subjSuperclasses = new HashSet(getAllSuperClassURIs(vclassURI)); + HashSet subjSuperclasses = new HashSet( + getAllSuperClassURIs(vclassURI)); subjSuperclasses.add(vclassURI); for (String objectPropertyURI : superproperties) { - for (Iterator restStmtIt = getOntModel().listStatements(null,OWL.onProperty,getOntModel().getProperty(objectPropertyURI)); restStmtIt.hasNext();) { + for (Iterator restStmtIt = getOntModel().listStatements( + null,OWL.onProperty,getOntModel().getProperty(objectPropertyURI)); restStmtIt.hasNext();) { Statement restStmt = (Statement) restStmtIt.next(); Resource restRes = restStmt.getSubject(); for (Iterator axStmtIt = getOntModel().listStatements(null,null,restRes); axStmtIt.hasNext();) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java index d02bbeceb..d68ca6433 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java @@ -138,24 +138,26 @@ public class UpdateKnowledgeBase implements ServletContextListener { KnowledgeBaseUpdater ontologyUpdater = new KnowledgeBaseUpdater(settings); boolean requiredUpdate = ontologyUpdater.updateRequired(ctx); - try { - ctx.setAttribute(KBM_REQURIED_AT_STARTUP, Boolean.TRUE); - log.info("Data migration required"); - migrationChangesMade = ontologyUpdater.update(ctx); - if (tryMigrateDisplay) { - try { - migrateDisplayModel(settings); - log.info("Migrated display model"); - } catch (Exception e) { - log.warn("unable to successfully update display model: " + e.getMessage()); - } - } - // reload the display model since the TBoxUpdater may have - // modified it - new ApplicationModelSetup().contextInitialized(sce); - } catch (Exception ioe) { - ss.fatal(this, "Exception updating knowledge base for ontology changes: ", ioe); - } + if(!JenaDataSourceSetupBase.isFirstStartup()) { + try { + ctx.setAttribute(KBM_REQURIED_AT_STARTUP, Boolean.TRUE); + log.info("Data migration required"); + migrationChangesMade = ontologyUpdater.update(ctx); + if (tryMigrateDisplay) { + try { + migrateDisplayModel(settings); + log.info("Migrated display model"); + } catch (Exception e) { + log.warn("unable to successfully update display model: " + e.getMessage()); + } + } + // reload the display model since the TBoxUpdater may have + // modified it + new ApplicationModelSetup().contextInitialized(sce); + } catch (Exception ioe) { + ss.fatal(this, "Exception updating knowledge base for ontology changes: ", ioe); + } + } SimpleReasoner simpleReasoner = (SimpleReasoner) sce.getServletContext() .getAttribute(SimpleReasoner.class.getName());