|
1 | 1 | package ubic.basecode.ontology.jena; |
2 | 2 |
|
| 3 | +import com.hp.hpl.jena.ontology.ConversionException; |
3 | 4 | import com.hp.hpl.jena.ontology.OntClass; |
4 | 5 | import com.hp.hpl.jena.ontology.OntModel; |
5 | 6 | import com.hp.hpl.jena.ontology.Restriction; |
@@ -42,7 +43,15 @@ private static Collection<OntClass> getParentsInternal( OntModel model, Collecti |
42 | 43 | ontClasses = ontClasses.stream() |
43 | 44 | .map( t -> t.inModel( model ) ) |
44 | 45 | .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 ) |
46 | 55 | .collect( Collectors.toList() ); |
47 | 56 | if ( ontClasses.isEmpty() ) { |
48 | 57 | return Collections.emptySet(); |
@@ -104,7 +113,15 @@ public static Collection<OntClass> getChildrenInternal( OntModel model, Collecti |
104 | 113 | terms = terms.stream() |
105 | 114 | .map( t -> t.inModel( model ) ) |
106 | 115 | .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 ) |
108 | 125 | .collect( Collectors.toList() ); |
109 | 126 | if ( terms.isEmpty() ) { |
110 | 127 | return Collections.emptySet(); |
|
0 commit comments