NIHVIVO-3498 modified VClassDaoJena.getRootClasses() to not return null; processing imports closure on ontology upload

This commit is contained in:
brianjlowe 2011-12-14 16:53:18 +00:00
parent 5880846144
commit 83b2ca3720
4 changed files with 57 additions and 76 deletions

View file

@ -88,8 +88,7 @@ public class ClassHierarchyListingController extends BaseEditController {
roots = vcDao.getRootClasses();
}
// DEBUGGING
if (roots == null) {
if (roots.isEmpty()) {
roots = new LinkedList<VClass>();
roots.add(vrequest.getFullWebappDaoFactory().getVClassDao()
.getTopConcept());

View file

@ -151,6 +151,9 @@ public class RDFUploadController extends BaseEditController {
/* ********** Do the model changes *********** */
if( !directRead && uploadModel != null ){
uploadModel.loadImports();
long tboxstmtCount = 0L;
long aboxstmtCount = 0L;

View file

@ -91,34 +91,32 @@ public class JenaModelUtils {
ontModel.enterCriticalSection(Lock.READ);
try {
try {
List<VClass> rootClasses = myWebappDaoFactory.getVClassDao()
.getRootClasses();
if(rootClasses != null) {
for (Iterator rootClassIt = rootClasses.iterator(); rootClassIt.hasNext(); ) {
VClass rootClass = (VClass) rootClassIt.next();
Individual classGroup = modelForClassgroups.createIndividual(
wadf.getDefaultNamespace() + "vitroClassGroup" +
rootClass.getLocalName(), classGroupClass);
classGroup.setLabel(rootClass.getName(), null);
Resource rootClassRes = modelForClassgroupAnnotations.getResource(
rootClass.getURI());
modelForClassgroupAnnotations.add(
rootClassRes, inClassGroupProperty, classGroup);
for (Iterator<String> childIt = myWebappDaoFactory.getVClassDao()
.getAllSubClassURIs(rootClass.getURI()).iterator();
childIt.hasNext(); ) {
String childURI = (String) childIt.next();
Resource childClass = modelForClassgroupAnnotations
.getResource(childURI);
if (!modelForClassgroupAnnotations.contains(
childClass, inClassGroupProperty, (RDFNode) null)) {
childClass.addProperty(inClassGroupProperty, classGroup);
}
}
}
}
List<VClass> rootClasses = myWebappDaoFactory.getVClassDao()
.getRootClasses();
for (Iterator<VClass> rootClassIt = rootClasses.iterator();
rootClassIt.hasNext(); ) {
VClass rootClass = (VClass) rootClassIt.next();
Individual classGroup = modelForClassgroups.createIndividual(
wadf.getDefaultNamespace() + "vitroClassGroup" +
rootClass.getLocalName(), classGroupClass);
classGroup.setLabel(rootClass.getName(), null);
Resource rootClassRes = modelForClassgroupAnnotations.getResource(
rootClass.getURI());
modelForClassgroupAnnotations.add(
rootClassRes, inClassGroupProperty, classGroup);
for (Iterator<String> childIt = myWebappDaoFactory.getVClassDao()
.getAllSubClassURIs(rootClass.getURI()).iterator();
childIt.hasNext(); ) {
String childURI = (String) childIt.next();
Resource childClass = modelForClassgroupAnnotations
.getResource(childURI);
if (!modelForClassgroupAnnotations.contains(
childClass, inClassGroupProperty, (RDFNode) null)) {
childClass.addProperty(inClassGroupProperty, classGroup);
}
}
}
} catch (Exception e) {
String errMsg = "Unable to create class groups automatically " +
"based on class hierarchy";

View file

@ -435,19 +435,19 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
}
public List <VClass> getAllVclasses() {
List classes = new ArrayList();
List<VClass> classes = new ArrayList<VClass>();
getOntModel().enterCriticalSection(Lock.READ);
try {
ClosableIterator classIt = getOntModel().listClasses();
ClosableIterator<OntClass> classIt = getOntModel().listClasses();
try {
while (classIt.hasNext()) {
try {
OntClass cls = (OntClass) classIt.next();
OntClass cls = classIt.next();
if (!cls.isAnon() && !(NONUSER_NAMESPACES.contains(cls.getNameSpace()))) {
classes.add(new VClassJena(cls,getWebappDaoFactory()));
}
} catch (ClassCastException cce) {
cce.printStackTrace();
log.error(cce, cce);
}
}
} finally {
@ -459,45 +459,27 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
Collections.sort(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 smarterListHierarchyRootClasses(OntModel ontModel) {
private Iterator<OntClass> smarterListHierarchyRootClasses(OntModel ontModel) {
return smarterListHierarchyRootClasses(ontModel, null);
}
/**
* The basic idea here is that we ignore anonymous superclasses for the purpose of determining whether something is a root class.
* We also avoid ClassCastExceptions deep in Jena-land by eschewing Jena's listSuperClasses() method.
* 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();
private Iterator<OntClass> smarterListHierarchyRootClasses(OntModel ontModel, String ontologyURI) {
List<OntClass> rootClassList = new ArrayList<OntClass>();
ClosableIterator ci = ontModel.listClasses();
try {
for (ClosableIterator i = ci ; i.hasNext(); ) {
try {
OntClass ontClass = (OntClass) i.next();
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();
if (res.canAs(OntClass.class)) {
OntClass superClass = (OntClass) res.as(OntClass.class);
@ -507,7 +489,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
!superClass.equals(ontClass) &&
!( ontModel.contains(ontClass,OWL.equivalentClass,superClass) ||
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;
break;
}
@ -532,28 +516,23 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
}
private List <VClass> getRootClasses(String ontologyURI) {
List rootClasses = new ArrayList();
List<VClass> rootClasses = new ArrayList<VClass>();
getOntModel().enterCriticalSection(Lock.READ);
try {
//ClosableIterator rootIt = getOntModel().listHierarchyRootClasses();
Iterator rootIt = smarterListHierarchyRootClasses(getOntModel(),ontologyURI);
try {
while (rootIt.hasNext()) {
try {
OntClass cls = (OntClass) rootIt.next();
if (!cls.isAnon() && cls.getNameSpace() != null && !(NONUSER_NAMESPACES.contains(cls.getNameSpace()))) {
rootClasses.add(new VClassJena(cls,getWebappDaoFactory()));
}
} catch (ClassCastException e) {}
Iterator<OntClass> rootIt = smarterListHierarchyRootClasses(
getOntModel(), ontologyURI);
while (rootIt.hasNext()) {
OntClass cls = rootIt.next();
if (!cls.isAnon() && cls.getNameSpace() != null
&& !(NONUSER_NAMESPACES.contains(cls.getNameSpace()))) {
rootClasses.add(new VClassJena(cls,getWebappDaoFactory()));
}
} finally {
//rootIt.close();
}
Collections.sort(rootClasses);
} finally {
getOntModel().leaveCriticalSection();
}
return (rootClasses.size()>0) ? rootClasses : null;
return rootClasses;
}
@ -839,7 +818,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
group.add(vcw);
}
}
} catch (ClassCastException cce) {cce.printStackTrace();}
} catch (ClassCastException cce) {
log.error(cce, cce);
}
}
} finally {
annotIt.close();