class MatchingKeyVaultConfigsForKeyDataValidator implements ConstraintValidator<MatchingKeyVaultConfigsForKeyData, KeyConfiguration> {

    @Override
    public boolean isValid(KeyConfiguration keyConfiguration, ConstraintValidatorContext cvc) {

        // return true so that only NotNull annotation creates violation
        if (keyConfiguration == null) {
            return true;
        }

        List<Boolean> outcomes =
                Stream.of(KeyVaultType.values())
                        .filter(k -> {
                            if (Optional.ofNullable(keyConfiguration.getKeyData()).isPresent()) {
                                return keyConfiguration.getKeyData().stream()
                                    .map(KeyDataUtil::getKeyPairTypeFor)
                                    .anyMatch(keyType -> Objects.equals(k.getKeyPairType(),keyType));
                            }
                            return false;
                        })
                        .filter(k -> !keyConfiguration.getKeyVaultConfig(k).isPresent())
                        .map(
                                k -> {
                                    cvc.disableDefaultConstraintViolation();
                                    String messageKey =
                                            String.format(
                                                    "{MatchingKeyVaultConfigsForKeyData.%s.message}",
                                                    k.name().toLowerCase());
                                    cvc.buildConstraintViolationWithTemplate(messageKey).addConstraintViolation();
                                    return false;
                                })
                        .collect(Collectors.toList());

        return outcomes.isEmpty();
    }

}