public CredentialsStrategy selectPrimaryStrategy(final ValidationContext validationContext) { final Map<PropertyDescriptor, String> properties = validationContext.getProperties(); return selectPrimaryStrategy(properties); }
public CredentialsStrategy selectPrimaryStrategy(final ValidationContext validationContext) { final Map<PropertyDescriptor, String> properties = validationContext.getProperties(); return selectPrimaryStrategy(properties); }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final boolean containsDynamic = validationContext.getProperties().keySet().stream() .anyMatch(property -> property.isDynamic()); if (containsDynamic) { return Collections.emptyList(); } return Collections.singleton(new ValidationResult.Builder() .subject("User-defined Properties") .valid(false) .explanation("At least one RecordPath must be specified") .build()); }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final boolean hasDynamic = validationContext.getProperties().keySet().stream() .anyMatch(prop -> prop.isDynamic()); if (hasDynamic) { return Collections.emptyList(); } return Collections.singleton(new ValidationResult.Builder() .subject("User-defined Properties") .valid(false) .explanation("At least one RecordPath must be added to this processor by adding a user-defined property") .build()); }
@Override protected Collection<ValidationResult> customValidate(ValidationContext validationContext) { Set<ValidationResult> results = new HashSet<>(); boolean strict = validationContext.getProperty(VALIDATE_FIELD_NAMES).asBoolean(); // Iterate over dynamic properties, validating the schemas, and adding results validationContext.getProperties().entrySet().stream().filter(entry -> entry.getKey().isDynamic()).forEach(entry -> { String subject = entry.getKey().getDisplayName(); String input = entry.getValue(); try { final Schema avroSchema = new Schema.Parser().setValidate(strict).parse(input); AvroTypeUtil.createSchema(avroSchema, input, SchemaIdentifier.EMPTY); } catch (final Exception e) { results.add(new ValidationResult.Builder() .input(input) .subject(subject) .valid(false) .explanation("Not a valid Avro Schema: " + e.getMessage()) .build()); } }); return results; }
/** * Custom validation for ensuring exactly one of Script File or Script Body is populated * * @param validationContext provides a mechanism for obtaining externally * managed values, such as property values and supplies convenience methods * for operating on those values * @return A collection of validation results */ public Collection<ValidationResult> customValidate(ValidationContext validationContext) { Set<ValidationResult> results = new HashSet<>(); // Verify that exactly one of "script file" or "script body" is set Map<PropertyDescriptor, String> propertyMap = validationContext.getProperties(); if (StringUtils.isEmpty(propertyMap.get(ScriptingComponentUtils.SCRIPT_FILE)) == StringUtils.isEmpty(propertyMap.get(ScriptingComponentUtils.SCRIPT_BODY))) { results.add(new ValidationResult.Builder().subject("Script Body or Script File").valid(false).explanation( "exactly one of Script File or Script Body must be set").build()); } return results; }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { boolean pathSpecified = false; for (final PropertyDescriptor property : validationContext.getProperties().keySet()) { if (property.isDynamic()) { pathSpecified = true; break; } } if (pathSpecified) { return Collections.emptyList(); } return Collections.singleton(new ValidationResult.Builder() .subject("JSON Paths") .valid(false) .explanation("No JSON Paths were specified") .build()); }
@Override @SuppressWarnings("unchecked") protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final Set<String> dynamicPropNames = validationContext.getProperties().keySet().stream() .filter(prop -> prop.isDynamic()) .map(prop -> prop.getName())
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final List<ValidationResult> results = new ArrayList<>(); if (validationContext.getProperty(TRANSLATE_CONTENT).asBoolean().equals(Boolean.FALSE)) { boolean foundDynamic = false; for (final PropertyDescriptor descriptor : validationContext.getProperties().keySet()) { if (descriptor.isDynamic()) { foundDynamic = true; break; } } if (!foundDynamic) { results.add(new ValidationResult.Builder().subject("Text to translate").input("<none>").valid(false) .explanation("Must either set 'Translate Content' to true or add at least one user-defined property").build()); } } return results; }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext context) { final List<ValidationResult> results = new ArrayList<>(super.customValidate(context)); final String destination = context.getProperty(DESTINATION).getValue(); if (DESTINATION_CONTENT.equals(destination)) { int xpathCount = 0; for (final PropertyDescriptor desc : context.getProperties().keySet()) { if (desc.isDynamic()) { xpathCount++; } } if (xpathCount != 1) { results.add(new ValidationResult.Builder().subject("XPaths").valid(false) .explanation("Exactly one XPath must be set if using destination of " + DESTINATION_CONTENT).build()); } } return results; }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext context) { final List<ValidationResult> results = new ArrayList<>(super.customValidate(context)); final String destination = context.getProperty(DESTINATION).getValue(); if (DESTINATION_CONTENT.equals(destination)) { int jsonPathCount = 0; for (final PropertyDescriptor desc : context.getProperties().keySet()) { if (desc.isDynamic()) { jsonPathCount++; } } if (jsonPathCount != 1) { results.add(new ValidationResult.Builder().subject("JsonPaths").valid(false) .explanation("Exactly one JsonPath must be set if using destination of " + DESTINATION_CONTENT).build()); } } return results; }
@Override protected Collection<ValidationResult> customValidate(ValidationContext validationContext) { final List<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext)); Validator validator = new RecordPathValidator(); Map<PropertyDescriptor, String> processorProperties = validationContext.getProperties(); for (final Map.Entry<PropertyDescriptor, String> entry : processorProperties.entrySet()) { PropertyDescriptor property = entry.getKey(); if (property.isDynamic() && property.isExpressionLanguageSupported()) { String dynamicValue = validationContext.getProperty(property).getValue(); if(!validationContext.isExpressionLanguagePresent(dynamicValue)) { results.add(validator.validate(property.getDisplayName(), dynamicValue, validationContext)); } } } return results; }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext context) { final List<ValidationResult> results = new ArrayList<>(super.customValidate(context)); final String destination = context.getProperty(DESTINATION).getValue(); if (DESTINATION_CONTENT.equals(destination)) { int xQueryCount = 0; for (final PropertyDescriptor desc : context.getProperties().keySet()) { if (desc.isDynamic()) { xQueryCount++; } } if (xQueryCount != 1) { results.add(new ValidationResult.Builder().subject("XQueries").valid(false) .explanation("Exactly one XQuery must be set if using destination of " + DESTINATION_CONTENT).build()); } } return results; }
@Override protected Collection<ValidationResult> customValidate(ValidationContext validationContext) { final List<ValidationResult> errors = new ArrayList<>(super.customValidate(validationContext)); final Set<PropertyDescriptor> dynamicProperties = validationContext.getProperties().keySet().stream() .filter(prop -> prop.isDynamic()) .collect(Collectors.toSet()); if (dynamicProperties == null || dynamicProperties.size() < 1) { errors.add(new ValidationResult.Builder() .subject("User-Defined Properties") .valid(false) .explanation("At least one user-defined property must be specified.") .build()); } final Set<String> requiredKeys = validationContext.getProperty(LOOKUP_SERVICE).asControllerService(LookupService.class).getRequiredKeys(); if (requiredKeys == null || requiredKeys.size() != 1) { errors.add(new ValidationResult.Builder() .subject(LOOKUP_SERVICE.getDisplayName()) .valid(false) .explanation("LookupAttribute requires a key-value lookup service supporting exactly one required key.") .build()); } return errors; }
@Override protected Collection<ValidationResult> customValidate(ValidationContext context) { final Collection<ValidationResult> results = new ArrayList<>(); final boolean isUserNameSet = context.getProperty(USER_NAME).isSet(); final boolean isUserPasswordSet = context.getProperty(USER_PASSWORD).isSet(); if ((isUserNameSet && !isUserPasswordSet) || (!isUserNameSet && isUserPasswordSet)) { results.add(new ValidationResult.Builder() .subject("User Name and Password") .explanation("Both User Name and Password are required to use.") .build()); } final boolean isBucketPasswordSet = context.getProperties().keySet().stream() .anyMatch(p -> p.isDynamic() && p.getName().startsWith(DYNAMIC_PROP_BUCKET_PASSWORD)); if (isUserNameSet && isUserPasswordSet && isBucketPasswordSet) { results.add(new ValidationResult.Builder() .subject("Authentication methods") .explanation("Different authentication methods can not be used at the same time," + " Use either one of User Name and Password, or Bucket Password.") .build()); } return results; }
@Override protected Collection<ValidationResult> customValidate(ValidationContext context) { final List<ValidationResult> results = new ArrayList<>(); int numDefinedServices = 0; for (final PropertyDescriptor descriptor : context.getProperties().keySet()) { if (descriptor.isDynamic()) { numDefinedServices++; } final String referencedId = context.getProperty(descriptor).getValue(); if (this.getIdentifier().equals(referencedId)) { results.add(new ValidationResult.Builder() .subject(descriptor.getDisplayName()) .explanation("the current service cannot be registered as a DBCPService to lookup") .valid(false) .build()); } } if (numDefinedServices == 0) { results.add(new ValidationResult.Builder() .subject(this.getClass().getSimpleName()) .explanation("at least one DBCPService must be defined via dynamic properties") .valid(false) .build()); } return results; }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final boolean cache = validationContext.getProperty(CACHE_SCHEMA).asBoolean(); if (cache) { for (final PropertyDescriptor descriptor : validationContext.getProperties().keySet()) { if (descriptor.isDynamic() && validationContext.isExpressionLanguagePresent(validationContext.getProperty(descriptor).getValue())) { return Collections.singleton(new ValidationResult.Builder() .subject("Cache Schema") .input("true") .valid(false) .explanation("Cannot have 'Cache Schema' property set to true if any SQL statement makes use of the Expression Language") .build()); } } } return Collections.emptyList(); }
results.addAll(validateStore(validationContext.getProperties(), KeystoreValidationGroup.KEYSTORE)); results.addAll(validateStore(validationContext.getProperties(), KeystoreValidationGroup.TRUSTSTORE));
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final List<ValidationResult> problems = new ArrayList<>(super.customValidate(validationContext)); // If the capture group zero is not going to be included, each dynamic property must have at least one group final boolean includeCaptureGroupZero = validationContext.getProperty(INCLUDE_CAPTURE_GROUP_ZERO).getValue().equalsIgnoreCase("true"); getLogger().debug("Include capture group zero is " + includeCaptureGroupZero); if (!includeCaptureGroupZero) { final Validator oneGroupMinimumValidator = StandardValidators.createRegexValidator(1, 40, true); for (Map.Entry<PropertyDescriptor, String> prop : validationContext.getProperties().entrySet()) { PropertyDescriptor pd = prop.getKey(); if (pd.isDynamic()) { String value = validationContext.getProperty(pd).getValue(); getLogger().debug("Evaluating dynamic property " + pd.getDisplayName() + " (" + pd.getName() + ") with value " + value); ValidationResult result = oneGroupMinimumValidator.validate(pd.getDisplayName(), value, validationContext); getLogger().debug("Validation result: " + result.toString()); if (!result.isValid()) { problems.add(result); } } } } return problems; }
Map<PropertyDescriptor, String> allProperties = validationContext.getProperties(); for (final PropertyDescriptor descriptor : allProperties.keySet()) { if (descriptor.isDynamic()) {