Skip to content

Commit 6d84f12

Browse files
committed
Handle possible conversion error when passing an ontology term into another model
1 parent 5d37806 commit 6d84f12

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/ubic/basecode/ontology/jena/JenaUtils.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ubic.basecode.ontology.jena;
22

3+
import com.hp.hpl.jena.ontology.ConversionException;
34
import com.hp.hpl.jena.ontology.OntClass;
45
import com.hp.hpl.jena.ontology.OntModel;
56
import com.hp.hpl.jena.ontology.Restriction;
@@ -42,7 +43,15 @@ private static Collection<OntClass> getParentsInternal( OntModel model, Collecti
4243
ontClasses = ontClasses.stream()
4344
.map( t -> t.inModel( model ) )
4445
.filter( t -> t.canAs( OntClass.class ) )
45-
.map( t -> t.as( OntClass.class ) )
46+
.map( t -> {
47+
try {
48+
return t.as( OntClass.class );
49+
} catch ( ConversionException e ) {
50+
log.error( "Conversion failed for " + t, e );
51+
return null;
52+
}
53+
} )
54+
.filter( Objects::nonNull )
4655
.collect( Collectors.toList() );
4756
if ( ontClasses.isEmpty() ) {
4857
return Collections.emptySet();
@@ -104,7 +113,15 @@ public static Collection<OntClass> getChildrenInternal( OntModel model, Collecti
104113
terms = terms.stream()
105114
.map( t -> t.inModel( model ) )
106115
.filter( t -> t.canAs( OntClass.class ) )
107-
.map( t -> t.as( OntClass.class ) )
116+
.map( t -> {
117+
try {
118+
return t.as( OntClass.class );
119+
} catch ( ConversionException e ) {
120+
log.error( "Conversion failed for " + t, e );
121+
return null;
122+
}
123+
} )
124+
.filter( Objects::nonNull )
108125
.collect( Collectors.toList() );
109126
if ( terms.isEmpty() ) {
110127
return Collections.emptySet();

0 commit comments

Comments
 (0)