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 UsersExistsByIdValidator implements ConstraintValidator<UserExists, Integer> { 011 @Inject GenericRepository genericRepository; 012 013 014 @Override 015 public void initialize(UserExists userExists) { 016 017 } 018 019 @Override 020 public boolean isValid(Integer id, ConstraintValidatorContext constraintValidatorContext) { 021 if(id == null) return true; 022 return genericRepository.findById(User.class, id) != null; 023 } 024}