package uk.ac.ebi.quickgo.client.service.loader.presets;

import uk.ac.ebi.quickgo.rest.search.RetrievalException;
import uk.ac.ebi.quickgo.rest.search.request.FilterRequest;
import uk.ac.ebi.quickgo.rest.search.request.converter.ConvertedFilter;
import uk.ac.ebi.quickgo.rest.search.request.converter.RESTFilterConverterFactory;

import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Simple to use implementation to retrieve values from an external restful service.
 */
public class RestValuesRetriever {
    private static final Logger LOGGER = LoggerFactory.getLogger(RestValuesRetriever.class);
    private final RESTFilterConverterFactory converterFactory;

    public RestValuesRetriever(RESTFilterConverterFactory restConverterFactory) {
        this.converterFactory = restConverterFactory;
    }

    /**
     * Retrieve values identified by the lookup key from an external source.
     * @param <T> the type of the return value.
     * @param lookupKey the value used as the identifier for the looked up values.
     * @return a set of retrieved values.
     */
    public <T> Optional<T> retrieveValues(String lookupKey) {
        FilterRequest restRequest = FilterRequest.newBuilder().addProperty(lookupKey).build();
        try {
            ConvertedFilter<T> convertedFilter = converterFactory.convert(restRequest);
            return Optional.of(convertedFilter.getConvertedValue());
        } catch (RetrievalException | IllegalStateException e) {
            LOGGER.error(String.format("Failed to retrieve values for %s via REST", lookupKey), e);
        }
        return Optional.empty();
    }
}

@@ -324,16 +324,42 @@
 ctory;%0A%0A
+import java.util.Objects;%0A
 import j
@@ -435,16 +435,83 @@
 ctory;%0A%0A
+import static com.google.common.base.Preconditions.checkArgument;%0A%0A
 /**%0A * S
@@ -1254,24 +1254,139 @@
 ookupKey) %7B%0A
+        checkArgument(Objects.nonNull(lookupKey), %22The lookupKey passed to the RestValuesRetriever is %22 + %22null%22);%0A
         Filt

Add check for null argument to retrieveValues().