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;

import static uk.ac.ebi.quickgo.rest.search.filter.JoinFilterConverter.createJoinConverterUsingMap;

/**
 * Implementation of the {@link FilterConverterFactory} interface.
 *
 * This class knows which implementation of the {@link FilterConverter} is needed to convert a {@link RequestFilter}
 * into a {@link uk.ac.ebi.quickgo.rest.search.query.QuickGOQuery}.
 *
 * @author Ricardo Antunes
 */
@Component
public class FilterConverterFactoryImpl implements FilterConverterFactory {
    private final FilterExecutionConfig globalFilterExecutionConfig;

    @Autowired
    public FilterConverterFactoryImpl(FilterExecutionConfig globalFilterExecutionConfig) {
        this.globalFilterExecutionConfig = globalFilterExecutionConfig;
    }

    @Override public FilterConverter createConverter(RequestFilter requestFilter) {
        Preconditions.checkArgument(requestFilter != null, "RequestFilter can not be null");

        Optional<FieldExecutionConfig> fieldOpt = globalFilterExecutionConfig.getField(requestFilter.getField());

        return fieldOpt.map(field -> createConverter(requestFilter, field))
                .orElseThrow(() -> new IllegalArgumentException("Unable to process request filter: " + requestFilter));
    }

    /**
     * Creates the appropriate {@link FilterConverter} for the given {@link RequestFilter} based on the processing
     * information of the provided by the {@link uk.ac.ebi.quickgo.rest.search.filter.FilterExecutionConfig}.
     *
     * @param field holds details about the search field and how to execute it
     * @param filter the filter that will be converted
     * @return a {@link FilterConverter} capable of processing the {@param filter}
     */
    private FilterConverter createConverter(RequestFilter filter, FieldExecutionConfig field) {
        FilterConverter filterConverter;

        switch (field.getExecution()) {
            case SIMPLE:
                filterConverter = new SimpleFilterConverter(filter);
                break;
            case JOIN:
                filterConverter = createJoinConverterUsingMap(field.getProperties(),
                        new SimpleFilterConverter(filter)); break;
            case REST_COMM:
                throw new RuntimeException("REST_COMM: Functionality not Implemented yet");
            default:
                throw new RuntimeException("Unrecognized ExecutionType: " + field.getExecution());
        }

        return filterConverter;
    }
}
@@ -225,16 +225,113 @@
 onent;%0A%0A
+import static uk.ac.ebi.quickgo.rest.search.filter.FieldExecutionConfig.ExecutionType.REST_COMM;%0A
 import s
@@ -2481,16 +2481,32 @@
 ilter));
+%0A               
  break;%0A
@@ -2576,17 +2576,16 @@
 ception(
-%22
 REST_COM
@@ -2585,16 +2585,20 @@
 EST_COMM
+ + %22
 : Functi

Change the message in the REST_COMM exception to use the enum instead of the string "REST_COMM".