You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2019/09/06 15:29:33 UTC

[nifi] branch master updated: NIFI-6380: Fixed partial updates to parameters

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4868308  NIFI-6380: Fixed partial updates to parameters
4868308 is described below

commit 4868308fd8e3e630c8dfaa9c418aa64f1f8a74b4
Author: Mark Payne <ma...@hotmail.com>
AuthorDate: Wed Sep 4 11:48:56 2019 -0400

    NIFI-6380: Fixed partial updates to parameters
    
    This closes #3692
---
 .../nifi/parameter/StandardParameterContext.java   | 46 +++++++++++++++++++++-
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java
index 04cfb8a..ecd8cfa 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java
@@ -112,8 +112,10 @@ public class StandardParameterContext implements ParameterContext {
                     parameters.remove(parameterDescriptor);
                     changeAffectingComponents = true;
                 } else {
-                    final Parameter oldParameter = parameters.put(parameter.getDescriptor(), parameter);
-                    if (oldParameter == null || !Objects.equals(oldParameter.getValue(), parameter.getValue())) {
+                    final Parameter updatedParameter = createFullyPopulatedParameter(parameter);
+
+                    final Parameter oldParameter = parameters.put(updatedParameter.getDescriptor(), updatedParameter);
+                    if (oldParameter == null || !Objects.equals(oldParameter.getValue(), updatedParameter.getValue())) {
                         changeAffectingComponents = true;
                     }
                 }
@@ -133,6 +135,46 @@ public class StandardParameterContext implements ParameterContext {
         }
     }
 
+    /**
+     * When updating a Parameter, the provided 'updated' Parameter may or may not contain a value. This is done because once a Parameter is set,
+     * a user may want to change the description of the Parameter but cannot include the value of the Parameter in the request if the Parameter is sensitive (because
+     * the value of the Parameter, when retrieved, is masked for sensitive Parameters). As a result, a call may be made to {@link #setParameters(Map)} that includes
+     * a Parameter whose value is <code>null</code>. If we encounter this, we do not want to change the value of the Parameter, so we want to insert into our Map
+     * a Parameter object whose value is equal to the current value for that Parameter (if any). This method, then, takes a Parameter whose value may or may not be
+     * populated and returns a Parameter whose value is populated, if there is an appropriate value to populate it with.
+     *
+     * @param proposedParameter the proposed parameter
+     * @return a Parameter whose descriptor is the same as the given proposed parameter but whose value has been populated based on the existing value for that Parameter (if any)
+     * if the given proposed parameter does not have its value populated
+     */
+    private Parameter createFullyPopulatedParameter(final Parameter proposedParameter) {
+        final ParameterDescriptor descriptor = getFullyPopulatedDescriptor(proposedParameter);
+        final String value = getFullyPopulatedValue(proposedParameter);
+        return new Parameter(descriptor, value);
+    }
+
+    private String getFullyPopulatedValue(final Parameter proposedParameter) {
+        if (proposedParameter.getValue() != null) {
+            return proposedParameter.getValue();
+        }
+
+        final Parameter oldParameter = parameters.get(proposedParameter.getDescriptor());
+        return oldParameter == null ? null : oldParameter.getValue();
+    }
+
+    private ParameterDescriptor getFullyPopulatedDescriptor(final Parameter proposedParameter) {
+        final ParameterDescriptor descriptor = proposedParameter.getDescriptor();
+        if (descriptor.getDescription() != null) {
+            return descriptor;
+        }
+
+        final Parameter oldParameter = parameters.get(proposedParameter.getDescriptor());
+
+        // We know that the Parameters have the same name, since this is what the Descriptor's hashCode & equality are based on. The only thing that may be different
+        // is the description. And since the proposed Parameter does not have a Description, we want to use whatever is currently set.
+        return oldParameter == null ? null : oldParameter.getDescriptor();
+    }
+
     @Override
     public long getVersion() {
         readLock.lock();