resolution of JIRA issue NIHVIVO-404
This commit is contained in:
parent
082627f121
commit
83f0854c31
5 changed files with 140 additions and 16 deletions
|
@ -5,7 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.controller.edit.listing;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,6 +22,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.PropertyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
@ -43,20 +43,28 @@ public class VClassWebappsListingController extends BaseEditController {
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
//need to figure out how to structure the results object to put the classes underneath
|
//need to figure out how to structure the results object to put the classes underneath
|
||||||
|
|
||||||
VClassDao dao = getWebappDaoFactory().getVClassDao();
|
List<VClass> classes = null;
|
||||||
|
|
||||||
List classes = (request.getParameter("iffRoot") != null)
|
if (request.getParameter("showPropertyRestrictions") != null) {
|
||||||
? dao.getRootClasses()
|
PropertyDao pdao = getWebappDaoFactory().getObjectPropertyDao();
|
||||||
: dao.getAllVclasses();
|
classes = pdao.getClassesRestrictedOn(request.getParameter("propertyURI"));
|
||||||
|
} else {
|
||||||
|
VClassDao vcdao = getWebappDaoFactory().getVClassDao();
|
||||||
|
|
||||||
|
if (request.getParameter("iffRoot") != null) {
|
||||||
|
classes = vcdao.getRootClasses();
|
||||||
|
} else {
|
||||||
|
classes = vcdao.getAllVclasses();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
String ontologyURI = vrequest.getParameter("ontologyUri");
|
String ontologyURI = vrequest.getParameter("ontologyUri");
|
||||||
|
|
||||||
Collections.sort(classes);
|
ArrayList<String> results = new ArrayList<String>();
|
||||||
|
|
||||||
ArrayList results = new ArrayList();
|
|
||||||
results.add("XX");
|
results.add("XX");
|
||||||
results.add("Class");
|
results.add("Class");
|
||||||
results.add("short definition");
|
results.add("short definition");
|
||||||
|
@ -68,7 +76,8 @@ public class VClassWebappsListingController extends BaseEditController {
|
||||||
results.add("update level");
|
results.add("update level");
|
||||||
|
|
||||||
if (classes != null) {
|
if (classes != null) {
|
||||||
Iterator classesIt = classes.iterator();
|
Collections.sort(classes);
|
||||||
|
Iterator<VClass> classesIt = classes.iterator();
|
||||||
while (classesIt.hasNext()) {
|
while (classesIt.hasNext()) {
|
||||||
VClass cls = (VClass) classesIt.next();
|
VClass cls = (VClass) classesIt.next();
|
||||||
if ( (ontologyURI==null) || ( (ontologyURI != null) && (cls.getNamespace()!=null) && (ontologyURI.equals(cls.getNamespace())) ) ) {
|
if ( (ontologyURI==null) || ( (ontologyURI != null) && (cls.getNamespace()!=null) && (ontologyURI.equals(cls.getNamespace())) ) ) {
|
||||||
|
@ -157,7 +166,7 @@ public class VClassWebappsListingController extends BaseEditController {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response) {
|
public void doPost(HttpServletRequest request, HttpServletResponse response) {
|
||||||
doGet(request,response);
|
doGet(request,response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ package edu.cornell.mannlib.vitro.webapp.dao;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
|
|
||||||
public interface PropertyDao {
|
public interface PropertyDao {
|
||||||
|
|
||||||
|
@ -43,4 +43,6 @@ public interface PropertyDao {
|
||||||
|
|
||||||
List <String> getEquivalentPropertyURIs(String propertyURI);
|
List <String> getEquivalentPropertyURIs(String propertyURI);
|
||||||
|
|
||||||
|
List <VClass> getClassesRestrictedOn(String propertyURI);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||||
|
@ -183,5 +184,9 @@ class DataPropertyDaoFiltering extends BaseFiltering implements DataPropertyDao{
|
||||||
Property equivalentProperty) {
|
Property equivalentProperty) {
|
||||||
innerDataPropertyDao.removeEquivalentProperty(property, equivalentProperty);
|
innerDataPropertyDao.removeEquivalentProperty(property, equivalentProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List <VClass> getClassesRestrictedOn(String propertyURI) {
|
||||||
|
return innerDataPropertyDao.getClassesRestrictedOn(propertyURI);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
|
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||||
|
@ -196,4 +198,8 @@ class ObjectPropertyDaoFiltering extends BaseFiltering implements ObjectProperty
|
||||||
return innerObjectPropertyDao.skipEditForm(predicateURI);
|
return innerObjectPropertyDao.skipEditForm(predicateURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List <VClass> getClassesRestrictedOn(String propertyURI) {
|
||||||
|
return innerObjectPropertyDao.getClassesRestrictedOn(propertyURI);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,15 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntClass;
|
import com.hp.hpl.jena.ontology.OntClass;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntProperty;
|
import com.hp.hpl.jena.ontology.OntProperty;
|
||||||
|
@ -20,12 +24,15 @@ import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.PropertyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.PropertyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||||
|
|
||||||
public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
|
public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
|
||||||
|
|
||||||
|
protected static final Log log = LogFactory.getLog(PropertyDaoJena.class.getName());
|
||||||
|
|
||||||
public PropertyDaoJena(WebappDaoFactoryJena wadf) {
|
public PropertyDaoJena(WebappDaoFactoryJena wadf) {
|
||||||
super(wadf);
|
super(wadf);
|
||||||
}
|
}
|
||||||
|
@ -266,5 +273,100 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the classes that have a definition involving a restriction
|
||||||
|
* on the given property.
|
||||||
|
*
|
||||||
|
* @param propertyURI identifier of a property
|
||||||
|
* @return a list of VClass objects representing the classes that have
|
||||||
|
* definitions involving a restriction on the given property.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public List <VClass> getClassesRestrictedOn(String propertyURI) {
|
||||||
|
|
||||||
|
if (propertyURI == null) {
|
||||||
|
log.info("getClassesRestrictedOn: called with null propertyURI");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
OntModel ontModel = getOntModel();
|
||||||
|
ontModel.enterCriticalSection(Lock.READ);
|
||||||
|
|
||||||
|
HashSet<String> classURISet = new HashSet<String>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Resource targetProp = ontModel.getResource(propertyURI);
|
||||||
|
|
||||||
|
if (targetProp != null) {
|
||||||
|
|
||||||
|
StmtIterator stmtIter = ontModel.listStatements((Resource) null, OWL.onProperty, (RDFNode) targetProp);
|
||||||
|
|
||||||
|
while (stmtIter.hasNext()) {
|
||||||
|
Statement statement = stmtIter.next();
|
||||||
|
|
||||||
|
if ( statement.getSubject().canAs(OntClass.class) ) {
|
||||||
|
classURISet.addAll(getRelatedClasses((OntClass) statement.getSubject().as(OntClass.class)));
|
||||||
|
} else {
|
||||||
|
log.warn("getClassesRestrictedOn: Unexpected use of onProperty: it is not applied to a restriction");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.error("getClassesRestrictedOn: Error: didn't find a Property in the ontology model for the URI: " + propertyURI);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
ontModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<VClass> classes = new ArrayList<VClass>();
|
||||||
|
Iterator<String> iter = classURISet.iterator();
|
||||||
|
|
||||||
|
VClassDao vcd = getWebappDaoFactory().getVClassDao();
|
||||||
|
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
|
||||||
|
String curi = iter.next();
|
||||||
|
VClass vc = vcd.getVClassByURI(curi);
|
||||||
|
|
||||||
|
if (vc != null) {
|
||||||
|
classes.add(vc);
|
||||||
|
} else {
|
||||||
|
log.error("getClassesRestrictedOn: Error: no VClass found for URI: " + curi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (classes.size()>0) ? classes : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds all named superclasses, subclasses and equivalent classes of
|
||||||
|
* the given class.
|
||||||
|
*
|
||||||
|
* @param resourceURI identifier of a class
|
||||||
|
* @return set of class URIs
|
||||||
|
*
|
||||||
|
* Note: this method assumes that the caller holds a read lock on
|
||||||
|
* the ontology model.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public HashSet<String> getRelatedClasses(OntClass ontClass) {
|
||||||
|
|
||||||
|
HashSet<String> classSet = new HashSet<String>();
|
||||||
|
|
||||||
|
List<OntClass> classList = ontClass.listEquivalentClasses().toList();
|
||||||
|
classList.addAll(ontClass.listSubClasses().toList());
|
||||||
|
classList.addAll(ontClass.listSuperClasses().toList());
|
||||||
|
|
||||||
|
Iterator<OntClass> it = classList.iterator();
|
||||||
|
|
||||||
|
while (it.hasNext()) {
|
||||||
|
OntClass oc = it.next();
|
||||||
|
|
||||||
|
if (!oc.isAnon()) {
|
||||||
|
classSet.add(oc.getURI());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return classSet;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue