This is an automated email from the ASF dual-hosted git repository.
markap14 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 39aa106943 NIFI-14016 Resolved issue for onPropertyModified() where
oldValue was always null (#9560)
39aa106943 is described below
commit 39aa10694317cd4279bdc4cb6a45e68b997640f6
Author: NissimShiman <[email protected]>
AuthorDate: Tue Dec 3 15:34:09 2024 +0000
NIFI-14016 Resolved issue for onPropertyModified() where oldValue was
always null (#9560)
NIFI-14016 Resolved issue for onPropertyModified() where oldValue was
always null (#9560)
---
.../nifi/controller/AbstractComponentNode.java | 3 ++-
.../nifi/controller/TestAbstractComponentNode.java | 31 ++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractComponentNode.java
b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractComponentNode.java
index 89bf5156d1..0a2f5f2e8a 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractComponentNode.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractComponentNode.java
@@ -555,10 +555,11 @@ public abstract class AbstractComponentNode implements
ComponentNode {
// Keep setProperty/removeProperty private so that all calls go through
setProperties
private void setProperty(final PropertyDescriptor descriptor, final
PropertyConfiguration propertyConfiguration, final Function<PropertyDescriptor,
PropertyConfiguration> valueToCompareFunction) {
+ final PropertyConfiguration propertyModComparisonValue =
valueToCompareFunction.apply(descriptor);
+
// Remove current PropertyDescriptor to force updated instance
references
final PropertyConfiguration removed = properties.remove(descriptor);
- final PropertyConfiguration propertyModComparisonValue =
valueToCompareFunction.apply(descriptor);
properties.put(descriptor, propertyConfiguration);
final String effectiveValue =
propertyConfiguration.getEffectiveValue(getParameterContext());
final String resolvedValue = resolveAllowableValue(effectiveValue,
descriptor);
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestAbstractComponentNode.java
b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestAbstractComponentNode.java
index 1d2116debe..40d72fb8aa 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestAbstractComponentNode.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestAbstractComponentNode.java
@@ -306,6 +306,37 @@ public class TestAbstractComponentNode {
assertFalse(updatedPropertyDescriptor.isSensitive());
}
+ @Test
+ public void testSetPropertiesPropertyModified() {
+ final String propertyValueModified = PROPERTY_VALUE + "-modified";
+ final List<PropertyModification> propertyModifications = new
ArrayList<>();
+ final AbstractComponentNode node = new LocalComponentNode() {
+ @Override
+ protected void onPropertyModified(final PropertyDescriptor
descriptor, final String oldValue, final String newValue) {
+ propertyModifications.add(new PropertyModification(descriptor,
oldValue, newValue));
+ super.onPropertyModified(descriptor, oldValue, newValue);
+ }
+ };
+
+ final Map<String, String> properties = new HashMap<>();
+ properties.put(PROPERTY_NAME, PROPERTY_VALUE);
+ node.setProperties(properties);
+
+ assertEquals(1, propertyModifications.size());
+ PropertyModification mod = propertyModifications.get(0);
+ assertNull(mod.getPreviousValue());
+ assertEquals(PROPERTY_VALUE, mod.getUpdatedValue());
+ propertyModifications.clear();
+
+ properties.put(PROPERTY_NAME, propertyValueModified);
+ node.setProperties(properties);
+
+ assertEquals(1, propertyModifications.size());
+ mod = propertyModifications.get(0);
+ assertEquals(PROPERTY_VALUE, mod.getPreviousValue());
+ assertEquals(propertyValueModified, mod.getUpdatedValue());
+ }
+
@Test
public void testSetPropertiesSensitiveDynamicPropertyNames() {
final AbstractComponentNode node = new LocalComponentNode();