NIFI-4782: Allow the value of a Required Property to be moved when changing 
version of a flow or reverting a flow

This closes #2406.

Signed-off-by: Bryan Bende <bbe...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/4d14368d
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/4d14368d
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/4d14368d

Branch: refs/heads/HDF-3.1-maint
Commit: 4d14368d1d3940b0e11d28f542e1ca2e6c1d861f
Parents: fbc4ec3
Author: Mark Payne <marka...@hotmail.com>
Authored: Tue Jan 16 12:36:52 2018 -0500
Committer: Matt Gilman <matt.c.gil...@gmail.com>
Committed: Tue Jan 16 15:03:46 2018 -0500

----------------------------------------------------------------------
 .../nifi/controller/AbstractConfiguredComponent.java    | 12 ++++++++----
 .../org/apache/nifi/controller/ConfiguredComponent.java |  6 +++++-
 .../org/apache/nifi/groups/StandardProcessGroup.java    |  8 ++++++--
 3 files changed, 19 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/4d14368d/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java
index ff5a8af..a5f2631 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractConfiguredComponent.java
@@ -151,7 +151,7 @@ public abstract class AbstractConfiguredComponent 
implements ConfigurableCompone
     }
 
     @Override
-    public void setProperties(Map<String, String> properties) {
+    public void setProperties(final Map<String, String> properties, final 
boolean allowRemovalOfRequiredProperties) {
         if (properties == null) {
             return;
         }
@@ -170,7 +170,7 @@ public abstract class AbstractConfiguredComponent 
implements ConfigurableCompone
                     }
 
                     if (entry.getKey() != null && entry.getValue() == null) {
-                        removeProperty(entry.getKey());
+                        removeProperty(entry.getKey(), 
allowRemovalOfRequiredProperties);
                     } else if (entry.getKey() != null) {
                         setProperty(entry.getKey(), 
CharacterFilterUtils.filterInvalidXmlCharacters(entry.getValue()));
                     }
@@ -231,17 +231,20 @@ public abstract class AbstractConfiguredComponent 
implements ConfigurableCompone
      * 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) {
+    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);
         String value = null;
-        if (!descriptor.isRequired() && (value = 
properties.remove(descriptor)) != null) {
+
+        final boolean allowRemoval = allowRemovalOfRequiredProperties || 
!descriptor.isRequired();
+        if (allowRemoval && (value = properties.remove(descriptor)) != null) {
 
             if (descriptor.getControllerServiceDefinition() != null) {
                 if (value != null) {
@@ -541,6 +544,7 @@ public abstract class AbstractConfiguredComponent 
implements ConfigurableCompone
         }
     }
 
+    @Override
     public ComponentVariableRegistry getVariableRegistry() {
         return this.variableRegistry;
     }

http://git-wip-us.apache.org/repos/asf/nifi/blob/4d14368d/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/ConfiguredComponent.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/ConfiguredComponent.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/ConfiguredComponent.java
index 940ac21..b0f65a7 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/ConfiguredComponent.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/ConfiguredComponent.java
@@ -50,7 +50,11 @@ public interface ConfiguredComponent extends 
ComponentAuthorizable {
 
     public void setAnnotationData(String data);
 
-    public void setProperties(Map<String, String> properties);
+    public default void setProperties(Map<String, String> properties) {
+        setProperties(properties, false);
+    }
+
+    public void setProperties(Map<String, String> properties, boolean 
allowRemovalOfRequiredProperties);
 
     public Map<PropertyDescriptor, String> getProperties();
 

http://git-wip-us.apache.org/repos/asf/nifi/blob/4d14368d/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
index baf02bc..15f2b5f 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
@@ -3925,7 +3925,9 @@ public final class StandardProcessGroup implements 
ProcessGroup {
         service.setAnnotationData(proposed.getAnnotationData());
         service.setComments(proposed.getComments());
         service.setName(proposed.getName());
-        service.setProperties(populatePropertiesMap(service.getProperties(), 
proposed.getProperties(), proposed.getPropertyDescriptors(), 
service.getProcessGroup()));
+
+        final Map<String, String> properties = 
populatePropertiesMap(service.getProperties(), proposed.getProperties(), 
proposed.getPropertyDescriptors(), service.getProcessGroup());
+        service.setProperties(properties, true);
 
         if (!isEqual(service.getBundleCoordinate(), proposed.getBundle())) {
             final BundleCoordinate newBundleCoordinate = 
toCoordinate(proposed.getBundle());
@@ -4045,7 +4047,9 @@ public final class StandardProcessGroup implements 
ProcessGroup {
         
processor.setExecutionNode(ExecutionNode.valueOf(proposed.getExecutionNode()));
         processor.setName(proposed.getName());
         processor.setPenalizationPeriod(proposed.getPenaltyDuration());
-        
processor.setProperties(populatePropertiesMap(processor.getProperties(), 
proposed.getProperties(), proposed.getPropertyDescriptors(), 
processor.getProcessGroup()));
+
+        final Map<String, String> properties = 
populatePropertiesMap(processor.getProperties(), proposed.getProperties(), 
proposed.getPropertyDescriptors(), processor.getProcessGroup());
+        processor.setProperties(properties, true);
         processor.setRunDuration(proposed.getRunDurationMillis(), 
TimeUnit.MILLISECONDS);
         processor.setScheduldingPeriod(proposed.getSchedulingPeriod());
         
processor.setSchedulingStrategy(SchedulingStrategy.valueOf(proposed.getSchedulingStrategy()));

Reply via email to