Interface PropertyConfiguration


public interface PropertyConfiguration
  • Method Details

    • renameProperty

      boolean renameProperty(String propertyName, String newName)
      Renames an existing property, if it exists. If the property does not exist, this is a no-op
      Parameters:
      propertyName - the current name of the property
      newName - the new name for the property
      Returns:
      true if the property was renamed, false if the property did not exist
    • removeProperty

      boolean removeProperty(String propertyName)
      Removes the property with the given name, if it exists. If the property does not exist, this is a no-op.
      Parameters:
      propertyName - the name of the property to remove
      Returns:
      true if the property was removed, false if the property did not exist
    • hasProperty

      boolean hasProperty(String propertyName)

      Determines whether or not the configuration has an entry for the given property. This method will return true even if the value for the given property is null. A value of false will be returned only if the property name is not known to the configuration. This allows for disambiguation between a value that is configured to be null and a value that has not yet been configured.

      An idiom to determine if the property was explicitly set to null is as follows:

      
           final boolean setToNull = configuration.hasProperty("MyProperty") invalid input: '&'invalid input: '&' !configuration.isPropertySet("MyProperty");
       
      Parameters:
      propertyName - the name of the property
      Returns:
      true if the property name is known to this configuration, false otherwise.
    • hasProperty

      default boolean hasProperty(PropertyDescriptor descriptor)

      Determines whether or not the configuration has an entry for the given property. This method will return true even if the value for the given property is null. A value of false will be returned only if the property identified by the descriptor is not known to the configuration. This allows for disambiguation between a value that is configured to be null and a value that has not yet been configured.

      An idiom to determine if the property was explicitly set to null is as follows:

      
           final boolean setToNull = configuration.hasProperty(MY_PROPERTY) invalid input: '&'invalid input: '&' !configuration.isSet(MY_PROPERTY);
       
      Parameters:
      descriptor - the property descriptor that identifies the property
      Returns:
      true if the property name is known to this configuration, false otherwise.
    • isPropertySet

      boolean isPropertySet(String propertyName)
      Indicates whether or not the property with the given name has been set to a non-null value
      Parameters:
      propertyName - the name of the property
      Returns:
      true if the value has been set and is non-null. Returns false if the value is unset or is null
    • isPropertySet

      default boolean isPropertySet(PropertyDescriptor descriptor)
      Indicates whether or not the property identified by the given descriptor name has been set to a non-null value
      Parameters:
      descriptor - the descriptor that identifies the property
      Returns:
      true if the value has been set and is non-null. Returns false if the value is unset or is null
    • setProperty

      void setProperty(String propertyName, String propertyValue)
      Sets the value of the property with the given name and value
      Parameters:
      propertyName - the name of the property
      propertyValue - the value to set
    • setProperty

      default void setProperty(PropertyDescriptor descriptor, String propertyValue)
      Sets the value of the property identified by the given descriptor's name to the given value
      Parameters:
      descriptor - the property descriptor that identifies the property
      propertyValue - the value to set
    • getPropertyValue

      Optional<String> getPropertyValue(String propertyName)
      Returns an optional value representing the value of the property with the given name
      Parameters:
      propertyName - the name of the property
      Returns:
      an empty optional if the value is null or unset, else an Optional representing the configured value
    • getPropertyValue

      default Optional<String> getPropertyValue(PropertyDescriptor descriptor)
      Returns an optional value representing the value of the property identified by the given descriptor
      Parameters:
      descriptor - the property descriptor that identifies the property
      Returns:
      an empty optional if the value is null or unset, else an Optional representing the configured value
    • getRawPropertyValue

      Optional<String> getRawPropertyValue(String propertyName)
      Returns an optional value representing the "raw" value of the property with the given name. The "raw" value is the value before any parameters are substituted.
      Parameters:
      propertyName - the name of the property
      Returns:
      an empty optional if the value is null or unset, else an Optional representing the configured value
    • getRawPropertyValue

      default Optional<String> getRawPropertyValue(PropertyDescriptor descriptor)
      Returns an optional value representing the "raw" value of the property identified by the given descriptor. The "raw" value is the value before any parameters are substituted.
      Parameters:
      descriptor - the descriptor that identifies the property
      Returns:
      an empty optional if the value is null or unset, else an Optional representing the configured value
    • getProperties

      Map<String,String> getProperties()
      Returns a map containing all of the configured properties
      Returns:
      a Map containing the names and values of all configured properties
    • getRawProperties

      Map<String,String> getRawProperties()
      Returns a map containing all of the raw property values
      Returns:
      a Map containing the names and values of all configured properties
    • createControllerService

      String createControllerService(String implementationClassName, Map<String,String> serviceProperties)

      Creates a new Controller Service of the given type and configures it with the given property values. Note that if a Controller Service already exists within the same scope and with the same implementation and configuration, a new service may not be created and instead the existing service may be used.

      This allows for properties that were previously defined in the extension to be moved to a Controller Service. For example, consider a Processor that has "Username" and "Password" properties. In the next version of the Processor, we want to support multiple types of authentication, and we delegate the authentication to a Controller Service. Consider that the Controller Service implementation we wish to use has a classname of org.apache.nifi.services.authentication.UsernamePassword. We might then use this method as such:

      
           // Create a new Controller Service of type org.apache.nifi.services.authentication.UsernamePassword whose Username and Password
           // properties match those currently configured for this Processor.
           final Map<String, String> serviceProperties = Map.of("Username", propertyConfiguration.getRawPropertyValue("Username"),
                "Password", propertyConfiguration.getRawPropertyValue("Password"));
           final String serviceId = propertyConfiguration.createControllerService("org.apache.nifi.services.authentication.UsernamePassword", serviceProperties);
      
           // Set our Authentication Service property to point to this new service.
           propertyConfiguration.setProperty(AUTHENTICATION_SERVICE, serviceId);
      
           // Remove the Username and Password properties from this Processor, since we are now going to use then Authentication Service.
           propertyConfiguration.removeProperty("Username");
           propertyConfiguration.removeProperty("Password");
       

      Note the use of getRawPropertyValue(String) here instead of getPropertyValue(String). Because we want to set the new Controller Service's value to the same value as is currently configured for the Processor's "Username" and "Password" properties, we use getRawPropertyValue(String). This ensures that if the Processor is configured using Parameters, those Parameter references are still held by the Controller Service.

      Also note that this method expects the classname of the implementation, not the classname of the interface.

      Parameters:
      implementationClassName - the fully qualified classname of the Controller Service implementation
      serviceProperties - the property values to configure the newly created Controller Service with
      Returns:
      an identifier for the Controller Service