package uk.ac.ebi.quickgo.ontology.coterms;

import uk.ac.ebi.quickgo.ontology.common.coterms.CoTermRepository;
import uk.ac.ebi.quickgo.ontology.common.coterms.CoTermRepositorySimpleMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;

/**
 * @author Tony Wardell
 * Date: 29/09/2016
 * Time: 11:50
 * Created with IntelliJ IDEA.
 */
@Configuration
public class CoTermConfig {

    private static final Logger LOGGER = LoggerFactory.getLogger(CoTermConfig.class);

    @Value("${coterm.default.limit:50}")
    private int defaultLimit;

    @Value("${coterm.source.manual}")
    private Resource manualResource;

    @Value("${coterm.source.all}")
    private Resource allResource;

    @Value("${coterm.source.headerLines:1}")
    private int headerLines;

    /**
     * If we have been unable to load the CoTermRepository, do not propagate the exception as this will stop all
     * configuration completing and the ontology service will not be available. Instead return a repository instance
     * that contains no data. It will throw an error everytime it is used to look up CoTerms for an id.
     * @return CoTerm repository instance.
     */
    @Bean
    public CoTermRepository coTermRepository() {
        CoTermRepositorySimpleMap coTermRepository;
        try {
            coTermRepository = CoTermRepositorySimpleMap.createCoTermRepositorySimpleMap(manualResource, allResource,
                                                                                         headerLines);
        } catch (Exception e) {
            LOGGER.error("Failed to load co-occurring terms from 'MANUAL' source " +
                                 (manualResource != null ? manualResource.getDescription() : "unknown") +
                                 " or from 'ALL' source " +
                                 (allResource != null ? allResource.getDescription() : "unknown"));
            coTermRepository = CoTermRepositorySimpleMap.createEmptyRepository();
        }
        return coTermRepository;
    }

}

@@ -457,16 +457,122 @@
 ource;%0A%0A
+import static uk.ac.ebi.quickgo.ontology.common.coterms.CoTermRepositorySimpleMap.createEmptyRepository;%0A%0A
 /**%0A * @
@@ -1381,16 +1381,17 @@
 or every
+ 
 time it 
@@ -1873,21 +1873,36 @@
     
-LOGGER.error(
+final String errorMessage = 
 %22Fai
@@ -1977,29 +1977,16 @@
         
-             
 (manualR
@@ -1993,25 +1993,25 @@
 esource 
-!
+=
 = null ?
  manualR
@@ -2002,16 +2002,28 @@
 = null ?
+ %22unknown%22 :
  manualR
@@ -2050,37 +2050,12 @@
 on()
- : %22unknown%22) +%0A             
+) +%0A
     
@@ -2117,29 +2117,16 @@
         
-         
-    
 (allReso
@@ -2134,17 +2134,17 @@
 rce 
-!
+=
 = null ?
  all
@@ -2139,16 +2139,28 @@
 = null ?
+ %22unknown%22 :
  allReso
@@ -2184,21 +2184,48 @@
 on()
- : %22unknown%22)
+);%0A            LOGGER.error(errorMessage
 );%0A 
@@ -2258,34 +2258,8 @@
 y = 
-CoTermRepositorySimpleMap.
 crea

Fix spelling, make error message creation clearer.