@Test public final void test_isValidEnums_happyPath() { List<RangerEnumDef> input = _utils.createEnumDefs(enums_good); assertTrue(_validator.isValidEnums(input, _failures)); assertTrue(_failures.isEmpty()); }
boolean isValidEnums(List<RangerEnumDef> enumDefs, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidEnums(%s, %s)", enumDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(enumDefs)) { LOG.debug("enum def collection passed in was null/empty. Ok."); } else { Set<String> names = new HashSet<>(); Set<Long> ids = new HashSet<>(); for (RangerEnumDef enumDef : enumDefs) { if (enumDef == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NULL_OBJECT; failures.add(new ValidationFailureDetailsBuilder() .field("enum def") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage()) .build()); valid = false; } else { String enumName = enumDef.getName(); valid = isUnique(enumName, names, "enum def name", "enum defs", failures) && valid; valid = isUnique(enumDef.getItemId(), ids, "enum def itemId", "enum defs", failures) && valid; if (CollectionUtils.isEmpty(enumDef.getElements())) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NO_VALUES; failures.add(new ValidationFailureDetailsBuilder() .field("enum values") .subField(enumName) .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(enumName)) .build()); valid = false; } else { valid = isValidEnumElements(enumDef.getElements(), failures, enumName) && valid; int defaultIndex = getEnumDefaultIndex(enumDef); if (defaultIndex < 0 || defaultIndex >= enumDef.getElements().size()) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_INVALID_DEFAULT_INDEX; failures.add(new ValidationFailureDetailsBuilder() .field("enum default index") .subField(enumName) .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(defaultIndex, enumName)) .build()); valid = false; } } } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidEnums(%s, %s): %s", enumDefs, failures, valid)); } return valid; }
RangerServiceDefValidator extends RangerValidator { boolean isValidEnums(List<RangerEnumDef> enumDefs, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidEnums(%s, %s)", enumDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(enumDefs)) { LOG.debug("enum def collection passed in was null/empty. Ok."); } else { Set<String> names = new HashSet<>(); Set<Long> ids = new HashSet<>(); for (RangerEnumDef enumDef : enumDefs) { if (enumDef == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NULL_OBJECT; failures.add(new ValidationFailureDetailsBuilder() .field("enum def") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage()) .build()); valid = false; } else { String enumName = enumDef.getName(); valid = isUnique(enumName, names, "enum def name", "enum defs", failures) && valid; valid = isUnique(enumDef.getItemId(), ids, "enum def itemId", "enum defs", failures) && valid; if (CollectionUtils.isEmpty(enumDef.getElements())) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NO_VALUES; failures.add(new ValidationFailureDetailsBuilder() .field("enum values") .subField(enumName) .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(enumName)) .build()); valid = false; } else { valid = isValidEnumElements(enumDef.getElements(), failures, enumName) && valid; int defaultIndex = getEnumDefaultIndex(enumDef); if (defaultIndex < 0 || defaultIndex >= enumDef.getElements().size()) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_INVALID_DEFAULT_INDEX; failures.add(new ValidationFailureDetailsBuilder() .field("enum default index") .subField(enumName) .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(defaultIndex, enumName)) .build()); valid = false; } } } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidEnums(%s, %s): %s", enumDefs, failures, valid)); } return valid; } }
RangerServiceDefValidator extends RangerValidator { boolean isValidEnums(List<RangerEnumDef> enumDefs, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidEnums(%s, %s)", enumDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(enumDefs)) { LOG.debug("enum def collection passed in was null/empty. Ok."); } else { Set<String> names = new HashSet<>(); Set<Long> ids = new HashSet<>(); for (RangerEnumDef enumDef : enumDefs) { if (enumDef == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NULL_OBJECT; failures.add(new ValidationFailureDetailsBuilder() .field("enum def") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage()) .build()); valid = false; } else { String enumName = enumDef.getName(); valid = isUnique(enumName, names, "enum def name", "enum defs", failures) && valid; valid = isUnique(enumDef.getItemId(), ids, "enum def itemId", "enum defs", failures) && valid; if (CollectionUtils.isEmpty(enumDef.getElements())) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NO_VALUES; failures.add(new ValidationFailureDetailsBuilder() .field("enum values") .subField(enumName) .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(enumName)) .build()); valid = false; } else { valid = isValidEnumElements(enumDef.getElements(), failures, enumName) && valid; int defaultIndex = getEnumDefaultIndex(enumDef); if (defaultIndex < 0 || defaultIndex >= enumDef.getElements().size()) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_INVALID_DEFAULT_INDEX; failures.add(new ValidationFailureDetailsBuilder() .field("enum default index") .subField(enumName) .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(defaultIndex, enumName)) .build()); valid = false; } } } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidEnums(%s, %s): %s", enumDefs, failures, valid)); } return valid; } RangerServiceDefValidator(ServiceStore store); }
RangerServiceDefValidator extends RangerValidator { boolean isValidEnums(List<RangerEnumDef> enumDefs, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidEnums(%s, %s)", enumDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(enumDefs)) { LOG.debug("enum def collection passed in was null/empty. Ok."); } else { Set<String> names = new HashSet<>(); Set<Long> ids = new HashSet<>(); for (RangerEnumDef enumDef : enumDefs) { if (enumDef == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NULL_OBJECT; failures.add(new ValidationFailureDetailsBuilder() .field("enum def") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage()) .build()); valid = false; } else { String enumName = enumDef.getName(); valid = isUnique(enumName, names, "enum def name", "enum defs", failures) && valid; valid = isUnique(enumDef.getItemId(), ids, "enum def itemId", "enum defs", failures) && valid; if (CollectionUtils.isEmpty(enumDef.getElements())) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NO_VALUES; failures.add(new ValidationFailureDetailsBuilder() .field("enum values") .subField(enumName) .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(enumName)) .build()); valid = false; } else { valid = isValidEnumElements(enumDef.getElements(), failures, enumName) && valid; int defaultIndex = getEnumDefaultIndex(enumDef); if (defaultIndex < 0 || defaultIndex >= enumDef.getElements().size()) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_INVALID_DEFAULT_INDEX; failures.add(new ValidationFailureDetailsBuilder() .field("enum default index") .subField(enumName) .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(defaultIndex, enumName)) .build()); valid = false; } } } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidEnums(%s, %s): %s", enumDefs, failures, valid)); } return valid; } RangerServiceDefValidator(ServiceStore store); void validate(final RangerServiceDef serviceDef, final Action action); boolean isValidResources(RangerServiceDef serviceDef, List<ValidationFailureDetails> failures, final Action action); }
RangerServiceDefValidator extends RangerValidator { boolean isValidEnums(List<RangerEnumDef> enumDefs, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidEnums(%s, %s)", enumDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(enumDefs)) { LOG.debug("enum def collection passed in was null/empty. Ok."); } else { Set<String> names = new HashSet<>(); Set<Long> ids = new HashSet<>(); for (RangerEnumDef enumDef : enumDefs) { if (enumDef == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NULL_OBJECT; failures.add(new ValidationFailureDetailsBuilder() .field("enum def") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage()) .build()); valid = false; } else { String enumName = enumDef.getName(); valid = isUnique(enumName, names, "enum def name", "enum defs", failures) && valid; valid = isUnique(enumDef.getItemId(), ids, "enum def itemId", "enum defs", failures) && valid; if (CollectionUtils.isEmpty(enumDef.getElements())) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NO_VALUES; failures.add(new ValidationFailureDetailsBuilder() .field("enum values") .subField(enumName) .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(enumName)) .build()); valid = false; } else { valid = isValidEnumElements(enumDef.getElements(), failures, enumName) && valid; int defaultIndex = getEnumDefaultIndex(enumDef); if (defaultIndex < 0 || defaultIndex >= enumDef.getElements().size()) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_INVALID_DEFAULT_INDEX; failures.add(new ValidationFailureDetailsBuilder() .field("enum default index") .subField(enumName) .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(defaultIndex, enumName)) .build()); valid = false; } } } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidEnums(%s, %s): %s", enumDefs, failures, valid)); } return valid; } RangerServiceDefValidator(ServiceStore store); void validate(final RangerServiceDef serviceDef, final Action action); boolean isValidResources(RangerServiceDef serviceDef, List<ValidationFailureDetails> failures, final Action action);  }