This is an automated email from the ASF dual-hosted git repository.

pvillard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new e19efa6658 NIFI-10095 Use Allowable Value Display Name for Default 
Value when found
e19efa6658 is described below

commit e19efa6658d798d5f29cd92688286d9cbde2c572
Author: exceptionfactory <[email protected]>
AuthorDate: Mon Jun 6 15:03:37 2022 -0500

    NIFI-10095 Use Allowable Value Display Name for Default Value when found
    
    Signed-off-by: Pierre Villard <[email protected]>
    
    This closes #6103.
---
 .../documentation/html/HtmlDocumentationWriter.java | 21 ++++++++++++++++++++-
 .../example/FullyDocumentedProcessor.java           |  4 ++--
 .../html/ProcessorDocumentationWriterTest.java      |  4 ++++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlDocumentationWriter.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlDocumentationWriter.java
index d78f2899de..c086cc2f63 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlDocumentationWriter.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlDocumentationWriter.java
@@ -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.
      *
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java
index d4fdb1280b..66a17526f6 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java
@@ -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();
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java
index 617de73d67..94130ce575 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java
@@ -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");
 

Reply via email to