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

import uk.ac.ebi.quickgo.common.loader.DbXRefLoader;
import uk.ac.ebi.quickgo.common.validator.DbXRefEntityValidation;
import uk.ac.ebi.quickgo.geneproduct.common.GeneProductRepoConfig;
import uk.ac.ebi.quickgo.geneproduct.common.GeneProductRepository;
import uk.ac.ebi.quickgo.geneproduct.service.converter.GeneProductDocConverter;
import uk.ac.ebi.quickgo.geneproduct.service.converter.GeneProductDocConverterImpl;
import uk.ac.ebi.quickgo.rest.controller.ControllerValidationHelper;
import uk.ac.ebi.quickgo.rest.controller.ControllerValidationHelperImpl;
import uk.ac.ebi.quickgo.rest.search.QueryStringSanitizer;
import uk.ac.ebi.quickgo.rest.search.SolrQueryStringSanitizer;
import uk.ac.ebi.quickgo.rest.service.ServiceHelper;
import uk.ac.ebi.quickgo.rest.service.ServiceHelperImpl;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import static uk.ac.ebi.quickgo.rest.controller.ControllerValidationHelperImpl.MAX_PAGE_RESULTS;

/**
 *
 * Spring configuration for the service layer, which depends on the repositories
 * made available by {@link GeneProductRepoConfig}. Services
 * to additionally make accessible are defined in specified the {@link ComponentScan} packages.
 *
 * @author Tony Wardell
 * Date: 04/04/2016
 * Time: 11:42
 * Created with IntelliJ IDEA.
 */
@Configuration
@ComponentScan({"uk.ac.ebi.quickgo.geneproduct.service"})
@Import({GeneProductRepoConfig.class})
public class ServiceConfig {

    private static final boolean DEFAULT_XREF_VALIDATION_IS_CASE_SENSITIVE = true;
    @Value("${geneproduct.db.xref.valid.casesensitive:"+DEFAULT_XREF_VALIDATION_IS_CASE_SENSITIVE+"}")
    boolean xrefValidationCaseSensitive;
    @Value("${geneproduct.db.xref.valid.regexes}")
    private String xrefValidationRegexFile;

    @Bean
    public GeneProductService goGeneProductService(GeneProductRepository geneProductRepository) {
        return new GeneProductServiceImpl(
                serviceHelper(),
                geneProductRepository,
                geneProductDocConverter());
    }

    @Bean
    public ControllerValidationHelper geneProductValidator() {
        return new ControllerValidationHelperImpl(MAX_PAGE_RESULTS, idValidator());
    }

    private ServiceHelper serviceHelper() {
        return new ServiceHelperImpl(queryStringSanitizer());
    }

    private GeneProductDocConverter geneProductDocConverter() {
        return new GeneProductDocConverterImpl();
    }

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

    private DbXRefEntityValidation idValidator() {
        return DbXRefEntityValidation.createWithData(geneProductLoader().load());
    }

    private DbXRefLoader geneProductLoader() {
        return new DbXRefLoader(this.xrefValidationRegexFile, xrefValidationCaseSensitive);
    }

}

@@ -90,24 +90,80 @@
 XRefLoader;%0A
+import uk.ac.ebi.quickgo.common.validator.DbXRefEntity;%0A
 import uk.ac
@@ -212,24 +212,24 @@
 Validation;%0A
-
 import uk.ac
@@ -889,16 +889,96 @@
 rImpl;%0A%0A
+import java.util.List;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import o
@@ -1837,16 +1837,82 @@
 Config %7B
+%0A    Logger LOGGER = LoggerFactory.getLogger(ServiceConfig.class);
 %0A%0A    pr
@@ -3071,23 +3071,27 @@
         
-return 
+final List%3C
 DbXRefEn
@@ -3086,33 +3086,35 @@
 ist%3CDbXRefEntity
-V
+%3E v
 alidation.create
@@ -3110,50 +3110,273 @@
 tion
-.createWithData(
+List = geneProductLoader().load();%0A        LOGGER.info(%22Here is the contents of the file used for 
 gene
-P
+ p
 roduct
-Loader().load()
+ validation%22);%0A        validationList.stream().forEach(v -%3E LOGGER.info(v.toString()));%0A        return DbXRefEntityValidation.createWithData(validationList
 );%0A 

Add some logging so we see the entries that comprise the validation regexes for gene products.