/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.harvard.iq.dataverse;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import org.apache.commons.validator.routines.EmailValidator;

/**
 *
 * @author skraffmi
 */
public class EMailValidator implements ConstraintValidator<ValidateEmail, String> {

    @Override
    public void initialize(ValidateEmail constraintAnnotation) {

    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        
        return isEmailValid(value, context);

        
    }
    
    public static boolean isEmailValid(String value, ConstraintValidatorContext context){
            boolean isValid= EmailValidator.getInstance().isValid(value.trim());        
            if (!isValid) {
                context.buildConstraintViolationWithTemplate( value + " is not a valid email address.").addConstraintViolation();
                return false;
            }
        
        
        return true;
        
    }
}

@@ -831,22 +831,144 @@
 context)
+ 
 %7B%0A    
+    if (value == null) %7B%0A            //we'll let someone else decide if it's required%0A            return true;%0A        %7D%0A
         
@@ -982,16 +982,17 @@
  isValid
+ 
 = EmailV
@@ -1040,26 +1040,17 @@
 ());
-        %0A 
+%0A
         
    i
@@ -1041,27 +1041,24 @@
 ));%0A        
-   
 if (!isValid
@@ -1073,20 +1073,16 @@
         
-   
- 
 context.
@@ -1118,17 +1118,16 @@
 emplate(
- 
 value + 
@@ -1194,28 +1194,24 @@
             
-   
- 
 return false
@@ -1224,32 +1224,10 @@
     
-    
 %7D%0A
-        %0A        %0A
     
@@ -1243,25 +1243,16 @@
 n true;%0A
-        %0A
     %7D%0A%7D%0A

Allow null email to pass EmailValidator