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