package uk.ac.ebi.quickgo.rest.search.filter;

import com.google.common.base.Preconditions;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Holds the definitions of both the {@link InternalFilterExecutionConfig} and the
 * {@link ExternalFilterExecutionConfig}. It is then capable of providing information for all types of fields.
 *
 * @author Ricardo Antunes
 */
@Component class GlobalFilterExecutionConfig implements FilterExecutionConfig {
    private final InternalFilterExecutionConfig internalExecutionConfig;
    private final ExternalFilterExecutionConfig externalExecutionConfig;

    @Autowired
    public GlobalFilterExecutionConfig(InternalFilterExecutionConfig internalExecutionConfig,
            ExternalFilterExecutionConfig externalExecutionConfig) {
        Preconditions.checkArgument(internalExecutionConfig != null, "InternalExecutionConfiguration cannot be null.");
        Preconditions.checkArgument(externalExecutionConfig != null, "ExternalExecutionConfiguration cannot be null.");

        this.internalExecutionConfig = internalExecutionConfig;
        this.externalExecutionConfig = externalExecutionConfig;
    }

    @Override public Optional<FieldExecutionConfig> getConfig(String fieldName) {
        Preconditions.checkArgument(fieldName != null && !fieldName.trim().isEmpty(),
                "Field name cannot be null or empty");

        Optional<FieldExecutionConfig> config = internalExecutionConfig.getConfig(fieldName);

            if (!config.isPresent()) {
                config = externalExecutionConfig.getConfig(fieldName);
            }

        return config;
    }
}

@@ -112,16 +112,73 @@
 tional;%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import o
@@ -594,16 +594,93 @@
 onfig %7B%0A
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());%0A%0A
     priv
@@ -1635,17 +1635,25 @@
 Config%3E 
-c
+internalC
 onfig = 
@@ -1698,25 +1698,24 @@
 dName);%0A
-%0A
         
     if (
@@ -1710,108 +1710,593 @@
     
-    if (!config.isPresent()) %7B%0A                config = externalExecutionConfig.getConfig(fieldName)
+Optional%3CFieldExecutionConfig%3E externalConfig = externalExecutionConfig.getConfig(fieldName);%0A%0A        Optional%3CFieldExecutionConfig%3E config;%0A%0A        if(internalConfig.isPresent() && externalConfig.isPresent()) %7B%0A            logger.warn(%22Both the internal and external execution configurators contain definitions for the field: %7B%7D%22 +%0A                    %22. Will choose internal config over external config.%22);%0A            config = internalConfig;%0A        %7D else if(internalConfig.isPresent()) %7B%0A            config = internalConfig;%0A        %7D else %7B%0A            config = externalConfig
 ;%0A  

Put back previous modification added to master, removed when merged Filter-By-Aspect branch.