package uk.ac.ebi.quickgo.annotation.validation.service;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import org.springframework.beans.factory.annotation.Autowired;

import static uk.ac.ebi.quickgo.annotation.validation.service.DbCrossReferenceId.db;

/**
 * Validate the reference values used to filter annotations.
 * There is a limited list of databases that can be used as the database portion of the identifier, defined within
 * this class.
 *
 * @author Tony Wardell
 * Date: 10/11/2016
 * Time: 13:22
 * Created with IntelliJ IDEA.
 */
public class ReferenceValuesValidation implements ConstraintValidator<ReferenceValidator, String[]> {

    private final ValidationEntityChecker validator;

    @Autowired
    public ReferenceValuesValidation(ValidationEntityChecker validator) {
        this.validator = validator;
    }

    private final List<String> referenceDatabases = Arrays.asList("pmid","doi","go_ref","reactome");

    @Override public void initialize(ReferenceValidator constraintAnnotation) {}

    @Override public boolean isValid(String[] values, ConstraintValidatorContext context) {
        return values == null || Stream.of(values).allMatch(this::isValid);
    }

    private boolean isValid(String value){
        if(Objects.isNull(value)){
            return false;
        }

        if (value.trim().isEmpty()) {
            return false;
        }

        if (!value.contains(":")) {
            return true;
        }

        if (!referenceDatabases.contains(db(value))) {
            return false;
        }

        return validator.isValid(value);
    }
}

@@ -62,48 +62,76 @@
 ort 
-java.util.Arrays;%0Aimport java.util.List;
+uk.ac.ebi.quickgo.annotation.validation.model.ValidationProperties;%0A
 %0Aimp
@@ -344,16 +344,98 @@
 towired;
+%0Aimport org.springframework.boot.context.properties.EnableConfigurationProperties;
 %0A%0Aimport
@@ -806,16 +806,75 @@
 EA.%0A */%0A
+@EnableConfigurationProperties(ValidationProperties.class)%0A
 public c
@@ -1020,16 +1020,81 @@
 lidator;
+%0A    private final ValidationProperties validationLoadProperties;
 %0A%0A    @A
@@ -1172,16 +1172,63 @@
 alidator
+, ValidationProperties validationLoadProperties
 ) %7B%0A    
@@ -1267,111 +1267,75 @@
     
-%7D%0A%0A
     
-private final List%3CString%3E referenceDatabases = Arrays.asList(%22pmid%22,%22doi%22,%22go_ref%22,%22reactome%22);
+this.validationLoadProperties = validationLoadProperties;%0A    %7D
 %0A%0A  
@@ -1864,17 +1864,45 @@
    if (!
-r
+validationLoadProperties.getR
 eference
@@ -1902,24 +1902,20 @@
 ferenceD
-atabases
+bs()
 .contain

Add ValidationProperties to replace hard coded reference dbs.