From 4f3664b9059213d740ccd35c0a5ef37481607a5b Mon Sep 17 00:00:00 2001 From: bjl23 Date: Thu, 22 Jul 2010 21:28:28 +0000 Subject: [PATCH] some merges back to the trunk that I forgot to commit earlier --- .../vitro/webapp/beans/PropertyInstance.java | 16 +++++++- .../PropertyWebappsListingController.java | 21 +++++++++- .../freemarker/BrowseController.java | 6 ++- .../webapp/dao/jena/DataPropertyDaoJena.java | 7 ++++ .../dao/jena/ObjectPropertyDaoJena.java | 1 + .../vitro/webapp/dao/jena/VClassDaoJena.java | 10 +++-- .../dao/jena/pellet/PelletListener.java | 4 ++ .../edit/n3editing/SelectListGenerator.java | 26 ++++++++++++- .../webapp/ontology/update/TBoxUpdater.java | 39 ++++++++++--------- .../servlet/setup/UpdateKnowledgeBase.java | 1 - 10 files changed, 102 insertions(+), 29 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/PropertyInstance.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/PropertyInstance.java index a80471947..73b78eb56 100755 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/PropertyInstance.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/PropertyInstance.java @@ -9,7 +9,7 @@ import java.util.Date; from the entities, object property statements, properties, and ent2relationships tables bundled up in a usable object. */ -public class PropertyInstance implements PropertyInstanceIface { +public class PropertyInstance implements PropertyInstanceIface, Comparable { private String propertyURI = null; private String objectEntURI = null; @@ -198,5 +198,19 @@ public class PropertyInstance implements PropertyInstanceIface { out = getDomainClassName() + "("+ getDomainClassURI() + ")"; } return out; + } + + public int compareTo(PropertyInstance pi) { + + try { + if (this.getDomainPublic().equals(pi.getDomainPublic())) { + return this.getRangeClassName().compareTo(pi.getRangeClassName()); + } else { + return (this.getDomainPublic().compareTo(pi.getDomainPublic())); + } + } catch (NullPointerException npe) { + return -1; + } + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/PropertyWebappsListingController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/PropertyWebappsListingController.java index 6d613b3d9..69dc4c7f1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/PropertyWebappsListingController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/PropertyWebappsListingController.java @@ -12,6 +12,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import javax.servlet.RequestDispatcher; import javax.servlet.http.HttpServletRequest; @@ -64,10 +65,28 @@ public class PropertyWebappsListingController extends BaseEditController { VClassDao vcDao = vrequest.getFullWebappDaoFactory().getVClassDao(); PropertyGroupDao pgDao = vrequest.getFullWebappDaoFactory().getPropertyGroupDao(); + String vclassURI = request.getParameter("vclassUri"); + List props = new ArrayList(); if (request.getParameter("propsForClass") != null) { noResultsMsgStr = "There are no properties that apply to this class."; - Collection propInsts = piDao.getAllPropInstByVClass(request.getParameter("vclassUri")); + + // incomplete list of classes to check, but better than before + List superclassURIs = vcDao.getAllSuperClassURIs(vclassURI); + superclassURIs.add(vclassURI); + superclassURIs.addAll(vcDao.getEquivalentClassURIs(vclassURI)); + + Map propInstMap = new HashMap(); + for (String classURI : superclassURIs) { + Collection propInsts = piDao.getAllPropInstByVClass(classURI); + for (PropertyInstance propInst : propInsts) { + propInstMap.put(propInst.getPropertyURI(), propInst); + } + } + List propInsts = new ArrayList(); + propInsts.addAll(propInstMap.values()); + Collections.sort(propInsts); + Iterator propInstIt = propInsts.iterator(); HashSet propURIs = new HashSet(); while (propInstIt.hasNext()) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java index fd2e03e49..2814d245b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java @@ -117,12 +117,14 @@ public class BrowseController extends FreeMarkerHttpServlet { // Get all classgroups, each populated with a list of their member vclasses List groups = vcgDao.getPublicGroupsWithVClasses(ORDER_BY_DISPLAYRANK, !INCLUDE_UNINSTANTIATED); + // remove classes that have been configured to be hidden + // from search results + removeClassesHiddenFromSearch(groups); + // now cull out the groups with no populated classes //removeUnpopulatedClasses( groups); vcgDao.removeUnpopulatedGroups(groups); - removeClassesHiddenFromSearch(groups); - _groupListMap.put(portalId, groups); return groups; } else { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyDaoJena.java index 2c75b8221..b58b0b68b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyDaoJena.java @@ -45,6 +45,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.InsertException; 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; public class DataPropertyDaoJena extends PropertyDaoJena implements @@ -96,6 +97,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements // TODO check if used as onProperty of restriction ontModel.enterCriticalSection(Lock.WRITE); try { + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); DatatypeProperty dp = ontModel.getDatatypeProperty(URI); if (dp != null) { Iterator restIt = ontModel.listSubjectsWithProperty(OWL.onProperty, dp); @@ -109,6 +111,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements removeRulesMentioningResource(dp, ontModel); dp.remove(); } + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); } finally { ontModel.leaveCriticalSection(); } @@ -509,6 +512,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements public String insertDataProperty(DataProperty dtp, OntModel ontModel) throws InsertException { ontModel.enterCriticalSection(Lock.WRITE); try { + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); String errMsgStr = getWebappDaoFactory().checkURI(dtp.getURI()); if (errMsgStr != null) { throw new InsertException(errMsgStr); @@ -565,6 +569,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements log.error("error linking data property "+dtp.getURI()+" to property group"); } addPropertyStringValue(jDataprop,PROPERTY_CUSTOMENTRYFORMANNOT,dtp.getCustomEntryForm(),ontModel); + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); } finally { ontModel.leaveCriticalSection(); } @@ -578,6 +583,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements public void updateDataProperty(DataProperty dtp, OntModel ontModel) { ontModel.enterCriticalSection(Lock.WRITE); try { + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); com.hp.hpl.jena.ontology.DatatypeProperty jDataprop = ontModel.getDatatypeProperty(dtp.getURI()); updateRDFSLabel(jDataprop, dtp.getPublicName()); @@ -614,6 +620,7 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements } updatePropertyStringValue(jDataprop,PROPERTY_CUSTOMENTRYFORMANNOT,dtp.getCustomEntryForm(),ontModel); + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); } finally { ontModel.leaveCriticalSection(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java index 107250d90..27977c767 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java @@ -379,6 +379,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp doUpdate(prop,p,inv,ontModel); return 0; } finally { + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); ontModel.leaveCriticalSection(); } } 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 b196f4c64..087bd5103 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 @@ -268,6 +268,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { getOntModel().enterCriticalSection(Lock.READ); try { OntClass ontClass = getOntClass(getOntModel(), classURI); + System.out.println(classURI); ClosableIterator equivalentOntClassIt = ontClass.listEquivalentClasses(); try { for (Iterator eqOntClassIt = equivalentOntClassIt; eqOntClassIt.hasNext(); ) { @@ -394,7 +395,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { //if ("true".equalsIgnoreCase(infersTypes)) { PelletListener pl = getWebappDaoFactory().getPelletListener(); - if (pl != null && pl.isConsistent() && !pl.isInErrorState()) { + if (pl != null && pl.isConsistent() && !pl.isInErrorState() && !pl.isReasoning()) { superclassURIs = new ArrayList(); OntClass cls = getOntClass(getOntModel(),classURI); StmtIterator superClassIt = getOntModel().listStatements(cls,RDFS.subClassOf,(RDFNode)null); @@ -740,7 +741,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { String isInferencing = getWebappDaoFactory().getProperties().get("infersTypes"); // if this model infers types based on the taxonomy, adding the subclasses will only // waste time for no benefit - if (isInferencing == null || "false".equalsIgnoreCase(isInferencing)) { + PelletListener pl = getWebappDaoFactory().getPelletListener(); + if (pl == null || !pl.isConsistent() || pl.isInErrorState() || pl.isReasoning() + || isInferencing == null || "false".equalsIgnoreCase(isInferencing)) { Iterator classURIs = getAllSubClassURIs(getClassURIStr(superclass)).iterator(); while (classURIs.hasNext()) { String classURI = (String) classURIs.next(); @@ -748,8 +751,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { if (vClass != null) vClasses.add(vClass); } - } else { - } + } } } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/pellet/PelletListener.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/pellet/PelletListener.java index 040a6513e..ddc95eb23 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/pellet/PelletListener.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/pellet/PelletListener.java @@ -80,6 +80,10 @@ public class PelletListener implements ModelChangedListener { return this.inErrorState; } + public boolean isReasoning() { + return this.isReasoning; + } + public void closePipe() { pipeOpen = false; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SelectListGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SelectListGenerator.java index 876cef4af..6ccda58d0 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SelectListGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SelectListGenerator.java @@ -30,6 +30,9 @@ import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; +import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; +import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener; +import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener; @@ -241,7 +244,28 @@ public class SelectListGenerator { log.error("Cannot find owl:Class " + vclassUri + " in the model" ); optionsMap.put("", "Could not find class " + vclassUri); }else{ - List individuals = wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(),-1,-1); + Map individualMap = new HashMap(); + + for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(),-1,-1)) { + if (ind.getURI() != null) { + individualMap.put(ind.getURI(), ind); + } + } + + if (!inferenceAvailable) { + for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) { + for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI,-1,-1)) { + if (ind.getURI() != null) { + individualMap.put(ind.getURI(), ind); + } + } + } + } + + List individuals = new ArrayList(); + individuals.addAll(individualMap.values()); + Collections.sort(individuals); + Map individualMap = new HashMap(); for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(),-1,-1)) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/TBoxUpdater.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/TBoxUpdater.java index 988170763..ce2f1d125 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/TBoxUpdater.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/TBoxUpdater.java @@ -162,28 +162,29 @@ public class TBoxUpdater { if (!newObject.equals(oldObject)) { NodeIterator siteObjects = siteModel.listObjectsOfProperty(subject,predicate); - - if (siteObjects == null || !siteObjects.hasNext()) { - continue; - } - RDFNode siteObject = siteObjects.next(); - - i = 1; - while (siteObjects.hasNext()) { - i++; - siteObjects.next(); - } - - if (i > 1) { - logger.log("WARNING: found " + i + - " statements with subject = " + subject.getURI() + - " and property = " + predicate.getURI() + - " in the site annotations model. (maximum of one is expected). "); - continue; + RDFNode siteObject = null; + + if (siteObjects != null && siteObjects.hasNext()) { + + siteObject = siteObjects.next(); + + i = 1; + while (siteObjects.hasNext()) { + i++; + siteObjects.next(); + } + + if (i > 1) { + logger.log("WARNING: found " + i + + " statements with subject = " + subject.getURI() + + " and property = " + predicate.getURI() + + " in the site annotations model. (maximum of one is expected). "); + continue; + } } - if (siteObject.equals(oldObject)) { + if (siteObject == null || siteObject.equals(oldObject)) { try { StmtIterator it = siteModel.listStatements(subject, predicate, (RDFNode)null); while (it.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 0366d5573..d15552e10 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 @@ -104,7 +104,6 @@ public class UpdateKnowledgeBase implements ServletContextListener { if (ontologyUpdater.updateRequired()) { ctx.setAttribute(LuceneSetup.INDEX_REBUILD_REQUESTED_AT_STARTUP, Boolean.TRUE); doMiscAppMetadataReplacements(ctx.getRealPath(MISC_REPLACEMENTS_FILE), oms); - System.out.println(ctx.getRealPath(MISC_REPLACEMENTS_FILE)); } } catch (Throwable t){ log.error("Unable to perform miscellaneous application metadata replacements", t);