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 uk.ac.ebi.quickgo.rest.service.ServiceConfigException;

import java.io.IOException;
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.
     * @return
     */
    @Bean
    public CoTermRepository coTermRepository() {
        CoTermRepositorySimpleMap coTermRepository = null;
        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;
    }


}

@@ -185,98 +185,8 @@
 ap;%0A
-import uk.ac.ebi.quickgo.rest.service.ServiceConfigException;%0A%0Aimport java.io.IOException;
 %0Aimp
@@ -1195,17 +1195,45 @@
  @return
+ CoTerm repository instance.
 %0A
-
      */%0A
@@ -1345,15 +1345,8 @@
 tory
- = null
 ;%0A  
@@ -1354,16 +1354,17 @@
      try
+ 
 %7B%0A      
@@ -1715,16 +1715,29 @@
         
+             
 (manualR
@@ -1743,23 +1743,27 @@
 Resource
+ 
 !=
+ 
 null
-?
+ ? 
 manualRe
@@ -1777,33 +1777,35 @@
 getDescription()
-:
+ : 
 %22unknown%22) + %22 o
@@ -1800,16 +1800,49 @@
 nown%22) +
+%0A                                
  %22 or fr
@@ -1881,16 +1881,29 @@
         
+  
+           
 (allReso
@@ -1910,15 +1910,19 @@
 urce
+ 
 !=
+ 
 null
-?
+ ? 
 allR
@@ -1945,17 +1945,19 @@
 iption()
-:
+ : 
 %22unknown
@@ -2090,14 +2090,13 @@
 ry;%0A
+
     %7D%0A%0A
-%0A
 %7D%0A

Remove unused imports. Reformat.