exceptionfactory commented on code in PR #10844:
URL: https://github.com/apache/nifi/pull/10844#discussion_r2771332159


##########
nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java:
##########
@@ -2173,6 +2188,48 @@ private void updateParameterContext(final ProcessGroup 
group, final VersionedPro
         }
     }
 
+    /**
+     * Finds a parameter context from the parent group hierarchy that 
corresponds to the given versioned
+     * parameter context name. This is used to ensure that when a new child 
process group is added during
+     * a flow version upgrade, it uses the same parameter context as its 
parent (if they both reference
+     * the same parameter context in the versioned flow), rather than looking 
up by name globally which
+     * could result in using a different parameter context with the same base 
name.
+     *
+     * @param group the process group being updated
+     * @param versionedParameterContextName the name of the parameter context 
in the versioned flow
+     * @return the matching parent parameter context, or null if not found
+     */
+    private ParameterContext findMatchingParentParameterContext(final 
ProcessGroup group, final String versionedParameterContextName) {
+        ProcessGroup parent = group.getParent();
+        while (parent != null) {
+            final ParameterContext parentContext = 
parent.getParameterContext();
+            if (parentContext != null) {
+                // Check if the parent's context corresponds to the same 
versioned parameter context name.
+                // The parent's context name might be the exact name or have a 
suffix like " (1)", " (2)", etc.
+                // if it was created during an import with REPLACE strategy.
+                final String parentContextName = parentContext.getName();
+                if (parentContextName.equals(versionedParameterContextName)
+                        || isParameterContextNameWithSuffix(parentContextName, 
versionedParameterContextName)) {
+                    return parentContext;
+                }
+            }
+            parent = parent.getParent();
+        }
+        return null;
+    }
+
+    /**
+     * Checks if the given parameter context name is the versioned name with a 
numeric suffix.
+     * For example, "P (1)" or "P (2)" would match versioned name "P".
+     *
+     * @param contextName the actual parameter context name
+     * @param versionedName the parameter context name from the versioned flow
+     * @return true if contextName is versionedName with a suffix like " (n)"
+     */
+    private boolean isParameterContextNameWithSuffix(final String contextName, 
final String versionedName) {
+        return ParameterContextNameUtils.isNameWithSuffix(contextName, 
versionedName);
+    }

Review Comment:
   This method seems unnecessary, the new Utils method can be called directly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to