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

import com.google.common.base.Preconditions;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 Logger logger = LoggerFactory.getLogger(this.getClass());

    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;
    }

    /**
     * {@inheritDoc}
     *
     * Note: This implementation looks first at the {@link InternalFilterExecutionConfig} and then at
     * {@link ExternalFilterExecutionConfig} to find the required field.
     *
     * @param fieldName the name of the field
     * @return an Optional containing the correct {@link FieldExecutionConfig} or an empty Optional if no config is
     * found for the given field.
     */
    @Override public Optional<FieldExecutionConfig> getField(String fieldName) {
    @Override public Optional<FieldExecutionConfig> getConfig(String fieldName) {
        Preconditions.checkArgument(fieldName != null && !fieldName.trim().isEmpty(),
                "Field name cannot be null or empty");

        Optional<FieldExecutionConfig> internalConfig = internalExecutionConfig.getField(fieldName);
        Optional<FieldExecutionConfig> externalConfig = externalExecutionConfig.getField(fieldName);
        Optional<FieldExecutionConfig> config = internalExecutionConfig.getConfig(fieldName);

        Optional<FieldExecutionConfig> config;

        if(internalConfig.isPresent() && externalConfig.isPresent()) {
            logger.warn("Both the internal and external execution configurators contain definitions for the field: {}" +
                    ". Will choose internal config over external config.");
            config = internalConfig;
        } else if(internalConfig.isPresent()) {
            config = internalConfig;
        } else {
            config = externalConfig;
        if (!config.isPresent()) {
            config = externalExecutionConfig.getConfig(fieldName);
        }

        return config;
    }
}

@@ -116,65 +116,8 @@
 al;%0A
-import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 impo
@@ -541,85 +541,8 @@
 g %7B%0A
-    private final Logger logger = LoggerFactory.getLogger(this.getClass());%0A%0A
     
@@ -1242,511 +1242,8 @@
  %7D%0A%0A
-    /**%0A     * %7B@inheritDoc%7D%0A     *%0A     * Note: This implementation looks first at the %7B@link InternalFilterExecutionConfig%7D and then at%0A     * %7B@link ExternalFilterExecutionConfig%7D to find the required field.%0A     *%0A     * @param fieldName the name of the field%0A     * @return an Optional containing the correct %7B@link FieldExecutionConfig%7D or an empty Optional if no config is%0A     * found for the given field.%0A     */%0A    @Override public Optional%3CFieldExecutionConfig%3E getField(String fieldName) %7B%0A
     
@@ -1466,210 +1466,8 @@
 );%0A%0A
-        Optional%3CFieldExecutionConfig%3E internalConfig = internalExecutionConfig.getField(fieldName);%0A        Optional%3CFieldExecutionConfig%3E externalConfig = externalExecutionConfig.getField(fieldName);%0A
     
@@ -1566,505 +1566,17 @@
     
-   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        if
  (!c
@@ -1592,24 +1592,28 @@
 resent()) %7B%0A
+    
             
@@ -1667,16 +1667,20 @@
 dName);%0A
+    
         

Remove changes from Master.