001package model.validation;
002
003
004import model.entity.Ban;
005import model.repository.GenericRepository;
006
007import javax.inject.Inject;
008import javax.validation.ConstraintValidator;
009import javax.validation.ConstraintValidatorContext;
010
011public class BanExistsValidator implements ConstraintValidator<BanExists, Integer> {
012    @Inject GenericRepository genericRepository;
013
014    @Override
015    public void initialize(BanExists constraintAnnotation) {
016
017    }
018
019    @Override
020    public boolean isValid(Integer value, ConstraintValidatorContext context) {
021        if(value==null) return true;
022        return (genericRepository.findById(Ban.class, value) != null);
023    }
024}