From 94717a37054f517285ad637e52a1409367e54795 Mon Sep 17 00:00:00 2001 From: brianjlowe Date: Thu, 22 Mar 2012 20:00:06 +0000 Subject: [PATCH] NIHVIVO-3532 get rid of Classes2ClassesDao --- .../Classes2ClassesOperationController.java | 8 +- .../edit/Classes2ClassesRetryController.java | 4 +- .../edit/VclassRetryController.java | 2 +- .../vitro/webapp/dao/Classes2ClassesDao.java | 13 - .../mannlib/vitro/webapp/dao/VClassDao.java | 7 +- .../vitro/webapp/dao/WebappDaoFactory.java | 6 - .../dao/filtering/VClassDaoFiltering.java | 9 + .../filtering/WebappDaoFactoryFiltering.java | 5 - .../dao/jena/Classes2ClassesDaoJena.java | 69 - .../vitro/webapp/dao/jena/VClassDaoJena.java | 1444 +++++++++-------- .../webapp/dao/jena/WebappDaoFactoryJena.java | 8 - .../webapp/dao/WebappDaoFactoryStub.java | 7 - 12 files changed, 765 insertions(+), 817 deletions(-) delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/dao/Classes2ClassesDao.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/Classes2ClassesDaoJena.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Classes2ClassesOperationController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Classes2ClassesOperationController.java index 7829d9765..292524c72 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Classes2ClassesOperationController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Classes2ClassesOperationController.java @@ -16,7 +16,6 @@ import edu.cornell.mannlib.vedit.controller.BaseEditController; import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.beans.Classes2Classes; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.dao.Classes2ClassesDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; public class Classes2ClassesOperationController extends BaseEditController { @@ -58,7 +57,6 @@ public class Classes2ClassesOperationController extends BaseEditController { return; } - Classes2ClassesDao dao = request.getFullWebappDaoFactory().getClasses2ClassesDao(); VClassDao vcDao = request.getFullWebappDaoFactory().getVClassDao(); String modeStr = request.getParameter("opMode"); @@ -81,7 +79,7 @@ public class Classes2ClassesOperationController extends BaseEditController { Classes2Classes c2c = new Classes2Classes(); c2c.setSubclassURI(subclassURIstrs[i]); c2c.setSuperclassURI(superclassURIstr); - dao.deleteClasses2Classes(c2c); + vcDao.deleteClasses2Classes(c2c); } } } @@ -98,7 +96,7 @@ public class Classes2ClassesOperationController extends BaseEditController { Classes2Classes c2c = new Classes2Classes(); c2c.setSuperclassURI(superclassURIstrs[i]); c2c.setSubclassURI(subclassURIstr); - dao.deleteClasses2Classes(c2c); + vcDao.deleteClasses2Classes(c2c); } } } @@ -112,7 +110,7 @@ public class Classes2ClassesOperationController extends BaseEditController { Classes2Classes c2c = new Classes2Classes(); c2c.setSuperclassURI(request.getParameter("SuperclassURI")); c2c.setSubclassURI(request.getParameter("SubclassURI")); - dao.insertNewClasses2Classes(c2c); + vcDao.insertNewClasses2Classes(c2c); } } } catch (Exception e) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Classes2ClassesRetryController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Classes2ClassesRetryController.java index 011d8d757..298cda38f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Classes2ClassesRetryController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Classes2ClassesRetryController.java @@ -19,7 +19,6 @@ import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.beans.Classes2Classes; import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.dao.Classes2ClassesDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; public class Classes2ClassesRetryController extends BaseEditController { @@ -44,9 +43,8 @@ public class Classes2ClassesRetryController extends BaseEditController { action = epo.getAction(); } - Classes2ClassesDao c2cDao = request.getFullWebappDaoFactory().getClasses2ClassesDao(); VClassDao vcDao = request.getFullWebappDaoFactory().getVClassDao(); - epo.setDataAccessObject(c2cDao); + epo.setDataAccessObject(vcDao); Classes2Classes objectForEditing = new Classes2Classes(); String superclassURIstr = request.getParameter("SuperclassURI"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/VclassRetryController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/VclassRetryController.java index 57da63de7..7cb320d77 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/VclassRetryController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/VclassRetryController.java @@ -197,7 +197,7 @@ public class VclassRetryController extends BaseEditController { Classes2Classes c2c = new Classes2Classes(); c2c.setSubclassURI(((VClass)newObj).getURI()); c2c.setSuperclassURI(superclassURI); - daoFactory.getClasses2ClassesDao().insertNewClasses2Classes(c2c); + daoFactory.getVClassDao().insertNewClasses2Classes(c2c); } public void doUpdated(Object oldObj, Object newObj, EditProcessObject epo) { // nothing to do diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/Classes2ClassesDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/Classes2ClassesDao.java deleted file mode 100644 index 61f4e607e..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/Classes2ClassesDao.java +++ /dev/null @@ -1,13 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.dao; - -import edu.cornell.mannlib.vitro.webapp.beans.Classes2Classes; - -public interface Classes2ClassesDao { - - public abstract void deleteClasses2Classes(Classes2Classes c2c); - - public abstract void insertNewClasses2Classes(Classes2Classes c2c); - -} \ No newline at end of file diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VClassDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VClassDao.java index e3f696491..6d6e269ab 100755 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VClassDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VClassDao.java @@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.dao; import java.util.List; +import edu.cornell.mannlib.vitro.webapp.beans.Classes2Classes; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; @@ -65,7 +66,11 @@ public interface VClassDao { List getVClassesForProperty(String vclassURI, String propertyURI); - void addVClassesToGroup(VClassGroup group); + void addVClassesToGroup(VClassGroup group); + + void insertNewClasses2Classes(Classes2Classes c2c); + + void deleteClasses2Classes(Classes2Classes c2c); @SuppressWarnings("unchecked") void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses);/* (non-Javadoc) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactory.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactory.java index a31fdf2f3..05eccbccf 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactory.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactory.java @@ -3,7 +3,6 @@ package edu.cornell.mannlib.vitro.webapp.dao; import java.util.List; -import java.util.Map; import java.util.Set; public interface WebappDaoFactory { @@ -60,11 +59,6 @@ public interface WebappDaoFactory { /* =============== DAOs for ontology (TBox) manipulation =============== */ - /** - * returns a Data Access Object for working with class subsumption axioms - */ - public Classes2ClassesDao getClasses2ClassesDao(); - /** * returns a Data Access Object for working with DataProperties */ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/VClassDaoFiltering.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/VClassDaoFiltering.java index e11ccddf8..fd1a87c65 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/VClassDaoFiltering.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/VClassDaoFiltering.java @@ -11,6 +11,7 @@ import java.util.List; import net.sf.jga.algorithms.Filter; import net.sf.jga.fn.UnaryFunctor; import net.sf.jga.fn.property.GetProperty; +import edu.cornell.mannlib.vitro.webapp.beans.Classes2Classes; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; @@ -240,6 +241,14 @@ public class VClassDaoFiltering extends BaseFiltering implements VClassDao{ return innerVClassDao.getBottomConcept(); } + public void insertNewClasses2Classes(Classes2Classes c2c) { + innerVClassDao.insertNewClasses2Classes(c2c); + } + + public void deleteClasses2Classes(Classes2Classes c2c) { + innerVClassDao.deleteClasses2Classes(c2c); + } + public boolean isSubClassOf(VClass vc1, VClass vc2) { return innerVClassDao.isSubClassOf(vc1, vc2); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/WebappDaoFactoryFiltering.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/WebappDaoFactoryFiltering.java index 58e9b833d..7ebe23b0d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/WebappDaoFactoryFiltering.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/WebappDaoFactoryFiltering.java @@ -7,7 +7,6 @@ import java.util.Map; import java.util.Set; import edu.cornell.mannlib.vitro.webapp.dao.ApplicationDao; -import edu.cornell.mannlib.vitro.webapp.dao.Classes2ClassesDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao; @@ -164,10 +163,6 @@ public class WebappDaoFactoryFiltering implements WebappDaoFactory { /* ******************* non-filtering DAOs *************************** */ - public Classes2ClassesDao getClasses2ClassesDao() { - return innerWebappDaoFactory.getClasses2ClassesDao(); - } - public DatatypeDao getDatatypeDao() { return innerWebappDaoFactory.getDatatypeDao(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/Classes2ClassesDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/Classes2ClassesDaoJena.java deleted file mode 100644 index fd503f05f..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/Classes2ClassesDaoJena.java +++ /dev/null @@ -1,69 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.dao.jena; - -import com.hp.hpl.jena.ontology.OntModel; -import com.hp.hpl.jena.ontology.OntResource; -import com.hp.hpl.jena.rdf.model.Resource; -import com.hp.hpl.jena.shared.Lock; -import com.hp.hpl.jena.vocabulary.RDFS; - -import edu.cornell.mannlib.vitro.webapp.beans.Classes2Classes; -import edu.cornell.mannlib.vitro.webapp.dao.Classes2ClassesDao; -import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent; - -/** - * - */ -public class Classes2ClassesDaoJena extends JenaBaseDao implements Classes2ClassesDao { - - public Classes2ClassesDaoJena(WebappDaoFactoryJena wadf) { - super(wadf); - } - - public void deleteClasses2Classes( Classes2Classes c2c ) { - deleteClasses2Classes(c2c, getOntModelSelector().getTBoxModel()); - } - - public void deleteClasses2Classes( Classes2Classes c2c, OntModel ontModel ) - { - ontModel.enterCriticalSection(Lock.WRITE); - ontModel.getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); - try { - OntResource subclass = getOntClass(ontModel,c2c.getSubclassURI()); - OntResource superclass = getOntClass(ontModel,c2c.getSuperclassURI()); - if ((subclass != null) && (superclass != null)) { - ontModel.removeAll(subclass, RDFS.subClassOf, superclass); - } - if (subclass.isAnon()) { - smartRemove(subclass, getOntModel()); - } - if (superclass.isAnon()) { - smartRemove(superclass, getOntModel()); - } - } finally { - ontModel.getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); - ontModel.leaveCriticalSection(); - } - } - - public void insertNewClasses2Classes( Classes2Classes c2c ) { - insertNewClasses2Classes(c2c, getOntModelSelector().getTBoxModel()); - } - - public void insertNewClasses2Classes( Classes2Classes c2c, OntModel ontModel ) - { - ontModel.enterCriticalSection(Lock.WRITE); - ontModel.getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); - try { - Resource subclass = ontModel.getResource(c2c.getSubclassURI()); - Resource superclass = ontModel.getResource(c2c.getSuperclassURI()); - if ((subclass != null) && (superclass != null)) { - ontModel.add(subclass, RDFS.subClassOf, superclass); - } - } finally { - ontModel.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 e43c4b28f..e33d777c1 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 @@ -61,110 +61,110 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent; import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener; public class VClassDaoJena extends JenaBaseDao implements VClassDao { - + protected static final Log log = LogFactory.getLog(VClassDaoJena.class); - + public VClassDaoJena(WebappDaoFactoryJena wadf) { super(wadf); } - + @Override protected OntModel getOntModel() { - return getOntModelSelector().getTBoxModel(); + return getOntModelSelector().getTBoxModel(); } - + /* ************************************************** */ - + public String getLabelForClass(OntClass cls,boolean withPrefix,boolean forPickList) { - cls.getModel().enterCriticalSection(Lock.READ); - try { - if (cls.isAnon()) { - if (cls.isRestriction()) { - Restriction rest = cls.asRestriction(); - OntProperty onProperty = rest.getOnProperty(); - String labelStr = "restriction on " + getLabelOrId(onProperty) + ": "; - if (rest.isAllValuesFromRestriction() || rest.isSomeValuesFromRestriction()) { - Resource fillerRes = null; - if (rest.isAllValuesFromRestriction()) { - AllValuesFromRestriction avfRest = rest.asAllValuesFromRestriction(); - fillerRes = avfRest.getAllValuesFrom(); - labelStr += "all values from "; - } else { - SomeValuesFromRestriction svfRest = rest.asSomeValuesFromRestriction(); - fillerRes = svfRest.getSomeValuesFrom(); - labelStr += "some values from "; - } - if (fillerRes.canAs(OntClass.class)) { - OntClass avf = (OntClass) fillerRes.as(OntClass.class); - labelStr += getLabelForClass(avf,withPrefix,forPickList); - } else { - try { - labelStr += getLabelOrId( (OntResource) fillerRes.as(OntResource.class)); - } catch (Exception e) { - labelStr += "???"; - } - } - } else if (rest.isHasValueRestriction()) { - HasValueRestriction hvRest = rest.asHasValueRestriction(); - labelStr += "has value "; - RDFNode fillerNode = hvRest.getHasValue(); - try { - if (fillerNode.isResource()) { - labelStr += getLabelOrId((OntResource)fillerNode.as(OntResource.class)); - } else { - labelStr += ((Literal) fillerNode.as(Literal.class)).getLexicalForm(); - } - } catch (Exception e) { - labelStr += "???"; - } - } else if (rest.isMinCardinalityRestriction()) { - MinCardinalityRestriction mcRest = rest.asMinCardinalityRestriction(); - labelStr += "minimum cardinality "; - labelStr += mcRest.getMinCardinality(); - } else if (rest.isMaxCardinalityRestriction()) { - MaxCardinalityRestriction mcRest = rest.asMaxCardinalityRestriction(); - labelStr += "maximum cardinality "; - labelStr += mcRest.getMaxCardinality(); - } else if (rest.isCardinalityRestriction()) { - CardinalityRestriction cRest = rest.asCardinalityRestriction(); - labelStr += "cardinality "; - labelStr += cRest.getCardinality(); - } - return labelStr; - } else if (isBooleanClassExpression(cls)) { - String labelStr = "("; - if (cls.isComplementClass()) { - labelStr += "not "; - ComplementClass ccls = (ComplementClass) cls.as(ComplementClass.class); - labelStr += getLabelForClass(ccls.getOperand(),withPrefix,forPickList); - } else if (cls.isIntersectionClass()) { - IntersectionClass icls = (IntersectionClass) cls.as(IntersectionClass.class); - for (Iterator operandIt = icls.listOperands(); operandIt.hasNext();) { - OntClass operand = (OntClass) operandIt.next(); - labelStr += getLabelForClass(operand,withPrefix,forPickList); - if (operandIt.hasNext()) { - labelStr += " and "; - } - } - } else if (cls.isUnionClass()) { - UnionClass icls = (UnionClass) cls.as(UnionClass.class); - for (Iterator operandIt = icls.listOperands(); operandIt.hasNext();) { - OntClass operand = (OntClass) operandIt.next(); - labelStr += getLabelForClass(operand,withPrefix,forPickList); - if (operandIt.hasNext()) { - labelStr += " or "; - } - } - } - return labelStr+")"; - } else { - // 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]"; - } - } else { - if (withPrefix || forPickList) { + cls.getModel().enterCriticalSection(Lock.READ); + try { + if (cls.isAnon()) { + if (cls.isRestriction()) { + Restriction rest = cls.asRestriction(); + OntProperty onProperty = rest.getOnProperty(); + String labelStr = "restriction on " + getLabelOrId(onProperty) + ": "; + if (rest.isAllValuesFromRestriction() || rest.isSomeValuesFromRestriction()) { + Resource fillerRes = null; + if (rest.isAllValuesFromRestriction()) { + AllValuesFromRestriction avfRest = rest.asAllValuesFromRestriction(); + fillerRes = avfRest.getAllValuesFrom(); + labelStr += "all values from "; + } else { + SomeValuesFromRestriction svfRest = rest.asSomeValuesFromRestriction(); + fillerRes = svfRest.getSomeValuesFrom(); + labelStr += "some values from "; + } + if (fillerRes.canAs(OntClass.class)) { + OntClass avf = (OntClass) fillerRes.as(OntClass.class); + labelStr += getLabelForClass(avf,withPrefix,forPickList); + } else { + try { + labelStr += getLabelOrId( (OntResource) fillerRes.as(OntResource.class)); + } catch (Exception e) { + labelStr += "???"; + } + } + } else if (rest.isHasValueRestriction()) { + HasValueRestriction hvRest = rest.asHasValueRestriction(); + labelStr += "has value "; + RDFNode fillerNode = hvRest.getHasValue(); + try { + if (fillerNode.isResource()) { + labelStr += getLabelOrId((OntResource)fillerNode.as(OntResource.class)); + } else { + labelStr += ((Literal) fillerNode.as(Literal.class)).getLexicalForm(); + } + } catch (Exception e) { + labelStr += "???"; + } + } else if (rest.isMinCardinalityRestriction()) { + MinCardinalityRestriction mcRest = rest.asMinCardinalityRestriction(); + labelStr += "minimum cardinality "; + labelStr += mcRest.getMinCardinality(); + } else if (rest.isMaxCardinalityRestriction()) { + MaxCardinalityRestriction mcRest = rest.asMaxCardinalityRestriction(); + labelStr += "maximum cardinality "; + labelStr += mcRest.getMaxCardinality(); + } else if (rest.isCardinalityRestriction()) { + CardinalityRestriction cRest = rest.asCardinalityRestriction(); + labelStr += "cardinality "; + labelStr += cRest.getCardinality(); + } + return labelStr; + } else if (isBooleanClassExpression(cls)) { + String labelStr = "("; + if (cls.isComplementClass()) { + labelStr += "not "; + ComplementClass ccls = (ComplementClass) cls.as(ComplementClass.class); + labelStr += getLabelForClass(ccls.getOperand(),withPrefix,forPickList); + } else if (cls.isIntersectionClass()) { + IntersectionClass icls = (IntersectionClass) cls.as(IntersectionClass.class); + for (Iterator operandIt = icls.listOperands(); operandIt.hasNext();) { + OntClass operand = (OntClass) operandIt.next(); + labelStr += getLabelForClass(operand,withPrefix,forPickList); + if (operandIt.hasNext()) { + labelStr += " and "; + } + } + } else if (cls.isUnionClass()) { + UnionClass icls = (UnionClass) cls.as(UnionClass.class); + for (Iterator operandIt = icls.listOperands(); operandIt.hasNext();) { + OntClass operand = (OntClass) operandIt.next(); + labelStr += getLabelForClass(operand,withPrefix,forPickList); + if (operandIt.hasNext()) { + labelStr += " or "; + } + } + } + return labelStr+")"; + } else { + // 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]"; + } + } else { + if (withPrefix || forPickList) { OntologyDao oDao=getWebappDaoFactory().getOntologyDao(); Ontology o = (Ontology)oDao.getOntologyByURI(cls.getNameSpace()); if (o!=null) { @@ -174,56 +174,56 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { return(getLabelOrId(cls)+(o.getPrefix()==null?(o.getName()==null?" (unspec)":" ("+o.getName()+")"):" ("+o.getPrefix()+")")); } } else { - return getLabelOrId(cls); + return getLabelOrId(cls); } - } - return getLabelOrId(cls); - } - } catch (Exception e) { - return "???"; - } finally { - cls.getModel().leaveCriticalSection(); - } + } + return getLabelOrId(cls); + } + } catch (Exception e) { + return "???"; + } finally { + cls.getModel().leaveCriticalSection(); + } } public void deleteVClass(VClass cls) { - deleteVClass(cls,getOntModel()); + deleteVClass(cls,getOntModel()); } public void deleteVClass(String URI) { - deleteVClass(URI,getOntModel()); + deleteVClass(URI,getOntModel()); } public void deleteVClass(String URI, OntModel ontModel) { - ontModel.enterCriticalSection(Lock.WRITE); - getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); - try { - OntClass cls = getOntClass(ontModel,URI); - if (cls != null) { - //Remove restriction class. - Iterator restIt = ontModel.listSubjectsWithProperty(OWL.allValuesFrom, cls); - while(restIt.hasNext()) { - Resource restRes = restIt.next(); - if (restRes.canAs(OntResource.class)) { - OntResource restOntRes = (OntResource) restRes.as(OntResource.class); - smartRemove(restOntRes, ontModel); - } - } - restIt = ontModel.listSubjectsWithProperty(OWL.someValuesFrom, cls); - while(restIt.hasNext()) { - Resource restRes = restIt.next(); - if (restRes.canAs(OntResource.class)) { - OntResource restOntRes = (OntResource) restRes.as(OntResource.class); - smartRemove(restOntRes, ontModel); - } - } - removeRulesMentioningResource(cls, ontModel); - smartRemove(cls, ontModel); - } - } finally { - getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); - ontModel.leaveCriticalSection(); - } + ontModel.enterCriticalSection(Lock.WRITE); + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); + try { + OntClass cls = getOntClass(ontModel,URI); + if (cls != null) { + //Remove restriction class. + Iterator restIt = ontModel.listSubjectsWithProperty(OWL.allValuesFrom, cls); + while(restIt.hasNext()) { + Resource restRes = restIt.next(); + if (restRes.canAs(OntResource.class)) { + OntResource restOntRes = (OntResource) restRes.as(OntResource.class); + smartRemove(restOntRes, ontModel); + } + } + restIt = ontModel.listSubjectsWithProperty(OWL.someValuesFrom, cls); + while(restIt.hasNext()) { + Resource restRes = restIt.next(); + if (restRes.canAs(OntResource.class)) { + OntResource restOntRes = (OntResource) restRes.as(OntResource.class); + smartRemove(restOntRes, ontModel); + } + } + removeRulesMentioningResource(cls, ontModel); + smartRemove(cls, ontModel); + } + } finally { + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); + ontModel.leaveCriticalSection(); + } } public void deleteVClass(VClass cls, OntModel ontModel) { @@ -231,218 +231,218 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { } public List getDisjointWithClassURIs(String classURI) { - OntClass ontClass = getOntClass(getOntModel(), classURI); - List uriList = new ArrayList(); - getOntModel().enterCriticalSection(Lock.READ); - try { - for (Iterator i = ontClass.listDisjointWith(); i.hasNext(); ) { - OntClass disjointClass = (OntClass) i.next(); - uriList.add(getClassURIStr(disjointClass)); - } - } catch (ProfileException pe) { - // Current language profile does not support disjointWith axioms. - // We'd prefer to return an empty list instead of throwing an exception. - } finally { - getOntModel().leaveCriticalSection(); - } - return uriList; + OntClass ontClass = getOntClass(getOntModel(), classURI); + List uriList = new ArrayList(); + getOntModel().enterCriticalSection(Lock.READ); + try { + for (Iterator i = ontClass.listDisjointWith(); i.hasNext(); ) { + OntClass disjointClass = (OntClass) i.next(); + uriList.add(getClassURIStr(disjointClass)); + } + } catch (ProfileException pe) { + // Current language profile does not support disjointWith axioms. + // We'd prefer to return an empty list instead of throwing an exception. + } finally { + getOntModel().leaveCriticalSection(); + } + return uriList; } - + public void addDisjointWithClass(String classURI, String disjointClassURI) { - getOntModel().enterCriticalSection(Lock.WRITE); - getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); - try { - OntClass ontClass = getOntClass(getOntModel(),classURI); - OntClass disjointClass = getOntClass(getOntModel(),disjointClassURI); - ontClass.addDisjointWith(disjointClass); - } finally { - getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); - getOntModel().leaveCriticalSection(); - } + getOntModel().enterCriticalSection(Lock.WRITE); + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); + try { + OntClass ontClass = getOntClass(getOntModel(),classURI); + OntClass disjointClass = getOntClass(getOntModel(),disjointClassURI); + ontClass.addDisjointWith(disjointClass); + } finally { + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); + getOntModel().leaveCriticalSection(); + } } - + public void removeDisjointWithClass(String classURI, String disjointClassURI) { - getOntModel().enterCriticalSection(Lock.WRITE); - getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); - try { - OntClass ontClass = getOntClass(getOntModel(),classURI); - OntClass disjointClass = getOntClass(getOntModel(),disjointClassURI); - ontClass.removeDisjointWith(disjointClass); - } finally { - getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); - getOntModel().leaveCriticalSection(); - } + getOntModel().enterCriticalSection(Lock.WRITE); + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); + try { + OntClass ontClass = getOntClass(getOntModel(),classURI); + OntClass disjointClass = getOntClass(getOntModel(),disjointClassURI); + ontClass.removeDisjointWith(disjointClass); + } finally { + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); + getOntModel().leaveCriticalSection(); + } } - + public List getEquivalentClassURIs(String classURI) { - List equivalentClassURIs = new ArrayList(); - getOntModel().enterCriticalSection(Lock.READ); - try { - OntClass ontClass = getOntClass(getOntModel(), classURI); - ClosableIterator equivalentOntClassIt = ontClass.listEquivalentClasses(); - try { - for (Iterator eqOntClassIt = equivalentOntClassIt; eqOntClassIt.hasNext(); ) { - OntClass eqClass = (OntClass) eqOntClassIt.next(); - equivalentClassURIs.add(getClassURIStr(eqClass)); - } - } finally { - equivalentOntClassIt.close(); - } - } catch (ProfileException pe) { - // Current language profile does not support equivalent classes. - // We'd prefer to return an empty list instead of throwing an exception - } catch (Exception e) { + List equivalentClassURIs = new ArrayList(); + getOntModel().enterCriticalSection(Lock.READ); + try { + OntClass ontClass = getOntClass(getOntModel(), classURI); + ClosableIterator equivalentOntClassIt = ontClass.listEquivalentClasses(); + try { + for (Iterator eqOntClassIt = equivalentOntClassIt; eqOntClassIt.hasNext(); ) { + OntClass eqClass = (OntClass) eqOntClassIt.next(); + equivalentClassURIs.add(getClassURIStr(eqClass)); + } + } finally { + equivalentOntClassIt.close(); + } + } catch (ProfileException pe) { + // Current language profile does not support equivalent classes. + // We'd prefer to return an empty list instead of throwing an exception + } catch (Exception e) { // we'll try this again using a different method that - // doesn't try to convert to OntClass + // doesn't try to convert to OntClass List supList = this.listDirectObjectPropertyValues( getOntModel().getResource(classURI), OWL.equivalentClass); for (Resource res : supList) { equivalentClassURIs.add(getClassURIStr(res)); } - } finally { - getOntModel().leaveCriticalSection(); - } - return equivalentClassURIs; + } finally { + getOntModel().leaveCriticalSection(); + } + return equivalentClassURIs; } - + public void addSuperclass(VClass vclass, VClass superclass) { - addSuperclass(vclass.getURI(),superclass.getURI()); + addSuperclass(vclass.getURI(),superclass.getURI()); } - + public void addSuperclass(String vclassURI, String superclassURI) { - Classes2Classes c2c = new Classes2Classes(); - c2c.setSubclassURI(vclassURI); - c2c.setSuperclassURI(superclassURI); - getWebappDaoFactory().getClasses2ClassesDao().insertNewClasses2Classes(c2c); + Classes2Classes c2c = new Classes2Classes(); + c2c.setSubclassURI(vclassURI); + c2c.setSuperclassURI(superclassURI); + insertNewClasses2Classes(c2c); } - + public void removeSuperclass(VClass vclass, VClass superclass) { - removeSuperclass(vclass.getURI(),superclass.getURI()); + removeSuperclass(vclass.getURI(),superclass.getURI()); } - + public void removeSuperclass(String vclassURI, String superclassURI) { - Classes2Classes c2c = new Classes2Classes(); - c2c.setSubclassURI(vclassURI); - c2c.setSuperclassURI(superclassURI); - getWebappDaoFactory().getClasses2ClassesDao().deleteClasses2Classes(c2c); + Classes2Classes c2c = new Classes2Classes(); + c2c.setSubclassURI(vclassURI); + c2c.setSuperclassURI(superclassURI); + deleteClasses2Classes(c2c); } - + public void addSubclass(VClass vclass, VClass subclass) { - addSubclass(vclass.getURI(),subclass.getURI()); + addSubclass(vclass.getURI(),subclass.getURI()); } - + public void addSubclass(String vclassURI, String subclassURI) { - Classes2Classes c2c = new Classes2Classes(); - c2c.setSubclassURI(subclassURI); - c2c.setSuperclassURI(vclassURI); - getWebappDaoFactory().getClasses2ClassesDao().insertNewClasses2Classes(c2c); + Classes2Classes c2c = new Classes2Classes(); + c2c.setSubclassURI(subclassURI); + c2c.setSuperclassURI(vclassURI); + insertNewClasses2Classes(c2c); } - + public void removeSubclass(VClass vclass, VClass subclass) { - removeSubclass(vclass.getURI(),subclass.getURI()); + removeSubclass(vclass.getURI(),subclass.getURI()); } - + public void removeSubclass(String vclassURI, String subclassURI) { - Classes2Classes c2c = new Classes2Classes(); - c2c.setSubclassURI(subclassURI); - c2c.setSuperclassURI(vclassURI); - getWebappDaoFactory().getClasses2ClassesDao().deleteClasses2Classes(c2c); + Classes2Classes c2c = new Classes2Classes(); + c2c.setSubclassURI(subclassURI); + c2c.setSuperclassURI(vclassURI); + deleteClasses2Classes(c2c); } - + public void addEquivalentClass(String classURI, String equivalentClassURI) { - getOntModel().enterCriticalSection(Lock.WRITE); - getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); - try { - OntClass ontClass = getOntClass(getOntModel(),classURI); - OntClass eqClass = getOntClass(getOntModel(),equivalentClassURI); - ontClass.addEquivalentClass(eqClass); - eqClass.addEquivalentClass(ontClass); - } finally { - getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); - getOntModel().leaveCriticalSection(); - } + getOntModel().enterCriticalSection(Lock.WRITE); + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); + try { + OntClass ontClass = getOntClass(getOntModel(),classURI); + OntClass eqClass = getOntClass(getOntModel(),equivalentClassURI); + ontClass.addEquivalentClass(eqClass); + eqClass.addEquivalentClass(ontClass); + } finally { + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); + getOntModel().leaveCriticalSection(); + } } - + public void removeEquivalentClass(String classURI, String equivalentClassURI) { - getOntModel().enterCriticalSection(Lock.WRITE); - getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); - try { - OntClass ontClass = getOntClass(getOntModel(),classURI); - OntClass eqClass = getOntClass(getOntModel(),equivalentClassURI); - ontClass.removeEquivalentClass(eqClass); - eqClass.removeEquivalentClass(ontClass); - if (ontClass.isAnon()) { - smartRemove(ontClass, getOntModel()); - } - if (eqClass.isAnon()) { - smartRemove(eqClass, getOntModel()); - } - } finally { - getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); - getOntModel().leaveCriticalSection(); - } + getOntModel().enterCriticalSection(Lock.WRITE); + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); + try { + OntClass ontClass = getOntClass(getOntModel(),classURI); + OntClass eqClass = getOntClass(getOntModel(),equivalentClassURI); + ontClass.removeEquivalentClass(eqClass); + eqClass.removeEquivalentClass(ontClass); + if (ontClass.isAnon()) { + smartRemove(ontClass, getOntModel()); + } + if (eqClass.isAnon()) { + smartRemove(eqClass, getOntModel()); + } + } finally { + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); + getOntModel().leaveCriticalSection(); + } } - + public List getAllSubClassURIs(String classURI) { - HashSet nodeSet = new HashSet(); - nodeSet.add(classURI); - getAllSubClassURIs(classURI, nodeSet); - nodeSet.remove(classURI); - List outputList = new ArrayList(); - outputList.addAll(nodeSet); - return outputList; + HashSet nodeSet = new HashSet(); + nodeSet.add(classURI); + getAllSubClassURIs(classURI, nodeSet); + nodeSet.remove(classURI); + List outputList = new ArrayList(); + outputList.addAll(nodeSet); + return outputList; } - + public void getAllSubClassURIs(String classURI, HashSet subtree){ List directSubclasses = getSubClassURIs(classURI); Iterator it=directSubclasses.iterator(); while(it.hasNext()){ String uri = (String)it.next(); if (!subtree.contains(uri)) { - subtree.add(uri); - getAllSubClassURIs(uri,subtree); + subtree.add(uri); + getAllSubClassURIs(uri,subtree); } } } public List getAllSuperClassURIs(String classURI) { - - List superclassURIs = null; - - //String infersTypes = getWebappDaoFactory().getProperties().get("infersTypes"); - //if ("true".equalsIgnoreCase(infersTypes)) { - - PelletListener pl = getWebappDaoFactory().getPelletListener(); - 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); - while (superClassIt.hasNext()) { - Statement stmt = superClassIt.nextStatement(); - if (stmt.getObject().canAs(OntResource.class)) { - OntResource superRes = (OntResource) stmt.getObject().as(OntResource.class); - String test = getClassURIStr(superRes); - superclassURIs.add(test); - } - } - return superclassURIs; - } else { - HashSet nodeSet = new HashSet(); - nodeSet.add(classURI); - getAllSuperClassURIs(classURI, nodeSet); - //nodeSet.remove(classURI); - return new ArrayList(nodeSet); - } + + List superclassURIs = null; + + //String infersTypes = getWebappDaoFactory().getProperties().get("infersTypes"); + //if ("true".equalsIgnoreCase(infersTypes)) { + + PelletListener pl = getWebappDaoFactory().getPelletListener(); + 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); + while (superClassIt.hasNext()) { + Statement stmt = superClassIt.nextStatement(); + if (stmt.getObject().canAs(OntResource.class)) { + OntResource superRes = (OntResource) stmt.getObject().as(OntResource.class); + String test = getClassURIStr(superRes); + superclassURIs.add(test); + } + } + return superclassURIs; + } else { + HashSet nodeSet = new HashSet(); + nodeSet.add(classURI); + getAllSuperClassURIs(classURI, nodeSet); + //nodeSet.remove(classURI); + return new ArrayList(nodeSet); + } } - + public void getAllSuperClassURIs(String classURI, HashSet subtree){ List directSuperclasses = getSuperClassURIs(classURI, true); Iterator it=directSuperclasses.iterator(); while(it.hasNext()){ String uri = (String)it.next(); if (!subtree.contains(uri)) { - subtree.add(uri); - getAllSuperClassURIs(uri,subtree); + subtree.add(uri); + getAllSuperClassURIs(uri,subtree); } } } @@ -473,72 +473,72 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { Collections.sort(classes); return classes; } - + private Iterator smarterListHierarchyRootClasses(OntModel ontModel) { - return smarterListHierarchyRootClasses(ontModel, null); + 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. * We also avoid ClassCastExceptions deep in Jena-land by eschewing Jena's * listSuperClasses() method. * @author bjl23 - */ + */ private Iterator smarterListHierarchyRootClasses(OntModel ontModel, String ontologyURI) { - List rootClassList = new ArrayList(); - ClosableIterator ci = ontModel.listIndividuals(OWL.Class); - try { - for (ClosableIterator i = ci ; i.hasNext(); ) { - try { - Individual classInd = i.next(); -// if (!classInd.canAs(OntClass.class)) { -// continue; -// } - OntClass ontClass = (OntClass) classInd.as(OntClass.class); - boolean isRoot = true; - for (Iterator j = ontClass.listPropertyValues(RDFS.subClassOf); j.hasNext(); ) { - Resource res = (Resource) j.next(); - if (res.canAs(OntClass.class)) { - OntClass superClass = (OntClass) res.as(OntClass.class); - if (!superClass.isAnon() && - ((ontologyURI==null) || (ontologyURI.equals(superClass.getNameSpace()))) && - !OWL.Thing.equals(superClass) && - !superClass.equals(ontClass) && - !( ontModel.contains(ontClass,OWL.equivalentClass,superClass) || - ontModel.contains(superClass,OWL.equivalentClass,ontClass) ) ) { - if ( (superClass.getNameSpace() != null) - && (!(NONUSER_NAMESPACES.contains( - superClass.getNameSpace()))) ) { - isRoot=false; - break; - } - } - } - } - if (isRoot) { - rootClassList.add(ontClass); - } - } catch (ClassCastException cce) { - log.error(cce, cce); - } - } - } finally { - ci.close(); - } - return rootClassList.iterator(); + List rootClassList = new ArrayList(); + ClosableIterator ci = ontModel.listIndividuals(OWL.Class); + try { + for (ClosableIterator i = ci ; i.hasNext(); ) { + try { + Individual classInd = i.next(); + // if (!classInd.canAs(OntClass.class)) { + // continue; + // } + OntClass ontClass = (OntClass) classInd.as(OntClass.class); + boolean isRoot = true; + for (Iterator j = ontClass.listPropertyValues(RDFS.subClassOf); j.hasNext(); ) { + Resource res = (Resource) j.next(); + if (res.canAs(OntClass.class)) { + OntClass superClass = (OntClass) res.as(OntClass.class); + if (!superClass.isAnon() && + ((ontologyURI==null) || (ontologyURI.equals(superClass.getNameSpace()))) && + !OWL.Thing.equals(superClass) && + !superClass.equals(ontClass) && + !( ontModel.contains(ontClass,OWL.equivalentClass,superClass) || + ontModel.contains(superClass,OWL.equivalentClass,ontClass) ) ) { + if ( (superClass.getNameSpace() != null) + && (!(NONUSER_NAMESPACES.contains( + superClass.getNameSpace()))) ) { + isRoot=false; + break; + } + } + } + } + if (isRoot) { + rootClassList.add(ontClass); + } + } catch (ClassCastException cce) { + log.error(cce, cce); + } + } + } finally { + ci.close(); + } + return rootClassList.iterator(); } public List getRootClasses() { - return getRootClasses(null); + return getRootClasses(null); } - + private List getRootClasses(String ontologyURI) { List rootClasses = new ArrayList(); getOntModel().enterCriticalSection(Lock.READ); try { - Iterator rootIt = smarterListHierarchyRootClasses( - getOntModel(), ontologyURI); + Iterator rootIt = smarterListHierarchyRootClasses( + getOntModel(), ontologyURI); while (rootIt.hasNext()) { OntClass cls = rootIt.next(); if (!cls.isAnon() && cls.getNameSpace() != null @@ -555,40 +555,40 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { public List getOntologyRootClasses(String ontologyURI) { - if (ontologyURI == null) { - throw new RuntimeException("can't find root classes for null ontology URI"); - } - // return getRootClasses(ontologyURI); - List ontologyRootClasses = new ArrayList(); - OntModel ontModel = getOntModel(); - ontModel.enterCriticalSection(Lock.READ); - try { - Iterator ontClassIt = ontModel.listClasses(); - while (ontClassIt.hasNext()) { - OntClass ontClass = ontClassIt.next(); - if (ontologyURI.equals(ontClass.getNameSpace())) { - boolean root = true; - 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()) ) { - root = false; - break; - } - } - } finally { - superStmtIt.close(); - } - if (root) { - ontologyRootClasses.add(new VClassJena(ontClass,getWebappDaoFactory())); - } - } - } - } finally { - ontModel.leaveCriticalSection(); - } - return ontologyRootClasses; + if (ontologyURI == null) { + throw new RuntimeException("can't find root classes for null ontology URI"); + } + // return getRootClasses(ontologyURI); + List ontologyRootClasses = new ArrayList(); + OntModel ontModel = getOntModel(); + ontModel.enterCriticalSection(Lock.READ); + try { + Iterator ontClassIt = ontModel.listClasses(); + while (ontClassIt.hasNext()) { + OntClass ontClass = ontClassIt.next(); + if (ontologyURI.equals(ontClass.getNameSpace())) { + boolean root = true; + 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()) ) { + root = false; + break; + } + } + } finally { + superStmtIt.close(); + } + if (root) { + ontologyRootClasses.add(new VClassJena(ontClass,getWebappDaoFactory())); + } + } + } + } finally { + ontModel.leaveCriticalSection(); + } + return ontologyRootClasses; } public List getSubClassURIs(String classURI) { @@ -601,15 +601,15 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { subURIs.add(getClassURIStr(cls)); } } catch (Exception e) { - // we'll try this again using a different method that doesn't try to convert to OntClass - List supList = this.listDirectObjectPropertySubjects(getOntModel().getResource(classURI), RDFS.subClassOf); - for (Resource res : supList) { - subURIs.add(res.getURI()); - } + // we'll try this again using a different method that doesn't try to convert to OntClass + List supList = this.listDirectObjectPropertySubjects(getOntModel().getResource(classURI), RDFS.subClassOf); + for (Resource res : supList) { + subURIs.add(res.getURI()); + } } return subURIs; } - + public List getSuperClassURIs(String classURI, boolean direct) { List supURIs = new ArrayList(); OntClass subClass = getOntClass(getOntModel(), classURI); @@ -620,54 +620,54 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { supURIs.add(getClassURIStr(cls)); } } catch (Exception e) { - //TODO make this attempt respect the direct argument - // we'll try this again using a different method that doesn't try to convert to OntClass - List supList = this.listDirectObjectPropertyValues(getOntModel().getResource(classURI), RDFS.subClassOf); - for (Resource res : supList) { - supURIs.add(getClassURIStr(res)); - } + //TODO make this attempt respect the direct argument + // we'll try this again using a different method that doesn't try to convert to OntClass + List supList = this.listDirectObjectPropertyValues(getOntModel().getResource(classURI), RDFS.subClassOf); + for (Resource res : supList) { + supURIs.add(getClassURIStr(res)); + } } return supURIs; } public VClass getTopConcept() { - VClass top = new VClass(); - if (getOntModel().getProfile().NAMESPACE().equals(RDFS.getURI())) { - top.setURI(RDF.getURI()+"Resource"); - } else { - top.setURI( (getOntModel().getProfile().THING().getURI()!=null) ? (getOntModel().getProfile().THING().getURI()): null); - } - if (top.getURI() != null) { - top.setName(top.getLocalName()); - return top; - } else { - return null; - } + VClass top = new VClass(); + if (getOntModel().getProfile().NAMESPACE().equals(RDFS.getURI())) { + top.setURI(RDF.getURI()+"Resource"); + } else { + top.setURI( (getOntModel().getProfile().THING().getURI()!=null) ? (getOntModel().getProfile().THING().getURI()): null); + } + if (top.getURI() != null) { + top.setName(top.getLocalName()); + return top; + } else { + return null; + } } - + public VClass getBottomConcept() { - VClass bottom = new VClass(); - if (getOntModel().getProfile().NAMESPACE().equals(RDFS.getURI())) { - return null; - } else { - bottom.setURI( (getOntModel().getProfile().NOTHING().getURI()!=null) ? (getOntModel().getProfile().NOTHING().getURI()): null); - } - if (bottom.getURI() != null) { - bottom.setName(bottom.getLocalName()); - return bottom; - } else { - return null; - } + VClass bottom = new VClass(); + if (getOntModel().getProfile().NAMESPACE().equals(RDFS.getURI())) { + return null; + } else { + bottom.setURI( (getOntModel().getProfile().NOTHING().getURI()!=null) ? (getOntModel().getProfile().NOTHING().getURI()): null); + } + if (bottom.getURI() != null) { + bottom.setName(bottom.getLocalName()); + return bottom; + } else { + return null; + } } - + public VClass getVClassByURI(String URIStr) { getOntModel().enterCriticalSection(Lock.READ); try { - OntClass cls = getOntClass(getOntModel(),URIStr); + OntClass cls = getOntClass(getOntModel(),URIStr); if (cls != null) { return new VClassJena(cls,getWebappDaoFactory()); } else { - return null; + return null; } } finally { getOntModel().leaveCriticalSection(); @@ -675,74 +675,74 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { } public void insertNewVClass(VClass cls) throws InsertException { - insertNewVClass(cls,getOntModelSelector().getTBoxModel()); + insertNewVClass(cls,getOntModelSelector().getTBoxModel()); } public List getVClassesForProperty(String propertyURI, boolean domainSide) { - return getVClassesForProperty(null, propertyURI, domainSide); + return getVClassesForProperty(null, propertyURI, domainSide); } - + public List getVClassesForProperty(String vclassURI, String propertyURI) { - return getVClassesForProperty(vclassURI, propertyURI, true); + return getVClassesForProperty(vclassURI, propertyURI, true); } - + private List getVClassesForProperty(String vclassURI, String propertyURI, boolean domainSide) { List vClasses = new ArrayList(); getOntModel().enterCriticalSection(Lock.READ); try { ObjectProperty op = getOntModel().getObjectProperty(propertyURI); if (op != null) { - OntResource superclass = null; - if (vclassURI != null) { - // TODO need a getAllSuperPropertyURIs method in ObjectPropertyDao - List superproperties = getWebappDaoFactory().getObjectPropertyDao().getSuperPropertyURIs(propertyURI,false); - superproperties.add(propertyURI); - 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();) { - Statement restStmt = (Statement) restStmtIt.next(); - Resource restRes = restStmt.getSubject(); - for (Iterator axStmtIt = getOntModel().listStatements(null,null,restRes); axStmtIt.hasNext();) { - Statement axStmt = (Statement) axStmtIt.next(); - OntResource subjOntRes = null; - if (axStmt.getSubject().canAs(OntResource.class)) { - subjOntRes = (OntResource) axStmt.getSubject().as(OntResource.class); - } - if ( - (subjOntRes != null) && (subjSuperclasses.contains(getClassURIStr(subjOntRes))) && - (axStmt.getPredicate().equals(RDFS.subClassOf) || (axStmt.getPredicate().equals(OWL.equivalentClass))) - ) { - if (restRes.canAs(AllValuesFromRestriction.class)) { - AllValuesFromRestriction avfRest = (AllValuesFromRestriction) restRes.as(AllValuesFromRestriction.class); - Resource avf = avfRest.getAllValuesFrom(); - if (avf.canAs(OntClass.class)) { - superclass = (OntClass) avfRest.getAllValuesFrom().as(OntClass.class); - } - } - } - } - } - } - } - if (superclass == null) { - superclass = (domainSide) ? op.getRange() : op.getDomain(); - if (superclass == null) { - superclass = getOntModel().getOntResource(OWL.Thing.getURI()); - } - } + OntResource superclass = null; + if (vclassURI != null) { + // TODO need a getAllSuperPropertyURIs method in ObjectPropertyDao + List superproperties = getWebappDaoFactory().getObjectPropertyDao().getSuperPropertyURIs(propertyURI,false); + superproperties.add(propertyURI); + 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();) { + Statement restStmt = (Statement) restStmtIt.next(); + Resource restRes = restStmt.getSubject(); + for (Iterator axStmtIt = getOntModel().listStatements(null,null,restRes); axStmtIt.hasNext();) { + Statement axStmt = (Statement) axStmtIt.next(); + OntResource subjOntRes = null; + if (axStmt.getSubject().canAs(OntResource.class)) { + subjOntRes = (OntResource) axStmt.getSubject().as(OntResource.class); + } + if ( + (subjOntRes != null) && (subjSuperclasses.contains(getClassURIStr(subjOntRes))) && + (axStmt.getPredicate().equals(RDFS.subClassOf) || (axStmt.getPredicate().equals(OWL.equivalentClass))) + ) { + if (restRes.canAs(AllValuesFromRestriction.class)) { + AllValuesFromRestriction avfRest = (AllValuesFromRestriction) restRes.as(AllValuesFromRestriction.class); + Resource avf = avfRest.getAllValuesFrom(); + if (avf.canAs(OntClass.class)) { + superclass = (OntClass) avfRest.getAllValuesFrom().as(OntClass.class); + } + } + } + } + } + } + } + if (superclass == null) { + superclass = (domainSide) ? op.getRange() : op.getDomain(); + if (superclass == null) { + superclass = getOntModel().getOntResource(OWL.Thing.getURI()); + } + } if (superclass != null) { - VClass superVclass; - if (superclass.isAnon()) { - superVclass = getVClassByURI(getClassURIStr(superclass)); - } else { - superVclass = getVClassByURI(superclass.getURI()); - } + VClass superVclass; + if (superclass.isAnon()) { + superVclass = getVClassByURI(getClassURIStr(superclass)); + } else { + superVclass = getVClassByURI(superclass.getURI()); + } if (superVclass != null) { vClasses.add(superVclass); //Commenting out this section to prevent all subclasses of owl:Thing //returned if range is owl:Thing, refer to NIHVIVO-3357 - /* String isInferencing = getWebappDaoFactory().getProperties().get("infersTypes"); + /* 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 PelletListener pl = getWebappDaoFactory().getPelletListener(); @@ -765,263 +765,309 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { return vClasses; } -///////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////// - public void addVClassesToGroup(VClassGroup group) { - addVClassesToGroup(group, true); - } + public void addVClassesToGroup(VClassGroup group) { + addVClassesToGroup(group, true); + } - @Deprecated - public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses) { - addVClassesToGroup(group, includeUninstantiatedClasses, false); - } + @Deprecated + public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses) { + addVClassesToGroup(group, includeUninstantiatedClasses, false); + } - @Deprecated - public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses, boolean getIndividualCount) { - getOntModel().enterCriticalSection(Lock.READ); - - if (getIndividualCount) { - group.setIndividualCount( getClassGroupInstanceCount(group)); - } - - try { - if ((group != null) && (group.getURI() != null)) { - Resource groupRes = ResourceFactory.createResource(group.getURI()); - AnnotationProperty inClassGroup = getOntModel().getAnnotationProperty(VitroVocabulary.IN_CLASSGROUP); - if (inClassGroup != null) { - ClosableIterator annotIt = getOntModel().listStatements((OntClass)null,inClassGroup,groupRes); - try { - while (annotIt.hasNext()) { - try { - Statement annot = (Statement) annotIt.next(); - Resource cls = (Resource) annot.getSubject(); - VClass vcw = (VClass) getVClassByURI(cls.getURI()); - if (vcw != null) { - boolean classIsInstantiated = false; - if (getIndividualCount) { - Model aboxModel = getOntModelSelector().getABoxModel(); - aboxModel.enterCriticalSection(Lock.READ); - int count = 0; - try { - String countQueryStr = "SELECT COUNT(*) WHERE \n" + - "{ ?s a <" + cls.getURI() + "> } \n"; - Query countQuery = QueryFactory.create(countQueryStr, Syntax.syntaxARQ); - QueryExecution qe = QueryExecutionFactory.create(countQuery, aboxModel); - ResultSet rs =qe.execSelect(); - count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm()); - //count = aboxModel.listStatements(null,RDF.type,cls).toList().size(); - } finally { - aboxModel.leaveCriticalSection(); - } - vcw.setEntityCount(count); - classIsInstantiated = (count > 0); - } else if (includeUninstantiatedClasses == false) { - // Note: to support SDB models, may want to do this with - // SPARQL and LIMIT 1 if SDB can take advantage of it - Model aboxModel = getOntModelSelector().getABoxModel(); - aboxModel.enterCriticalSection(Lock.READ); - try { - ClosableIterator countIt = aboxModel.listStatements(null,RDF.type,cls); - try { - if (countIt.hasNext()) { - classIsInstantiated = true; - } - } finally { - countIt.close(); - } - } finally { - aboxModel.leaveCriticalSection(); - } + @Deprecated + public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses, boolean getIndividualCount) { + getOntModel().enterCriticalSection(Lock.READ); + + if (getIndividualCount) { + group.setIndividualCount( getClassGroupInstanceCount(group)); + } + + try { + if ((group != null) && (group.getURI() != null)) { + Resource groupRes = ResourceFactory.createResource(group.getURI()); + AnnotationProperty inClassGroup = getOntModel().getAnnotationProperty(VitroVocabulary.IN_CLASSGROUP); + if (inClassGroup != null) { + ClosableIterator annotIt = getOntModel().listStatements((OntClass)null,inClassGroup,groupRes); + try { + while (annotIt.hasNext()) { + try { + Statement annot = (Statement) annotIt.next(); + Resource cls = (Resource) annot.getSubject(); + VClass vcw = (VClass) getVClassByURI(cls.getURI()); + if (vcw != null) { + boolean classIsInstantiated = false; + if (getIndividualCount) { + Model aboxModel = getOntModelSelector().getABoxModel(); + aboxModel.enterCriticalSection(Lock.READ); + int count = 0; + try { + String countQueryStr = "SELECT COUNT(*) WHERE \n" + + "{ ?s a <" + cls.getURI() + "> } \n"; + Query countQuery = QueryFactory.create(countQueryStr, Syntax.syntaxARQ); + QueryExecution qe = QueryExecutionFactory.create(countQuery, aboxModel); + ResultSet rs =qe.execSelect(); + count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm()); + //count = aboxModel.listStatements(null,RDF.type,cls).toList().size(); + } finally { + aboxModel.leaveCriticalSection(); } - - if (includeUninstantiatedClasses || classIsInstantiated) { - group.add(vcw); + vcw.setEntityCount(count); + classIsInstantiated = (count > 0); + } else if (includeUninstantiatedClasses == false) { + // Note: to support SDB models, may want to do this with + // SPARQL and LIMIT 1 if SDB can take advantage of it + Model aboxModel = getOntModelSelector().getABoxModel(); + aboxModel.enterCriticalSection(Lock.READ); + try { + ClosableIterator countIt = aboxModel.listStatements(null,RDF.type,cls); + try { + if (countIt.hasNext()) { + classIsInstantiated = true; + } + } finally { + countIt.close(); + } + } finally { + aboxModel.leaveCriticalSection(); } } - } catch (ClassCastException cce) { - log.error(cce, cce); + + if (includeUninstantiatedClasses || classIsInstantiated) { + group.add(vcw); + } } + } catch (ClassCastException cce) { + log.error(cce, cce); } - } finally { - annotIt.close(); } + } finally { + annotIt.close(); } } - java.util.Collections.sort(group.getVitroClassList()); - } finally { - getOntModel().leaveCriticalSection(); } + java.util.Collections.sort(group.getVitroClassList()); + } finally { + getOntModel().leaveCriticalSection(); } + } - int getClassGroupInstanceCount(VClassGroup vcg){ - Model ontModel = getOntModel(); - ontModel.enterCriticalSection(Lock.READ); - int count = 0; - try { - String queryText = + int getClassGroupInstanceCount(VClassGroup vcg){ + Model ontModel = getOntModel(); + ontModel.enterCriticalSection(Lock.READ); + int count = 0; + try { + String queryText = "SELECT COUNT( DISTINCT ?instance ) WHERE { \n" + - " ?class <"+VitroVocabulary.IN_CLASSGROUP+"> <"+vcg.getURI() +"> .\n" + - " ?instance a ?class . \n" + - "}" ; - Query countQuery = QueryFactory.create(queryText, Syntax.syntaxARQ); - QueryExecution qe = QueryExecutionFactory.create(countQuery, ontModel); - ResultSet rs =qe.execSelect(); - count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm()); - }catch(Exception ex){ - log.error(ex,ex); - } finally { - ontModel.leaveCriticalSection(); - } - return count; - } - - - public void addVClassesToGroups(List groups) { - getOntModel().enterCriticalSection(Lock.READ); - try { - if (groups != null) { - Iterator groupIt = groups.iterator(); - while (groupIt.hasNext()) { - VClassGroup g = (VClassGroup) groupIt.next(); - addVClassesToGroup(g); - } - } - } finally { - getOntModel().leaveCriticalSection(); - } + " ?class <"+VitroVocabulary.IN_CLASSGROUP+"> <"+vcg.getURI() +"> .\n" + + " ?instance a ?class . \n" + + "}" ; + Query countQuery = QueryFactory.create(queryText, Syntax.syntaxARQ); + QueryExecution qe = QueryExecutionFactory.create(countQuery, ontModel); + ResultSet rs =qe.execSelect(); + count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm()); + }catch(Exception ex){ + log.error(ex,ex); + } finally { + ontModel.leaveCriticalSection(); } + return count; + } - public int insertNewVClass(VClass cls, OntModel ontModel) throws InsertException { - ontModel.enterCriticalSection(Lock.WRITE); - getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); - try { - String errMsgStr = getWebappDaoFactory().checkURI(cls.getURI()); - if (errMsgStr != null) { - throw new InsertException(errMsgStr); - } - OntClass ontCls = ontModel.createClass(cls.getURI()); - try { - if (cls.getName() != null && cls.getName().length() > 0) { - ontCls.setLabel(cls.getName(), (String) getDefaultLanguage()); - } else { - ontCls.removeAll(RDFS.label); - } - } catch (Exception e) { - log.error("error setting label for class "+cls.getURI()); + + public void addVClassesToGroups(List groups) { + getOntModel().enterCriticalSection(Lock.READ); + try { + if (groups != null) { + Iterator groupIt = groups.iterator(); + while (groupIt.hasNext()) { + VClassGroup g = (VClassGroup) groupIt.next(); + addVClassesToGroup(g); } - try { - if (cls.getGroupURI() != null && cls.getGroupURI().length()>0) { - String badURIErrorStr = checkURI(cls.getGroupURI()); - if (badURIErrorStr == null) { - ontCls.addProperty(IN_CLASSGROUP, getOntModel().getResource(cls.getGroupURI())); - } else { - log.error(badURIErrorStr); - } - } - } catch (Exception e) { - log.error("error linking class "+cls.getURI()+" to class group"); - } - addPropertyStringValue(ontCls,SHORTDEF,cls.getShortDef(),ontModel); - addPropertyStringValue(ontCls,EXAMPLE_ANNOT,cls.getExample(),ontModel); - addPropertyStringValue(ontCls,DESCRIPTION_ANNOT,cls.getDescription(),ontModel); - addPropertyIntValue(ontCls,DISPLAY_LIMIT,cls.getDisplayLimit(),ontModel); - addPropertyIntValue(ontCls,DISPLAY_RANK_ANNOT,cls.getDisplayRank(),ontModel); - - ontCls.removeAll(HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT); - if (HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT != null && cls.getHiddenFromDisplayBelowRoleLevel() != null) { // only need to add if present - try { - ontCls.addProperty(HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT, ResourceFactory.createResource(cls.getHiddenFromDisplayBelowRoleLevel().getURI())); - } catch (Exception e) { - log.error("error adding HiddenFromDisplayBelowRoleLevel annotation to class "+cls.getURI()); - } - } - - ontCls.removeAll(PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT); - if (PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT != null && cls.getProhibitedFromUpdateBelowRoleLevel() != null) { // only need to add if present - try { - ontCls.addProperty(PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT, ResourceFactory.createResource(cls.getProhibitedFromUpdateBelowRoleLevel().getURI())); - } catch (Exception e) { - log.error("error adding ProhibitedFromUpdateBelowRoleLevel annotation to class "+cls.getURI()); - } - } - - /* OPTIONAL annotation properties */ - addPropertyStringValue(ontCls,PROPERTY_CUSTOMENTRYFORMANNOT,cls.getCustomEntryForm(),ontModel); - addPropertyStringValue(ontCls,PROPERTY_CUSTOMDISPLAYVIEWANNOT,cls.getCustomDisplayView(),ontModel); - addPropertyStringValue(ontCls,PROPERTY_CUSTOMSHORTVIEWANNOT,cls.getCustomShortView(),ontModel); - addPropertyStringValue(ontCls,PROPERTY_CUSTOMSEARCHVIEWANNOT,cls.getCustomSearchView(),ontModel); - addPropertyFloatValue(ontCls, SEARCH_BOOST_ANNOT, cls.getSearchBoost(), ontModel); - } finally { - getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); - ontModel.leaveCriticalSection(); + } + } finally { + getOntModel().leaveCriticalSection(); + } + } + + public int insertNewVClass(VClass cls, OntModel ontModel) throws InsertException { + ontModel.enterCriticalSection(Lock.WRITE); + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); + try { + String errMsgStr = getWebappDaoFactory().checkURI(cls.getURI()); + if (errMsgStr != null) { + throw new InsertException(errMsgStr); } - return 0; - } - - public void updateVClass(VClass cls) { - updateVClass(cls,getOntModel()); - } - - public void updateVClass(VClass cls, OntModel ontModel) { - ontModel.enterCriticalSection(Lock.WRITE); - ontModel.getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); + OntClass ontCls = ontModel.createClass(cls.getURI()); try { - OntClass ontCls = ontModel.getOntClass(cls.getURI()); - - if (ontCls != null) { - updateRDFSLabel(ontCls, cls.getName()); - updatePropertyResourceURIValue(ontCls,IN_CLASSGROUP,cls.getGroupURI(),ontModel); - updatePropertyStringValue(ontCls,SHORTDEF,cls.getShortDef(),ontModel); - updatePropertyStringValue(ontCls,EXAMPLE_ANNOT,cls.getExample(),ontModel); - updatePropertyStringValue(ontCls,DESCRIPTION_ANNOT,cls.getDescription(),ontModel); - updatePropertyNonNegativeIntValue(ontCls,DISPLAY_LIMIT,cls.getDisplayLimit(),ontModel); - updatePropertyNonNegativeIntValue(ontCls,DISPLAY_RANK_ANNOT,cls.getDisplayRank(),ontModel); - updatePropertyFloatValue(ontCls, SEARCH_BOOST_ANNOT, cls.getSearchBoost(), ontModel); - - if (cls.getHiddenFromDisplayBelowRoleLevel() != null) { - updatePropertyResourceURIValue(ontCls,HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT,cls.getHiddenFromDisplayBelowRoleLevel().getURI(),ontModel); - } - - if (cls.getProhibitedFromUpdateBelowRoleLevel() != null) { - updatePropertyResourceURIValue(ontCls,PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT,cls.getProhibitedFromUpdateBelowRoleLevel().getURI(),ontModel); - } - - updatePropertyStringValue(ontCls,PROPERTY_CUSTOMENTRYFORMANNOT,cls.getCustomEntryForm(),ontModel); - updatePropertyStringValue(ontCls,PROPERTY_CUSTOMDISPLAYVIEWANNOT,cls.getCustomDisplayView(),ontModel); - updatePropertyStringValue(ontCls,PROPERTY_CUSTOMSHORTVIEWANNOT,cls.getCustomShortView(),ontModel); - updatePropertyStringValue(ontCls,PROPERTY_CUSTOMSEARCHVIEWANNOT,cls.getCustomSearchView(),ontModel); + if (cls.getName() != null && cls.getName().length() > 0) { + ontCls.setLabel(cls.getName(), (String) getDefaultLanguage()); } else { - log.error("error: cannot find jena class "+cls.getURI()+" for updating"); + ontCls.removeAll(RDFS.label); } - } finally { - getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); - ontModel.leaveCriticalSection(); + } catch (Exception e) { + log.error("error setting label for class "+cls.getURI()); } + try { + if (cls.getGroupURI() != null && cls.getGroupURI().length()>0) { + String badURIErrorStr = checkURI(cls.getGroupURI()); + if (badURIErrorStr == null) { + ontCls.addProperty(IN_CLASSGROUP, getOntModel().getResource(cls.getGroupURI())); + } else { + log.error(badURIErrorStr); + } + } + } catch (Exception e) { + log.error("error linking class "+cls.getURI()+" to class group"); + } + addPropertyStringValue(ontCls,SHORTDEF,cls.getShortDef(),ontModel); + addPropertyStringValue(ontCls,EXAMPLE_ANNOT,cls.getExample(),ontModel); + addPropertyStringValue(ontCls,DESCRIPTION_ANNOT,cls.getDescription(),ontModel); + addPropertyIntValue(ontCls,DISPLAY_LIMIT,cls.getDisplayLimit(),ontModel); + addPropertyIntValue(ontCls,DISPLAY_RANK_ANNOT,cls.getDisplayRank(),ontModel); + + ontCls.removeAll(HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT); + if (HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT != null && cls.getHiddenFromDisplayBelowRoleLevel() != null) { // only need to add if present + try { + ontCls.addProperty(HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT, ResourceFactory.createResource(cls.getHiddenFromDisplayBelowRoleLevel().getURI())); + } catch (Exception e) { + log.error("error adding HiddenFromDisplayBelowRoleLevel annotation to class "+cls.getURI()); + } + } + + ontCls.removeAll(PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT); + if (PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT != null && cls.getProhibitedFromUpdateBelowRoleLevel() != null) { // only need to add if present + try { + ontCls.addProperty(PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT, ResourceFactory.createResource(cls.getProhibitedFromUpdateBelowRoleLevel().getURI())); + } catch (Exception e) { + log.error("error adding ProhibitedFromUpdateBelowRoleLevel annotation to class "+cls.getURI()); + } + } + + /* OPTIONAL annotation properties */ + addPropertyStringValue(ontCls,PROPERTY_CUSTOMENTRYFORMANNOT,cls.getCustomEntryForm(),ontModel); + addPropertyStringValue(ontCls,PROPERTY_CUSTOMDISPLAYVIEWANNOT,cls.getCustomDisplayView(),ontModel); + addPropertyStringValue(ontCls,PROPERTY_CUSTOMSHORTVIEWANNOT,cls.getCustomShortView(),ontModel); + addPropertyStringValue(ontCls,PROPERTY_CUSTOMSEARCHVIEWANNOT,cls.getCustomSearchView(),ontModel); + addPropertyFloatValue(ontCls, SEARCH_BOOST_ANNOT, cls.getSearchBoost(), ontModel); + } finally { + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); + ontModel.leaveCriticalSection(); } - + return 0; + } + + public void updateVClass(VClass cls) { + updateVClass(cls,getOntModel()); + } + + public void updateVClass(VClass cls, OntModel ontModel) { + ontModel.enterCriticalSection(Lock.WRITE); + ontModel.getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); + try { + OntClass ontCls = ontModel.getOntClass(cls.getURI()); + + if (ontCls != null) { + updateRDFSLabel(ontCls, cls.getName()); + updatePropertyResourceURIValue(ontCls,IN_CLASSGROUP,cls.getGroupURI(),ontModel); + updatePropertyStringValue(ontCls,SHORTDEF,cls.getShortDef(),ontModel); + updatePropertyStringValue(ontCls,EXAMPLE_ANNOT,cls.getExample(),ontModel); + updatePropertyStringValue(ontCls,DESCRIPTION_ANNOT,cls.getDescription(),ontModel); + updatePropertyNonNegativeIntValue(ontCls,DISPLAY_LIMIT,cls.getDisplayLimit(),ontModel); + updatePropertyNonNegativeIntValue(ontCls,DISPLAY_RANK_ANNOT,cls.getDisplayRank(),ontModel); + updatePropertyFloatValue(ontCls, SEARCH_BOOST_ANNOT, cls.getSearchBoost(), ontModel); + + if (cls.getHiddenFromDisplayBelowRoleLevel() != null) { + updatePropertyResourceURIValue(ontCls,HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT,cls.getHiddenFromDisplayBelowRoleLevel().getURI(),ontModel); + } + + if (cls.getProhibitedFromUpdateBelowRoleLevel() != null) { + updatePropertyResourceURIValue(ontCls,PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT,cls.getProhibitedFromUpdateBelowRoleLevel().getURI(),ontModel); + } + + updatePropertyStringValue(ontCls,PROPERTY_CUSTOMENTRYFORMANNOT,cls.getCustomEntryForm(),ontModel); + updatePropertyStringValue(ontCls,PROPERTY_CUSTOMDISPLAYVIEWANNOT,cls.getCustomDisplayView(),ontModel); + updatePropertyStringValue(ontCls,PROPERTY_CUSTOMSHORTVIEWANNOT,cls.getCustomShortView(),ontModel); + updatePropertyStringValue(ontCls,PROPERTY_CUSTOMSEARCHVIEWANNOT,cls.getCustomSearchView(),ontModel); + } else { + log.error("error: cannot find jena class "+cls.getURI()+" for updating"); + } + } finally { + getOntModel().getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); + ontModel.leaveCriticalSection(); + } + } + + public void deleteClasses2Classes( Classes2Classes c2c ) { + deleteClasses2Classes(c2c, getOntModelSelector().getTBoxModel()); + } + + public void deleteClasses2Classes( Classes2Classes c2c, OntModel ontModel ) + { + ontModel.enterCriticalSection(Lock.WRITE); + ontModel.getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); + try { + OntResource subclass = getOntClass(ontModel,c2c.getSubclassURI()); + OntResource superclass = getOntClass(ontModel,c2c.getSuperclassURI()); + if ((subclass != null) && (superclass != null)) { + ontModel.removeAll(subclass, RDFS.subClassOf, superclass); + } + if (subclass.isAnon()) { + smartRemove(subclass, getOntModel()); + } + if (superclass.isAnon()) { + smartRemove(superclass, getOntModel()); + } + } finally { + ontModel.getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); + ontModel.leaveCriticalSection(); + } + } + + public void insertNewClasses2Classes( Classes2Classes c2c ) { + insertNewClasses2Classes(c2c, getOntModelSelector().getTBoxModel()); + } + + public void insertNewClasses2Classes( Classes2Classes c2c, OntModel ontModel ) + { + ontModel.enterCriticalSection(Lock.WRITE); + ontModel.getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),true)); + try { + Resource subclass = ontModel.getResource(c2c.getSubclassURI()); + Resource superclass = ontModel.getResource(c2c.getSuperclassURI()); + if ((subclass != null) && (superclass != null)) { + ontModel.add(subclass, RDFS.subClassOf, superclass); + } + } finally { + ontModel.getBaseModel().notifyEvent(new EditEvent(getWebappDaoFactory().getUserURI(),false)); + ontModel.leaveCriticalSection(); + } + } + public boolean isSubClassOf(VClass vc1, VClass vc2) { - if (vc1 == null || vc2 == null) { - return false; - } - return isSubClassOf(vc1.getURI(), vc2.getURI()); + if (vc1 == null || vc2 == null) { + return false; + } + return isSubClassOf(vc1.getURI(), vc2.getURI()); } - + public boolean isSubClassOf(String vclassURI1, String vclassURI2) { - if (vclassURI1 == null || vclassURI2 == null) { - return false; - } - OntModel ontModel = getOntModel(); - try { - ontModel.enterCriticalSection(Lock.READ); - OntClass oc1 = getOntClass(ontModel, vclassURI1); - OntClass oc2 = getOntClass(ontModel, vclassURI2); - if (oc1 == null || oc2 == null) { - return false; - } - return ontModel.contains(oc1, RDFS.subClassOf, oc2); - } finally { - ontModel.leaveCriticalSection(); - } + if (vclassURI1 == null || vclassURI2 == null) { + return false; + } + OntModel ontModel = getOntModel(); + try { + ontModel.enterCriticalSection(Lock.READ); + OntClass oc1 = getOntClass(ontModel, vclassURI1); + OntClass oc2 = getOntClass(ontModel, vclassURI2); + if (oc1 == null || oc2 == null) { + return false; + } + return ontModel.contains(oc1, RDFS.subClassOf, oc2); + } finally { + ontModel.leaveCriticalSection(); + } } - + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java index 0101815b3..055d1501b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java @@ -30,7 +30,6 @@ import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.util.iterator.ClosableIterator; import edu.cornell.mannlib.vitro.webapp.dao.ApplicationDao; -import edu.cornell.mannlib.vitro.webapp.dao.Classes2ClassesDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao; @@ -311,13 +310,6 @@ public class WebappDaoFactoryJena implements WebappDaoFactory { else return userAccountsDao = new UserAccountsDaoJena(this); } - - Classes2ClassesDao classes2ClassesDao = null; - public Classes2ClassesDao getClasses2ClassesDao() { - if(classes2ClassesDao == null ) - classes2ClassesDao = new Classes2ClassesDaoJena(this); - return classes2ClassesDao; - } DataPropertyStatementDao dataPropertyStatementDao = null; public DataPropertyStatementDao getDataPropertyStatementDao() { diff --git a/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactoryStub.java b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactoryStub.java index d8e67cfe3..c0aaa9d77 100644 --- a/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactoryStub.java +++ b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactoryStub.java @@ -7,7 +7,6 @@ import java.util.Map; import java.util.Set; import edu.cornell.mannlib.vitro.webapp.dao.ApplicationDao; -import edu.cornell.mannlib.vitro.webapp.dao.Classes2ClassesDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao; @@ -186,12 +185,6 @@ return this.objectPropertyStatementDao; } "WebappDaoFactory.getUserURI() not implemented."); } - @Override - public Classes2ClassesDao getClasses2ClassesDao() { - throw new RuntimeException( - "WebappDaoFactory.getClasses2ClassesDao() not implemented."); - } - @Override public DatatypeDao getDatatypeDao() { throw new RuntimeException(