001package model.validation;
002
003import model.entity.User;
004import model.repository.GenericRepository;
005
006import javax.inject.Inject;
007import javax.validation.ConstraintValidator;
008import javax.validation.ConstraintValidatorContext;
009
010public class UserExistsByNameValidator implements ConstraintValidator<UserExists, String> {
011    @Inject GenericRepository genericRepository;
012
013
014    @Override
015    public void initialize(UserExists userExists) {
016
017    }
018
019    @Override
020    public boolean isValid(String name, ConstraintValidatorContext constraintValidatorContext) {
021        if(name == null) return true;
022        return genericRepository.findByNaturalId(User.class,name) != null;
023    }
024}