NIFI-10095 Use Allowable Value Display Name for Default Value when found

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #6103.
This commit is contained in:
exceptionfactory 2022-06-06 15:03:37 -05:00 committed by Pierre Villard
parent 2455ba2c45
commit e19efa6658
No known key found for this signature in database
GPG Key ID: F92A93B30C07C6D5
3 changed files with 26 additions and 3 deletions

View File

@ -516,7 +516,7 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
}
xmlStreamWriter.writeEndElement();
writeSimpleElement(xmlStreamWriter, "td", property.getDefaultValue(), false, "default-value");
writeSimpleElement(xmlStreamWriter, "td", getDefaultValue(property), false, "default-value");
xmlStreamWriter.writeStartElement("td");
xmlStreamWriter.writeAttribute("id", "allowable-values");
writeValidValues(xmlStreamWriter, property);
@ -674,6 +674,25 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
}
}
private String getDefaultValue(final PropertyDescriptor propertyDescriptor) {
final String defaultValue;
final String descriptorDefaultValue = propertyDescriptor.getDefaultValue();
final List<AllowableValue> allowableValues = propertyDescriptor.getAllowableValues();
if (allowableValues != null) {
defaultValue = allowableValues.stream()
.filter(allowableValue -> allowableValue.getValue().equals(descriptorDefaultValue))
.findFirst()
.map(AllowableValue::getDisplayName)
.orElse(descriptorDefaultValue);
} else {
defaultValue = descriptorDefaultValue;
}
return defaultValue;
}
/**
* Indicates whether or not the component contains at least one sensitive property.
*

View File

@ -89,8 +89,8 @@ public class FullyDocumentedProcessor extends AbstractProcessor {
.description("Indicates whether or not to pull files from subdirectories")
.required(true)
.allowableValues(
new AllowableValue("true", "true", "Should pull from sub directories"),
new AllowableValue("false", "false", "Should not pull from sub directories")
new AllowableValue("true", "Enabled", "Should pull from sub directories"),
new AllowableValue("false", "Disabled", "Should not pull from sub directories")
)
.defaultValue("true")
.build();

View File

@ -94,6 +94,10 @@ public class ProcessorDocumentationWriterTest {
assertContains(results, "Supports Expression Language: true (will be evaluated using variable registry only)");
assertContains(results, "Supports Expression Language: true (undefined scope)");
// Check Property Values
assertContains(results, "Enabled");
assertContains(results, "0 sec");
// verify dynamic properties
assertContains(results, "Routes FlowFiles to relationships based on XPath");