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 UniqueSectionNameValidator implements ConstraintValidator<UniqueSection, String> { 011 @Inject GenericRepository genericRepository; 012 013 014 @Override 015 public void initialize(UniqueSection uniqueSection) { 016 017 } 018 019 @Override 020 public boolean isValid(String name, ConstraintValidatorContext constraintValidatorContext) { 021 if(name==null) return true; 022 return genericRepository.findByNaturalId(Section.class, name) == null; 023 } 024}