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

import java.util.Arrays;
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[]> {
    public static final String DEFAULT_ERROR_MESSAGE = "The 'Gene Product ID' parameter contains invalid values: %s";

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

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

    @Override public boolean isValid(String[] geneProducts, ConstraintValidatorContext context) {
        boolean isValid = true;

        if (geneProducts != null) {
            String invalidGpIds = Arrays.stream(geneProducts)
                    .filter(idValidator.negate())
                    .collect(Collectors.joining(", "));

            if (!invalidGpIds.isEmpty()) {
                isValid = false;

                context.disableDefaultConstraintViolation();
                context.buildConstraintViolationWithTemplate(String.format(DEFAULT_ERROR_MESSAGE, invalidGpIds))
                        .addConstraintViolation();
            }
        }

        return isValid;
    }
}
@@ -1389,30 +1389,34 @@
     
-boolean isValid = true
+String invalidGpIds = null
 ;%0A%0A 
@@ -1454,39 +1454,32 @@
 ) %7B%0A            
-String 
 invalidGpIds = A
@@ -1659,42 +1659,8 @@
 ) %7B%0A
-                isValid = false;%0A%0A
     
@@ -1921,22 +1921,61 @@
 return i
-sValid
+nvalidGpIds == null %7C%7C invalidGpIds.isEmpty()
 ;%0A    %7D%0A

Remove isValid flag, and use invalidGpIds to check if there are invalid GPs.