Class PropertyDescriptor.Builder

java.lang.Object
org.apache.nifi.components.PropertyDescriptor.Builder
Enclosing class:
PropertyDescriptor

public static final class PropertyDescriptor.Builder extends Object
  • Field Details

    • displayName

      private String displayName
    • name

      private String name
    • description

      private String description
    • defaultValue

      private String defaultValue
    • allowableValues

      private List<AllowableValue> allowableValues
    • dependencies

      private Set<PropertyDependency> dependencies
    • required

      private boolean required
    • sensitive

      private boolean sensitive
    • expressionLanguageScope

      private ExpressionLanguageScope expressionLanguageScope
    • dynamic

      private boolean dynamic
    • dynamicallyModifiesClasspath

      private boolean dynamicallyModifiesClasspath
    • controllerServiceDefinition

      private Class<? extends ControllerService> controllerServiceDefinition
    • resourceDefinition

      private ResourceDefinition resourceDefinition
    • validators

      private List<Validator> validators
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • fromPropertyDescriptor

      public PropertyDescriptor.Builder fromPropertyDescriptor(PropertyDescriptor specDescriptor)
    • displayName

      public PropertyDescriptor.Builder displayName(String displayName)
      Sets a unique id for the property. This field is optional and if not specified the PropertyDescriptor's name will be used as the identifying attribute. However, by supplying an id, the PropertyDescriptor's name can be changed without causing problems. This is beneficial because it allows a User Interface to represent the name differently.
      Parameters:
      displayName - of the property
      Returns:
      the builder
    • name

      public PropertyDescriptor.Builder name(String name)
      Sets the property name.
      Parameters:
      name - of the property
      Returns:
      the builder
    • expressionLanguageSupported

      public PropertyDescriptor.Builder expressionLanguageSupported(ExpressionLanguageScope expressionLanguageScope)
      Sets the scope of the expression language evaluation
      Parameters:
      expressionLanguageScope - scope of the expression language evaluation
      Returns:
      the builder
    • description

      public PropertyDescriptor.Builder description(String description)
      Parameters:
      description - of the property
      Returns:
      the builder
    • defaultValue

      public PropertyDescriptor.Builder defaultValue(String value)
      Specifies the initial value and the default value that will be used if the user does not specify a value.

      When build() is called, if Allowable Values have been set (see allowableValues(DescribedValue...) and overloads) and this value is not one of those Allowable Values, an Exception will be thrown. If the Allowable Values have been set, the default value should be set to the "Value" of the DescribedValue object (see DescribedValue.getValue()). There's an overload available for this (see defaultValue(DescribedValue)).

      Parameters:
      value - default value
      Returns:
      the builder
    • defaultValue

      public PropertyDescriptor.Builder defaultValue(DescribedValue value)
      Specifies the initial value and the default value that will be used if the user does not specify a value.

      Sets the default value to the "Value" of the DescribedValue object. When build() is called, if Allowable Values have been set (see allowableValues(DescribedValue...) and overloads) and this value is not one of those Allowable Values, an Exception will be thrown. In case there is not a restricted set of Allowable Values defaultValue(String) may be used.

      Parameters:
      value - default value holder
      Returns:
      the builder
    • clearDefaultValue

      public PropertyDescriptor.Builder clearDefaultValue()
      Clears the initial value and default value from this Property.
      Returns:
      the builder
    • dynamic

      public PropertyDescriptor.Builder dynamic(boolean dynamic)
    • dynamicallyModifiesClasspath

      public PropertyDescriptor.Builder dynamicallyModifiesClasspath(boolean dynamicallyModifiesClasspath)
      Specifies that the value of this property represents one or more resources that the framework should add to the classpath of as well as consider when looking for native libraries for the given component.

      NOTE: If a component contains a PropertyDescriptor where dynamicallyModifiesClasspath is set to true, the component may also be annotated with @RequiresInstanceClassloading, in which case every class will be loaded by a separate InstanceClassLoader for each processor instance.
      It also allows to load native libraries from the extra classpath.

      One can choose to omit the annotation. In this case the loading of native libraries from the extra classpath is not supported. Also by default, classes will be loaded by a common NarClassLoader, however it's possible to acquire an InstanceClassLoader by calling Thread.currentThread().getContextClassLoader() which can be used manually to load required classes on an instance-by-instance basis (by calling Class.forName(String, boolean, ClassLoader) for example).

      Any property descriptor that dynamically modifies the classpath should also make use of the identifiesExternalResource(ResourceCardinality, ResourceType, ResourceType...) method to indicate that the property descriptor references external resources and optionally restrict which types of resources and how many resources the property allows.

      Parameters:
      dynamicallyModifiesClasspath - whether or not this property should be used by the framework to modify the classpath
      Returns:
      the builder
    • allowableValues

      public PropertyDescriptor.Builder allowableValues(Set<String> values)
      Sets the Allowable Values for this Property.
      Parameters:
      values - constrained set of values
      Returns:
      the builder
    • allowableValues

      public <E extends Enum<E>> PropertyDescriptor.Builder allowableValues(E[] values)
      Sets the Allowable Values for this Property.

      Uses the Enum.name() of each value as "Value" for the AllowableValue. In case the enum value is a DescribedValue, uses the information provided instead (see DescribedValue.getValue(), DescribedValue.getDisplayName(), DescribedValue.getDescription()).

      Parameters:
      values - constrained set of values
      Returns:
      the builder
    • allowableValues

      public <E extends Enum<E>> PropertyDescriptor.Builder allowableValues(Class<E> enumClass)
      Sets the Allowable Values for this Property.

      Uses the Enum.name() of each value from Class.getEnumConstants() as "Value" for the AllowableValue. In case the enum value is a DescribedValue, uses the information provided instead (see DescribedValue.getValue(), DescribedValue.getDisplayName(), DescribedValue.getDescription()).

      Type Parameters:
      E - generic parameter for an enum class, that may implement the DescribedValue interface
      Parameters:
      enumClass - an enum class that contains a set of values and optionally implements the DescribedValue interface
      Returns:
      the builder
    • allowableValues

      public <E extends Enum<E>> PropertyDescriptor.Builder allowableValues(EnumSet<E> enumValues)
      Sets the Allowable Values for this Property.

      Uses the Enum.name() of each value of the EnumSet as "Value" for the AllowableValue. In case the enum value is a DescribedValue, uses the information provided instead (see DescribedValue.getValue(), DescribedValue.getDisplayName(), DescribedValue.getDescription()).

      Type Parameters:
      E - generic parameter for an enum class, that may implement the DescribedValue interface
      Parameters:
      enumValues - an enum set that contains a set of values and optionally implements the DescribedValue interface
      Returns:
      the builder
    • allowableValues

      public PropertyDescriptor.Builder allowableValues(String... values)
      Sets the Allowable Values for this Property.
      Parameters:
      values - constrained set of values
      Returns:
      the builder
    • allowableValues

      public PropertyDescriptor.Builder allowableValues(DescribedValue... values)
      Sets the Allowable Values for this Property.

      Uses the information provided by each DescribedValue (see DescribedValue.getValue(), DescribedValue.getDisplayName(), DescribedValue.getDescription()) to populate the AllowableValues.

      Parameters:
      values - constrained set of values
      Returns:
      the builder
    • clearAllowableValues

      public PropertyDescriptor.Builder clearAllowableValues()
      Clears all Allowable Values from this Property
      Returns:
      the builder
    • required

      public PropertyDescriptor.Builder required(boolean required)
      Parameters:
      required - true if yes; false otherwise
      Returns:
      the builder
    • sensitive

      public PropertyDescriptor.Builder sensitive(boolean sensitive)
      Parameters:
      sensitive - true if sensitive; false otherwise
      Returns:
      the builder
    • addValidator

      public PropertyDescriptor.Builder addValidator(Validator validator)
      Parameters:
      validator - for the property
      Returns:
      the builder
    • clearValidators

      public PropertyDescriptor.Builder clearValidators()
      Clear all Validators from this Property
      Returns:
      the builder
    • identifiesControllerService

      public PropertyDescriptor.Builder identifiesControllerService(Class<? extends ControllerService> controllerServiceDefinition)
      Specifies that this property provides the identifier of a Controller Service that implements the given interface
      Parameters:
      controllerServiceDefinition - the interface that is implemented by the Controller Service
      Returns:
      the builder
    • isValueAllowed

      private boolean isValueAllowed(String value)
    • identifiesExternalResource

      public PropertyDescriptor.Builder identifiesExternalResource(ResourceCardinality cardinality, ResourceType resourceType, ResourceType... additionalResourceTypes)
      Specifies that this property references one or more resources that are external to NiFi that the component is meant to consume. Any property descriptor that identifies an external resource will be automatically validated against the following rules:
      • If the ResourceCardinality is SINGLE, the given property value must be a file, a directory, or a URL that uses a protocol of http/https/file.
      • The given resourceTypes dictate which types of input are allowed. For example, if identifiesExternalResource(ResourceCardinality.SINGLE, ResourceType.FILE) is used, the input must be a regular file. If identifiesExternalResource(ResourceCardinality.SINGLE, ResourceType.FILE, ResourceType.DIRECTORY) is used, then the input must be exactly one file OR directory.
      • If the ResourceCardinality is MULTIPLE, the given property value may consist of one or more resources, each separted by a comma and optional white space.

      Generally, any property descriptor that makes use of the dynamicallyModifiesClasspath(boolean) method to dynamically update its classpath should also make use of this method, specifying which types of resources are allowed and how many.

      Parameters:
      cardinality - specifies how many resources the property should allow
      resourceType - the type of resource that is allowed
      additionalResourceTypes - if more than one type of resource is allowed, any resource type in addition to the given resource type may be provided
      Returns:
      the builder
    • dependsOn

      public PropertyDescriptor.Builder dependsOn(PropertyDescriptor property, AllowableValue... dependentValues)
      Establishes a relationship between this Property and the given property by declaring that this Property is only relevant if the given Property has a non-null value. Furthermore, if one or more explicit Allowable Values are provided, this Property will not be relevant unless the given Property's value is equal to one of the given Allowable Values. If this method is called multiple times, each with a different dependency, then a relationship is established such that this Property is relevant only if all dependencies are satisfied.

      In the case that this property is NOT considered to be relevant (meaning that it depends on a property whose value is not specified, or whose value does not match one of the given Allowable Values), the property will not be shown in the component's configuration in the User Interface. Additionally, this property's value will not be considered for validation. That is, if this property is configured with an invalid value and this property depends on Property Foo, and Property Foo does not have a value set, then the component will still be valid, because the value of this property is irrelevant.

      If the given property is not relevant (because its dependencies are not satisfied), this property is also considered not to be valid.

      Parameters:
      property - the property that must be set in order for this property to become relevant
      dependentValues - the possible values for the given property for which this Property is relevant
      Returns:
      the builder
    • dependsOn

      public PropertyDescriptor.Builder dependsOn(PropertyDescriptor property, String firstDependentValue, String... additionalDependentValues)
      Establishes a relationship between this Property and the given property by declaring that this Property is only relevant if the given Property has a value equal to one of the given String arguments. If this method is called multiple times, each with a different dependency, then a relationship is established such that this Property is relevant only if all dependencies are satisfied.

      In the case that this property is NOT considered to be relevant (meaning that it depends on a property whose value is not specified, or whose value does not match one of the given Allowable Values), the property will not be shown in the component's configuration in the User Interface. Additionally, this property's value will not be considered for validation. That is, if this property is configured with an invalid value and this property depends on Property Foo, and Property Foo does not have a value set, then the component will still be valid, because the value of this property is irrelevant.

      If the given property is not relevant (because its dependencies are not satisfied), this property is also considered not to be valid.

      Parameters:
      property - the property that must be set in order for this property to become relevant
      firstDependentValue - the first value for the given property for which this Property is relevant
      additionalDependentValues - any other values for the given property for which this Property is relevant
      Returns:
      the builder
    • dependsOn

      public PropertyDescriptor.Builder dependsOn(PropertyDescriptor property, DescribedValue firstDependentValue, DescribedValue... additionalDependentValues)
      Establishes a relationship between this Property and the given property by declaring that this Property is only relevant if the given Property has a value equal to one of the given DescribedValue arguments. If this method is called multiple times, each with a different dependency, then a relationship is established such that this Property is relevant only if all dependencies are satisfied.

      In the case that this property is NOT considered to be relevant (meaning that it depends on a property whose value is not specified, or whose value does not match one of the given Described Values), the property will not be shown in the component's configuration in the User Interface. Additionally, this property's value will not be considered for validation. That is, if this property is configured with an invalid value and this property depends on Property Foo, and Property Foo does not have a value set, then the component will still be valid, because the value of this property is irrelevant.

      If the given property is not relevant (because its dependencies are not satisfied), this property is also considered not to be valid.

      Parameters:
      property - the property that must be set in order for this property to become relevant
      firstDependentValue - the first value for the given property for which this Property is relevant
      additionalDependentValues - any other values for the given property for which this Property is relevant
      Returns:
      the builder
    • clearDependsOn

      public PropertyDescriptor.Builder clearDependsOn()
      Clear all Dependencies from this Property
      Returns:
      the builder
    • build

      public PropertyDescriptor build()
      Returns:
      a PropertyDescriptor as configured
      Throws:
      IllegalStateException - if allowable values are configured but no default value is set, or the default value is not contained within the allowable values.