updating for NIHVIVO-3494

"Add RDF leads to null pointer exception in certain cases". Including check for null to avoid null pointer exception.
This commit is contained in:
hjkhjk54 2011-12-13 19:20:23 +00:00
parent 1a201b9037
commit 02304f6bb8

View file

@ -91,31 +91,34 @@ public class JenaModelUtils {
ontModel.enterCriticalSection(Lock.READ); ontModel.enterCriticalSection(Lock.READ);
try { try {
try { try {
for (Iterator rootClassIt = myWebappDaoFactory.getVClassDao() List<VClass> rootClasses = myWebappDaoFactory.getVClassDao()
.getRootClasses().iterator(); rootClassIt.hasNext(); ) { .getRootClasses();
VClass rootClass = (VClass) rootClassIt.next(); if(rootClasses != null) {
for (Iterator rootClassIt = rootClasses.iterator(); rootClassIt.hasNext(); ) {
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";