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

The following examples show how to use org.apache.nifi.components.PropertyDescriptor#isRequired() . 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: HashAttribute.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    if (descriptor.isRequired()) {
        return;
    }

    final Map<String, Pattern> patternMap = new HashMap<>(regexMapRef.get());
    if (newValue == null) {
        patternMap.remove(descriptor.getName());
    } else {
        if (newValue.equals(".*")) {
            patternMap.put(descriptor.getName(), null);
        } else {
            final Pattern pattern = Pattern.compile(newValue);
            patternMap.put(descriptor.getName(), pattern);
        }
    }

    regexMapRef.set(Collections.unmodifiableMap(patternMap));
}
 
Example 2
Source File: HashAttribute.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    if (descriptor.isRequired()) {
        return;
    }

    final Map<String, Pattern> patternMap = new HashMap<>(regexMapRef.get());
    if (newValue == null) {
        patternMap.remove(descriptor.getName());
    } else {
        if (newValue.equals(".*")) {
            patternMap.put(descriptor.getName(), null);
        } else {
            final Pattern pattern = Pattern.compile(newValue);
            patternMap.put(descriptor.getName(), pattern);
        }
    }

    regexMapRef.set(Collections.unmodifiableMap(patternMap));
}
 
Example 3
Source File: AbstractConfiguredComponent.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the property and value for the given property name if a
 * descriptor and value exists for the given name. If the property is
 * optional its value might be reset to default or will be removed entirely
 * if was a dynamic property.
 *
 * @param name the property to remove
 * @return true if removed; false otherwise
 * @throws java.lang.IllegalArgumentException if the name is null
 */
private boolean removeProperty(final String name) {
    if (null == name) {
        throw new IllegalArgumentException("Name can not be null");
    }

    final PropertyDescriptor descriptor = component.getPropertyDescriptor(name);
    String value = null;
    if (!descriptor.isRequired() && (value = properties.remove(descriptor)) != null) {

        if (descriptor.getControllerServiceDefinition() != null) {
            if (value != null) {
                final ControllerServiceNode oldNode = serviceProvider.getControllerServiceNode(value);
                if (oldNode != null) {
                    oldNode.removeReference(this);
                }
            }
        }

        try {
            component.onPropertyModified(descriptor, value, null);
        } catch (final Exception e) {
            logger.error(e.getMessage(), e);
        }

        return true;
    }

    return false;
}
 
Example 4
Source File: PutKudu.java    From nifi with Apache License 2.0 5 votes vote down vote up
private String getEvaluatedProperty(PropertyDescriptor property, ProcessContext context, FlowFile flowFile) {
    PropertyValue evaluatedProperty = context.getProperty(property).evaluateAttributeExpressions(flowFile);
    if (property.isRequired() && evaluatedProperty == null) {
        throw new ProcessException(String.format("Property `%s` is required but evaluated to null", property.getDisplayName()));
    }
    return evaluatedProperty.getValue();
}
 
Example 5
Source File: CryptographicHashAttribute.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
    if (descriptor.isRequired()) {
        return;
    }

    final Map<String, String> attributeToGeneratedNameMap = new HashMap<>(attributeToGenerateNameMapRef.get());
    if (newValue == null) {
        attributeToGeneratedNameMap.remove(descriptor.getName());
    } else {
        attributeToGeneratedNameMap.put(descriptor.getName(), newValue);
    }

    attributeToGenerateNameMapRef.set(Collections.unmodifiableMap(attributeToGeneratedNameMap));
}
 
Example 6
Source File: AbstractJMSProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void validateLocalConnectionFactoryConfig(List<PropertyDescriptor> localConnectionFactoryProperties, PropertyDescriptor indicatorProperty, List<ValidationResult> results) {
    for (PropertyDescriptor propertyDescriptor : localConnectionFactoryProperties) {
        if (propertyDescriptor.isRequired()) {
            PropertyValue propertyValue = validationContext.getProperty(propertyDescriptor);
            if (!propertyValue.isSet()) {
                results.add(new ValidationResult.Builder()
                        .subject("Connection Factory config")
                        .valid(false)
                        .explanation(String.format("'%s' must be specified when '%s' has been configured.", propertyDescriptor.getDisplayName(), indicatorProperty.getDisplayName()))
                        .build());
            }
        }
    }
}
 
Example 7
Source File: AbstractComponentNode.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the property and value for the given property name if a
 * descriptor and value exists for the given name. If the property is
 * optional its value might be reset to default or will be removed entirely
 * if was a dynamic property.
 *
 * @param name the property to remove
 * @param allowRemovalOfRequiredProperties whether or not the property should be removed if it's required
 * @return true if removed; false otherwise
 * @throws java.lang.IllegalArgumentException if the name is null
 */
