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