package uk.ac.ebi.quickgo.common.validator;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Gene product IDs that don't match the regular expressions for recognised/supported gene product types should be
 * rejected with an error; those that do match should be treated as valid (plausible), even if they don't actually
 * identify a gene product in any of the supported databases.
 * The supported databases should be: UniProtKB, RNAcentral, IntAct, and any of the databases that are available in
 * the ID mapping function.
 *
 * @author Tony Wardell
 * Date: 14/06/2016
 * Time: 13:32
 * Created with IntelliJ IDEA.
 */

public class GeneProductIDValidator implements ConstraintValidator<GeneProductIDList, String> {

    @Autowired
    EntityValidation xRefFormats;
    private Predicate<String> idValidator;

    @Override public void initialize(GeneProductIDList constraintAnnotation) {
        idValidator = xRefFormats::isValidId;
    }

    @Override public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        if (s == null) {
            return true;
        }
        List invalidGeneProdIDs = Arrays.stream(s.split(",")).filter(idValidator.negate()).collect
                (Collectors.toList());
        return invalidGeneProdIDs.size() == 0;
    }
}

@@ -1261,35 +1261,16 @@
  con
-straintValidatorCon
 text) %7B%0A
     
@@ -1261,24 +1261,24 @@
  context) %7B%0A
+
         if (
@@ -1337,20 +1337,22 @@
     
-List
+String
  invalid
 Gene
@@ -1347,27 +1347,16 @@
  invalid
-GeneProdIDs
  = Array
@@ -1447,64 +1447,304 @@
 ors.
-toList());%0A        return invalidGeneProdIDs.size() == 0
+joining(%22, %22));%0A%0A        if(invalid == null)%7B%0A            return true;%0A        %7D%0A        context.disableDefaultConstraintViolation();%0A        context.buildConstraintViolationWithTemplate(%22Provided ID: '%22 + invalid + %22' is invalid%22)%0A                .addConstraintViolation();%0A%0A        return false
 ;%0A  

Replace default message with custom message.