private boolean removeProperty(final String name, final boolean allowRemovalOfRequiredProperties) {
    if (null == name) {
        throw new IllegalArgumentException("Name can not be null");
    }

    final PropertyDescriptor descriptor = getComponent().getPropertyDescriptor(name);

    final boolean allowRemoval = allowRemovalOfRequiredProperties || !descriptor.isRequired();
    if (!allowRemoval) {
        return false;
    }

    final PropertyConfiguration propertyConfiguration = properties.remove(descriptor);
    if (propertyConfiguration == null || propertyConfiguration.getRawValue() == null) {
        return false;
    }

    final String value = propertyConfiguration.getEffectiveValue(getParameterContext());
    if (descriptor.getControllerServiceDefinition() != null) {
        if (value != null) {
            final ControllerServiceNode oldNode = serviceProvider.getControllerServiceNode(value);
            if (oldNode != null) {
                oldNode.removeReference(this, descriptor);
            }
        }
    }

    try {
        onPropertyModified(descriptor, value, null);
    } catch (final Exception e) {
        getLogger().error(e.getMessage(), e);
    }

    return true;
}
 
Example 8
Source File: HtmlDocumentationWriter.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Writes the PropertyDescriptors out as a table.
 *
 * @param configurableComponent the component to describe
 * @param xmlStreamWriter the stream writer
 * @throws XMLStreamException thrown if there was a problem writing to the
 * XML Stream
 */
protected void writeProperties(final ConfigurableComponent configurableComponent,
        final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {

    final List<PropertyDescriptor> properties = configurableComponent.getPropertyDescriptors();
    writeSimpleElement(xmlStreamWriter, "h3", "Properties: ");

    if (properties.size() > 0) {
        final boolean containsExpressionLanguage = containsExpressionLanguage(configurableComponent);
        final boolean containsSensitiveProperties = containsSensitiveProperties(configurableComponent);
        xmlStreamWriter.writeStartElement("p");
        xmlStreamWriter.writeCharacters("In the list below, the names of required properties appear in ");
        writeSimpleElement(xmlStreamWriter, "strong", "bold");
        xmlStreamWriter.writeCharacters(". Any other properties (not in bold) are considered optional. " +
                "The table also indicates any default values");
        if (containsExpressionLanguage) {
            if (!containsSensitiveProperties) {
                xmlStreamWriter.writeCharacters(", and ");
            } else {
                xmlStreamWriter.writeCharacters(", ");
            }
            xmlStreamWriter.writeCharacters("whether a property supports the ");
            writeLink(xmlStreamWriter, "NiFi Expression Language", "../../html/expression-language-guide.html");
        }
        if (containsSensitiveProperties) {
            xmlStreamWriter.writeCharacters(", and whether a property is considered " + "\"sensitive\", meaning that its value will be encrypted. Before entering a "
                    + "value in a sensitive property, ensure that the ");

            writeSimpleElement(xmlStreamWriter, "strong", "nifi.properties");
            xmlStreamWriter.writeCharacters(" file has " + "an entry for the property ");
            writeSimpleElement(xmlStreamWriter, "strong", "nifi.sensitive.props.key");
        }
        xmlStreamWriter.writeCharacters(".");
        xmlStreamWriter.writeEndElement();

        xmlStreamWriter.writeStartElement("table");
        xmlStreamWriter.writeAttribute("id", "properties");

        // write the header row
        xmlStreamWriter.writeStartElement("tr");
        writeSimpleElement(xmlStreamWriter, "th", "Name");
        writeSimpleElement(xmlStreamWriter, "th", "Default Value");
        writeSimpleElement(xmlStreamWriter, "th", "Allowable Values");
        writeSimpleElement(xmlStreamWriter, "th", "Description");
        xmlStreamWriter.writeEndElement();

        // write the individual properties
        for (PropertyDescriptor property : properties) {
            xmlStreamWriter.writeStartElement("tr");
            xmlStreamWriter.writeStartElement("td");
            xmlStreamWriter.writeAttribute("id", "name");
            if (property.isRequired()) {
                writeSimpleElement(xmlStreamWriter, "strong", property.getDisplayName());
            } else {
                xmlStreamWriter.writeCharacters(property.getDisplayName());
            }

            xmlStreamWriter.writeEndElement();
            writeSimpleElement(xmlStreamWriter, "td", property.getDefaultValue(), false, "default-value");
            xmlStreamWriter.writeStartElement("td");
            xmlStreamWriter.writeAttribute("id", "allowable-values");
            writeValidValues(xmlStreamWriter, property);
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeStartElement("td");
            xmlStreamWriter.writeAttribute("id", "description");
            if (property.getDescription() != null && property.getDescription().trim().length() > 0) {
                xmlStreamWriter.writeCharacters(property.getDescription());
            } else {
                xmlStreamWriter.writeCharacters("No Description Provided.");
            }

            if (property.isSensitive()) {
                xmlStreamWriter.writeEmptyElement("br");
                writeSimpleElement(xmlStreamWriter, "strong", "Sensitive Property: true");
            }

            if (property.isExpressionLanguageSupported()) {
                xmlStreamWriter.writeEmptyElement("br");
                writeSimpleElement(xmlStreamWriter, "strong", "Supports Expression Language: true");
            }
            xmlStreamWriter.writeEndElement();

            xmlStreamWriter.writeEndElement();
        }

        // TODO support dynamic properties...
        xmlStreamWriter.writeEndElement();

    } else {
        writeSimpleElement(xmlStreamWriter, "p", "This component has no required or optional properties.");
    }
}