Interface PropertyConfiguration
-
Method Summary
Modifier and TypeMethodDescriptioncreateControllerService
(String implementationClassName, Map<String, String> serviceProperties) Creates a new Controller Service of the given type and configures it with the given property values.Returns a map containing all of the configured propertiesgetPropertyValue
(String propertyName) Returns an optional value representing the value of the property with the given namegetPropertyValue
(PropertyDescriptor descriptor) Returns an optional value representing the value of the property identified by the given descriptorReturns a map containing all of the raw property valuesgetRawPropertyValue
(String propertyName) Returns an optional value representing the "raw" value of the property with the given name.getRawPropertyValue
(PropertyDescriptor descriptor) Returns an optional value representing the "raw" value of the property identified by the given descriptor.boolean
hasProperty
(String propertyName) Determines whether or not the configuration has an entry for the given property.default boolean
hasProperty
(PropertyDescriptor descriptor) Determines whether or not the configuration has an entry for the given property.boolean
isPropertySet
(String propertyName) Indicates whether or not the property with the given name has been set to a non-null valuedefault boolean
isPropertySet
(PropertyDescriptor descriptor) Indicates whether or not the property identified by the given descriptor name has been set to a non-null valueboolean
removeProperty
(String propertyName) Removes the property with the given name, if it exists.boolean
renameProperty
(String propertyName, String newName) Renames an existing property, if it exists.void
setProperty
(String propertyName, String propertyValue) Sets the value of the property with the given name and valuedefault void
setProperty
(PropertyDescriptor descriptor, String propertyValue) Sets the value of the property identified by the given descriptor's name to the given value
-
Method Details
-
renameProperty
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 propertynewName
- the new name for the property- Returns:
true
if the property was renamed,false
if the property did not exist
-
removeProperty
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
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 isnull
. A value offalse
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 benull
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
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 isnull
. A value offalse
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 benull
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
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. Returnsfalse
if the value is unset or is null
-
isPropertySet
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. Returnsfalse
if the value is unset or is null
-
setProperty
Sets the value of the property with the given name and value- Parameters:
propertyName
- the name of the propertypropertyValue
- the value to set
-
setProperty
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 propertypropertyValue
- the value to set
-
getPropertyValue
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
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
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
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
Returns a map containing all of the configured properties- Returns:
- a Map containing the names and values of all configured properties
-
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 ofgetPropertyValue(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 usegetRawPropertyValue(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 implementationserviceProperties
- the property values to configure the newly created Controller Service with- Returns:
- an identifier for the Controller Service
-