From 02304f6bb8f131652d79b04976a9185ef661bf76 Mon Sep 17 00:00:00 2001 From: hjkhjk54 Date: Tue, 13 Dec 2011 19:20:23 +0000 Subject: [PATCH] updating for NIHVIVO-3494 "Add RDF leads to null pointer exception in certain cases". Including check for null to avoid null pointer exception. --- .../vitro/webapp/dao/jena/JenaModelUtils.java | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtils.java index 695c65aaa..151d2244a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtils.java @@ -91,31 +91,34 @@ public class JenaModelUtils { ontModel.enterCriticalSection(Lock.READ); try { try { - for (Iterator rootClassIt = myWebappDaoFactory.getVClassDao() - .getRootClasses().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 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 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 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";