Java Code Examples for org.apache.nifi.components.PropertyDescriptor#validate()

The following examples show how to use org.apache.nifi.components.PropertyDescriptor#validate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockProcessContext.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the value of the property with the given PropertyDescriptor to
 * the specified value IF and ONLY IF the value is valid according to the
 * descriptor's validator. Otherwise, the property value is not updated. In
 * either case, the ValidationResult is returned, indicating whether or not
 * the property is valid
 *
 * @param descriptor of property to modify
 * @param value new value
 * @return result
 */
public ValidationResult setProperty(final PropertyDescriptor descriptor, final String value) {
    requireNonNull(descriptor);
    requireNonNull(value, "Cannot set property to null value; if the intent is to remove the property, call removeProperty instead");
    final PropertyDescriptor fullyPopulatedDescriptor = component.getPropertyDescriptor(descriptor.getName());

    final ValidationResult result = fullyPopulatedDescriptor.validate(value, new MockValidationContext(this, stateManager, variableRegistry));
    String oldValue = properties.put(fullyPopulatedDescriptor, value);
    if (oldValue == null) {
        oldValue = fullyPopulatedDescriptor.getDefaultValue();
    }
    if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) {
        component.onPropertyModified(fullyPopulatedDescriptor, oldValue, value);
    }

    return result;
}
 
Example 2
Source File: StandardProcessorTestRunner.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult setProperty(final ControllerService service, final PropertyDescriptor property, final String value) {
    final MockStateManager serviceStateManager = controllerServiceStateManagers.get(service.getIdentifier());
    if (serviceStateManager == null) {
        throw new IllegalStateException("Controller service " + service + " has not been added to this TestRunner via the #addControllerService method");
    }

    final ControllerServiceConfiguration configuration = getConfigToUpdate(service);
    final Map<PropertyDescriptor, String> curProps = configuration.getProperties();
    final Map<PropertyDescriptor, String> updatedProps = new HashMap<>(curProps);

    final ValidationContext validationContext = new MockValidationContext(context, serviceStateManager, variableRegistry).getControllerServiceValidationContext(service);
    final ValidationResult validationResult = property.validate(value, validationContext);

    final String oldValue = updatedProps.get(property);
    updatedProps.put(property, value);
    configuration.setProperties(updatedProps);

    if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) {
        service.onPropertyModified(property, oldValue, value);
    }

    return validationResult;
}
 
Example 3
Source File: MockProcessContext.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the value of the property with the given PropertyDescriptor to
 * the specified value IF and ONLY IF the value is valid according to the
 * descriptor's validator. Otherwise, the property value is not updated. In
 * either case, the ValidationResult is returned, indicating whether or not
 * the property is valid
 *
 * @param descriptor of property to modify
 * @param value new value
 * @return result
 */
public ValidationResult setProperty(final PropertyDescriptor descriptor, final String value) {
    requireNonNull(descriptor);
    requireNonNull(value, "Cannot set property to null value; if the intent is to remove the property, call removeProperty instead");
    final PropertyDescriptor fullyPopulatedDescriptor = component.getPropertyDescriptor(descriptor.getName());

    final ValidationResult result = fullyPopulatedDescriptor.validate(value, new MockValidationContext(this, stateManager, variableRegistry));
    String oldValue = properties.put(fullyPopulatedDescriptor, value);
    if (oldValue == null) {
        oldValue = fullyPopulatedDescriptor.getDefaultValue();
    }
    if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) {
        component.onPropertyModified(fullyPopulatedDescriptor, oldValue, value);
    }

    return result;
}
 
Example 4
Source File: StandardProcessorTestRunner.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult setProperty(final ControllerService service, final PropertyDescriptor property, final String value) {
    final MockStateManager serviceStateManager = controllerServiceStateManagers.get(service.getIdentifier());
    if (serviceStateManager == null) {
        throw new IllegalStateException("Controller service " + service + " has not been added to this TestRunner via the #addControllerService method");
    }

    final ControllerServiceConfiguration configuration = getConfigToUpdate(service);
    final Map<PropertyDescriptor, String> curProps = configuration.getProperties();
    final Map<PropertyDescriptor, String> updatedProps = new HashMap<>(curProps);

    final ValidationContext validationContext = new MockValidationContext(context, serviceStateManager, variableRegistry).getControllerServiceValidationContext(service);
    final ValidationResult validationResult = property.validate(value, validationContext);

    final String oldValue = updatedProps.get(property);
    updatedProps.put(property, value);
    configuration.setProperties(updatedProps);

    if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) {
        service.onPropertyModified(property, oldValue, value);
    }

    return validationResult;
}
 
Example 5
Source File: StatelessControllerServiceLookup.java    From nifi with Apache License 2.0 6 votes vote down vote up
public ValidationResult setControllerServiceProperty(final ControllerService service, final PropertyDescriptor property, final StatelessProcessContext context,
                                                     final VariableRegistry registry, final String value) {
    final StatelessStateManager serviceStateManager = controllerServiceStateManagers.get(service.getIdentifier());
    if (serviceStateManager == null) {
        throw new IllegalStateException("Controller service " + service + " has not been added to this TestRunner via the #addControllerService method");
    }

    final ValidationContext validationContext = new StatelessValidationContext(context, this, serviceStateManager, registry, parameterContext);
    final ValidationResult validationResult = property.validate(value, validationContext);

    final StatelessControllerServiceConfiguration configuration = getControllerServiceConfigToUpdate(service);
    final PropertyConfiguration oldValue = configuration.getProperties().get(property);
    final PropertyConfiguration propertyConfiguration = createPropertyConfiguration(value, property.isExpressionLanguageSupported());
    configuration.setProperty(property, propertyConfiguration);

    if (oldValue == null && value != null) {
        service.onPropertyModified(property, null, value);
    } else if ((value == null && oldValue.getRawValue() != null) || (value != null && !value.equals(oldValue.getRawValue()))) {
        service.onPropertyModified(property, oldValue.getRawValue(), value);
    }

    return validationResult;
}
 
Example 6
Source File: StatelessProcessContext.java    From nifi with Apache License 2.0 6 votes vote down vote up
public ValidationResult setProperty(final PropertyDescriptor descriptor, final String value) {
    if (descriptor == null) {
        throw new IllegalArgumentException("descriptor can not be null");
    }
    if (value == null) {
        throw new IllegalArgumentException("Cannot set property to null value; if the intent is to remove the property, call removeProperty instead");
    }

    final PropertyDescriptor fullyPopulatedDescriptor = component.getPropertyDescriptor(descriptor.getName());

    final ValidationResult result = fullyPopulatedDescriptor.validate(value, new StatelessValidationContext(this, lookup, stateManager, variableRegistry, parameterContext));
    final PropertyConfiguration propertyConfiguration = createPropertyConfiguration(value, fullyPopulatedDescriptor.isExpressionLanguageSupported());

    PropertyConfiguration oldConfig = properties.put(fullyPopulatedDescriptor, propertyConfiguration);
    if (oldConfig == null) {
        oldConfig = createPropertyConfiguration(fullyPopulatedDescriptor.getDefaultValue(), fullyPopulatedDescriptor.isExpressionLanguageSupported());
    }
    if ((value == null && oldConfig != null && oldConfig.getRawValue() != null) || (value != null && !value.equals(oldConfig.getRawValue()))) {
        component.onPropertyModified(fullyPopulatedDescriptor, oldConfig.getEffectiveValue(parameterContext), value);
    }

    return result;
}