NIHVIVO-3498 modified VClassDaoJena.getRootClasses() to not return null; processing imports closure on ontology upload
This commit is contained in:
parent
5880846144
commit
83b2ca3720
4 changed files with 57 additions and 76 deletions
|
@ -88,8 +88,7 @@ public class ClassHierarchyListingController extends BaseEditController {
|
||||||
roots = vcDao.getRootClasses();
|
roots = vcDao.getRootClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEBUGGING
|
if (roots.isEmpty()) {
|
||||||
if (roots == null) {
|
|
||||||
roots = new LinkedList<VClass>();
|
roots = new LinkedList<VClass>();
|
||||||
roots.add(vrequest.getFullWebappDaoFactory().getVClassDao()
|
roots.add(vrequest.getFullWebappDaoFactory().getVClassDao()
|
||||||
.getTopConcept());
|
.getTopConcept());
|
||||||
|
|
|
@ -151,6 +151,9 @@ public class RDFUploadController extends BaseEditController {
|
||||||
|
|
||||||
/* ********** Do the model changes *********** */
|
/* ********** Do the model changes *********** */
|
||||||
if( !directRead && uploadModel != null ){
|
if( !directRead && uploadModel != null ){
|
||||||
|
|
||||||
|
uploadModel.loadImports();
|
||||||
|
|
||||||
long tboxstmtCount = 0L;
|
long tboxstmtCount = 0L;
|
||||||
long aboxstmtCount = 0L;
|
long aboxstmtCount = 0L;
|
||||||
|
|
||||||
|
|
|
@ -91,34 +91,32 @@ public class JenaModelUtils {
|
||||||
ontModel.enterCriticalSection(Lock.READ);
|
ontModel.enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
List<VClass> rootClasses = myWebappDaoFactory.getVClassDao()
|
List<VClass> rootClasses = myWebappDaoFactory.getVClassDao()
|
||||||
.getRootClasses();
|
.getRootClasses();
|
||||||
if(rootClasses != null) {
|
for (Iterator<VClass> rootClassIt = rootClasses.iterator();
|
||||||
for (Iterator rootClassIt = rootClasses.iterator(); rootClassIt.hasNext(); ) {
|
rootClassIt.hasNext(); ) {
|
||||||
VClass rootClass = (VClass) rootClassIt.next();
|
VClass rootClass = (VClass) rootClassIt.next();
|
||||||
|
Individual classGroup = modelForClassgroups.createIndividual(
|
||||||
Individual classGroup = modelForClassgroups.createIndividual(
|
wadf.getDefaultNamespace() + "vitroClassGroup" +
|
||||||
wadf.getDefaultNamespace() + "vitroClassGroup" +
|
rootClass.getLocalName(), classGroupClass);
|
||||||
rootClass.getLocalName(), classGroupClass);
|
classGroup.setLabel(rootClass.getName(), null);
|
||||||
classGroup.setLabel(rootClass.getName(), null);
|
|
||||||
|
Resource rootClassRes = modelForClassgroupAnnotations.getResource(
|
||||||
Resource rootClassRes = modelForClassgroupAnnotations.getResource(
|
rootClass.getURI());
|
||||||
rootClass.getURI());
|
modelForClassgroupAnnotations.add(
|
||||||
modelForClassgroupAnnotations.add(
|
rootClassRes, inClassGroupProperty, classGroup);
|
||||||
rootClassRes, inClassGroupProperty, classGroup);
|
for (Iterator<String> childIt = myWebappDaoFactory.getVClassDao()
|
||||||
for (Iterator<String> childIt = myWebappDaoFactory.getVClassDao()
|
.getAllSubClassURIs(rootClass.getURI()).iterator();
|
||||||
.getAllSubClassURIs(rootClass.getURI()).iterator();
|
childIt.hasNext(); ) {
|
||||||
childIt.hasNext(); ) {
|
String childURI = (String) childIt.next();
|
||||||
String childURI = (String) childIt.next();
|
Resource childClass = modelForClassgroupAnnotations
|
||||||
Resource childClass = modelForClassgroupAnnotations
|
.getResource(childURI);
|
||||||
.getResource(childURI);
|
if (!modelForClassgroupAnnotations.contains(
|
||||||
if (!modelForClassgroupAnnotations.contains(
|
childClass, inClassGroupProperty, (RDFNode) null)) {
|
||||||
childClass, inClassGroupProperty, (RDFNode) null)) {
|
childClass.addProperty(inClassGroupProperty, classGroup);
|
||||||
childClass.addProperty(inClassGroupProperty, classGroup);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String errMsg = "Unable to create class groups automatically " +
|
String errMsg = "Unable to create class groups automatically " +
|
||||||
"based on class hierarchy";
|
"based on class hierarchy";
|
||||||
|
|
|
@ -435,19 +435,19 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List <VClass> getAllVclasses() {
|
public List <VClass> getAllVclasses() {
|
||||||
List classes = new ArrayList();
|
List<VClass> classes = new ArrayList<VClass>();
|
||||||
getOntModel().enterCriticalSection(Lock.READ);
|
getOntModel().enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
ClosableIterator classIt = getOntModel().listClasses();
|
ClosableIterator<OntClass> classIt = getOntModel().listClasses();
|
||||||
try {
|
try {
|
||||||
while (classIt.hasNext()) {
|
while (classIt.hasNext()) {
|
||||||
try {
|
try {
|
||||||
OntClass cls = (OntClass) classIt.next();
|
OntClass cls = classIt.next();
|
||||||
if (!cls.isAnon() && !(NONUSER_NAMESPACES.contains(cls.getNameSpace()))) {
|
if (!cls.isAnon() && !(NONUSER_NAMESPACES.contains(cls.getNameSpace()))) {
|
||||||
classes.add(new VClassJena(cls,getWebappDaoFactory()));
|
classes.add(new VClassJena(cls,getWebappDaoFactory()));
|
||||||
}
|
}
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
cce.printStackTrace();
|
log.error(cce, cce);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -459,45 +459,27 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
Collections.sort(classes);
|
Collections.sort(classes);
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
private boolean sameLevelOrHigher( RoleLevel userLevel, RoleLevel resourceLevel ){
|
|
||||||
if( resourceLevel == null )
|
|
||||||
return true; //default to visible
|
|
||||||
if ( userLevel == null ) { //default to PUBLIC
|
|
||||||
userLevel = BaseResourceBean.RoleLevel.PUBLIC;
|
|
||||||
}
|
|
||||||
int comparison = userLevel.compareTo(resourceLevel);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
if (comparison == 0) {
|
|
||||||
log.debug("user role "+userLevel.getShorthand()+" judged equal to current user role "+resourceLevel.getShorthand());
|
|
||||||
} else if (comparison > 0) {
|
|
||||||
log.debug("user role "+userLevel.getShorthand()+" judged greater than current user role "+resourceLevel.getShorthand());
|
|
||||||
} else if (comparison < 0) {
|
|
||||||
log.debug("user role "+userLevel.getShorthand()+" judged less than current user role "+resourceLevel.getShorthand());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ( userLevel.compareTo(resourceLevel) >= 0 );
|
|
||||||
} */
|
|
||||||
|
|
||||||
|
private Iterator<OntClass> smarterListHierarchyRootClasses(OntModel ontModel) {
|
||||||
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.
|
* The basic idea here is that we ignore anonymous superclasses for the purpose
|
||||||
* We also avoid ClassCastExceptions deep in Jena-land by eschewing Jena's listSuperClasses() method.
|
* of determining whether something is a root class.
|
||||||
|
* We also avoid ClassCastExceptions deep in Jena-land by eschewing Jena's
|
||||||
|
* listSuperClasses() method.
|
||||||
* @author bjl23
|
* @author bjl23
|
||||||
*/
|
*/
|
||||||
private Iterator smarterListHierarchyRootClasses(OntModel ontModel, String ontologyURI) {
|
private Iterator<OntClass> smarterListHierarchyRootClasses(OntModel ontModel, String ontologyURI) {
|
||||||
List rootClassList = new ArrayList();
|
List<OntClass> rootClassList = new ArrayList<OntClass>();
|
||||||
ClosableIterator ci = ontModel.listClasses();
|
ClosableIterator ci = ontModel.listClasses();
|
||||||
try {
|
try {
|
||||||
for (ClosableIterator i = ci ; i.hasNext(); ) {
|
for (ClosableIterator i = ci ; i.hasNext(); ) {
|
||||||
try {
|
try {
|
||||||
OntClass ontClass = (OntClass) i.next();
|
OntClass ontClass = (OntClass) i.next();
|
||||||
boolean isRoot = true;
|
boolean isRoot = true;
|
||||||
for (Iterator j = ontClass.listPropertyValues(RDFS.subClassOf); j.hasNext(); ) {
|
for (Iterator<RDFNode> j = ontClass.listPropertyValues(RDFS.subClassOf); j.hasNext(); ) {
|
||||||
Resource res = (Resource) j.next();
|
Resource res = (Resource) j.next();
|
||||||
if (res.canAs(OntClass.class)) {
|
if (res.canAs(OntClass.class)) {
|
||||||
OntClass superClass = (OntClass) res.as(OntClass.class);
|
OntClass superClass = (OntClass) res.as(OntClass.class);
|
||||||
|
@ -507,7 +489,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
!superClass.equals(ontClass) &&
|
!superClass.equals(ontClass) &&
|
||||||
!( ontModel.contains(ontClass,OWL.equivalentClass,superClass) ||
|
!( ontModel.contains(ontClass,OWL.equivalentClass,superClass) ||
|
||||||
ontModel.contains(superClass,OWL.equivalentClass,ontClass) ) ) {
|
ontModel.contains(superClass,OWL.equivalentClass,ontClass) ) ) {
|
||||||
if ( (superClass.getNameSpace() != null) && (!(NONUSER_NAMESPACES.contains(superClass.getNameSpace()))) ) {
|
if ( (superClass.getNameSpace() != null)
|
||||||
|
&& (!(NONUSER_NAMESPACES.contains(
|
||||||
|
superClass.getNameSpace()))) ) {
|
||||||
isRoot=false;
|
isRoot=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -532,28 +516,23 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List <VClass> getRootClasses(String ontologyURI) {
|
private List <VClass> getRootClasses(String ontologyURI) {
|
||||||
List rootClasses = new ArrayList();
|
List<VClass> rootClasses = new ArrayList<VClass>();
|
||||||
getOntModel().enterCriticalSection(Lock.READ);
|
getOntModel().enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
//ClosableIterator rootIt = getOntModel().listHierarchyRootClasses();
|
Iterator<OntClass> rootIt = smarterListHierarchyRootClasses(
|
||||||
Iterator rootIt = smarterListHierarchyRootClasses(getOntModel(),ontologyURI);
|
getOntModel(), ontologyURI);
|
||||||
try {
|
while (rootIt.hasNext()) {
|
||||||
while (rootIt.hasNext()) {
|
OntClass cls = rootIt.next();
|
||||||
try {
|
if (!cls.isAnon() && cls.getNameSpace() != null
|
||||||
OntClass cls = (OntClass) rootIt.next();
|
&& !(NONUSER_NAMESPACES.contains(cls.getNameSpace()))) {
|
||||||
if (!cls.isAnon() && cls.getNameSpace() != null && !(NONUSER_NAMESPACES.contains(cls.getNameSpace()))) {
|
rootClasses.add(new VClassJena(cls,getWebappDaoFactory()));
|
||||||
rootClasses.add(new VClassJena(cls,getWebappDaoFactory()));
|
|
||||||
}
|
|
||||||
} catch (ClassCastException e) {}
|
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
//rootIt.close();
|
|
||||||
}
|
}
|
||||||
Collections.sort(rootClasses);
|
Collections.sort(rootClasses);
|
||||||
} finally {
|
} finally {
|
||||||
getOntModel().leaveCriticalSection();
|
getOntModel().leaveCriticalSection();
|
||||||
}
|
}
|
||||||
return (rootClasses.size()>0) ? rootClasses : null;
|
return rootClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -839,7 +818,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
||||||
group.add(vcw);
|
group.add(vcw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ClassCastException cce) {cce.printStackTrace();}
|
} catch (ClassCastException cce) {
|
||||||
|
log.error(cce, cce);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
annotIt.close();
|
annotIt.close();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue