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

import uk.ac.ebi.quickgo.ontology.common.OntologyRepoConfig;
import uk.ac.ebi.quickgo.ontology.common.OntologyRepository;
import uk.ac.ebi.quickgo.ontology.common.document.OntologyType;
import uk.ac.ebi.quickgo.ontology.model.ECOTerm;
import uk.ac.ebi.quickgo.ontology.model.GOTerm;
import uk.ac.ebi.quickgo.ontology.service.converter.ECODocConverter;
import uk.ac.ebi.quickgo.ontology.service.converter.GODocConverter;
import uk.ac.ebi.quickgo.ontology.service.search.SearchServiceConfig;
import uk.ac.ebi.quickgo.ontology.traversal.OntologyGraphTraversal;
import uk.ac.ebi.quickgo.ontology.traversal.read.OntologyGraphConfig;
import uk.ac.ebi.quickgo.rest.search.QueryStringSanitizer;
import uk.ac.ebi.quickgo.rest.search.SolrQueryStringSanitizer;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * Spring configuration for the service layer, which depends on the repositories
 * made available by {@link OntologyRepoConfig} and {@link SearchServiceConfig}. Services
 * to additionally make accessible are defined in specified the {@link ComponentScan} packages.
 *
 * Created 19/11/15
 * @author Edd
 */
@Configuration
@ComponentScan({"uk.ac.ebi.quickgo.ontology.service"})
@Import({OntologyRepoConfig.class, OntologyGraphConfig.class})
public class ServiceConfig {
    @Bean
    public OntologyService<GOTerm> goOntologyService(OntologyRepository ontologyRepository, OntologyGraphTraversal ontologyGraphTraversal) {
        return new OntologyServiceImpl<>(
                ontologyRepository,
                goDocumentConverter(),
                OntologyType.GO,
                queryStringSanitizer(),
                ontologyGraphTraversal);
    }

    private GODocConverter goDocumentConverter() {
        return new GODocConverter();
    }

    @Bean
    public OntologyService<ECOTerm> ecoOntologyService(OntologyRepository ontologyRepository, OntologyGraphTraversal ontologyGraphTraversal) {
        return new OntologyServiceImpl<>(
                ontologyRepository,
                ecoDocConverter(),
                OntologyType.ECO,
                queryStringSanitizer(),
                ontologyGraphTraversal);
    }

    private ECODocConverter ecoDocConverter() {
        return new ECODocConverter();
    }

    private QueryStringSanitizer queryStringSanitizer() {
        return new SolrQueryStringSanitizer();
    }
}

@@ -160,16 +160,148 @@
 sitory;%0A
+import uk.ac.ebi.quickgo.ontology.common.coterm.CoTermRepoConfig;%0Aimport uk.ac.ebi.quickgo.ontology.common.coterm.CoTermRepository;%0A
 import u
@@ -1593,16 +1593,40 @@
 ig.class
+, CoTermRepoConfig.class
 %7D)%0Apubli
@@ -1742,32 +1742,44 @@
 ologyRepository,
+%0A           
  OntologyGraphTr
@@ -1800,32 +1800,67 @@
 gyGraphTraversal
+, CoTermRepository coTermRepository
 ) %7B%0A        retu
@@ -2067,32 +2067,66 @@
 gyGraphTraversal
+,%0A                coTermRepository
 );%0A    %7D%0A%0A    pr
@@ -2592,18 +2592,67 @@
 raversal
-);
+,%0A                emptyCoTermRepository());  //todo
 %0A    %7D%0A%0A
@@ -2854,11 +2854,237 @@
 );%0A    %7D
+%0A%0A    private CoTermRepository emptyCoTermRepository()%7B%0A        return (id, type, limit, thresholdLimit) -%3E %7B%0A            throw new IllegalStateException(%22The method 'findCoTerms' is not valid for ECO Terms%22);%0A        %7D;%0A    %7D
 %0A%7D%0A

Add co-occurring terms lookup classes to the OntologyService constructor.