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