4444import ubic .basecode .util .Configuration ;
4545
4646import javax .annotation .Nullable ;
47+ import java .io .IOException ;
4748import java .io .InputStream ;
4849import java .util .*;
4950import java .util .concurrent .locks .Lock ;
@@ -108,6 +109,15 @@ private void initialize( @Nullable InputStream stream, boolean forceLoad, boolea
108109 String ontologyName = getOntologyName ();
109110 String cacheName = getCacheName ();
110111
112+ // Detect configuration problems.
113+ if ( StringUtils .isBlank ( ontologyUrl ) ) {
114+ throw new IllegalStateException ( "URL not defined for %s: ontology cannot be loaded. (" + this + ")" );
115+ }
116+
117+ if ( cacheName == null && forceIndexing ) {
118+ throw new IllegalArgumentException ( String .format ( "No cache directory is set for %s, cannot force indexing." , this ) );
119+ }
120+
111121 boolean loadOntology = isEnabled ();
112122
113123 // If loading ontologies is disabled in the configuration, return
@@ -117,16 +127,6 @@ private void initialize( @Nullable InputStream stream, boolean forceLoad, boolea
117127 return ;
118128 }
119129
120- // Detect configuration problems.
121- if ( StringUtils .isBlank ( ontologyUrl ) ) {
122- throw new IllegalStateException ( "URL not defined for %s: ontology cannot be loaded. (" + this + ")" );
123- }
124-
125- // This thread indexes ontology and creates local cache for uri->ontology terms mappings.
126- if ( !forceIndexing ) {
127- log .info ( "{} index will *not* be refreshed unless the ontology has changed or the index is missing" , this );
128- }
129-
130130 log .info ( "Loading ontology: {}..." , this );
131131 StopWatch loadTime = StopWatch .createStarted ();
132132
@@ -150,22 +150,18 @@ private void initialize( @Nullable InputStream stream, boolean forceLoad, boolea
150150 .filterKeep ( new RestrictionWithOnPropertyFilter ( additionalProperties ) )
151151 .toSet ();
152152
153- //Checks if the current ontology has changed since it was last loaded.
154- boolean changed = cacheName == null || OntologyLoader .hasChanged ( cacheName );
155- boolean indexExists = cacheName != null && OntologyIndexer .getSubjectIndex ( cacheName ) != null ;
156- boolean forceReindexing = forceLoad && forceIndexing ;
157-
158- /*
159- * Indexing is slow, don't do it if we don't have to.
160- */
161- boolean force = forceReindexing || changed || !indexExists ;
162-
163153 // indexing is lengthy, don't bother if we're interrupted
164154 if ( checkIfInterrupted () )
165155 return ;
166156
167157 if ( cacheName != null ) {
168- index = OntologyIndexer .indexOntology ( cacheName , model , force );
158+ //Checks if the current ontology has changed since it was last loaded.
159+ boolean changed = OntologyLoader .hasChanged ( cacheName );
160+ boolean indexExists = OntologyIndexer .getSubjectIndex ( cacheName ) != null ;
161+ boolean forceReindexing = forceLoad && forceIndexing ;
162+ // indexing is slow, don't do it if we don't have to.
163+ index = OntologyIndexer .indexOntology ( cacheName , model ,
164+ forceReindexing || changed || !indexExists );
169165 } else {
170166 index = null ;
171167 }
@@ -183,7 +179,11 @@ private void initialize( @Nullable InputStream stream, boolean forceLoad, boolea
183179 this .isInitialized = true ;
184180 if ( cacheName != null ) {
185181 // now that the terms have been replaced, we can clear old caches
186- OntologyLoader .deleteOldCache ( cacheName );
182+ try {
183+ OntologyLoader .deleteOldCache ( cacheName );
184+ } catch ( IOException e ) {
185+ log .error ( String .format ( String .format ( "Failed to delete old cache directory for %s." , this ), e ) );
186+ }
187187 }
188188 } finally {
189189 lock .unlock ();
0 commit comments