-
Notifications
You must be signed in to change notification settings - Fork 3k
NIFI-15931: Fetching parameter values in the Connector canvas. #11263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1620,8 +1620,7 @@ public ParameterDTO createParameterDto(final ParameterContext parameterContext, | |
| final Set<AffectedComponentEntity> referencingComponentEntities = createAffectedComponentEntities(referencingComponents, revisionManager); | ||
| dto.setReferencingComponents(referencingComponentEntities); | ||
|
|
||
| final ParameterContext containingParameterContext = (parameter.getParameterContextId() == null) | ||
| ? parameterContext : parameterContextLookup.getParameterContext(parameter.getParameterContextId()); | ||
| final ParameterContext containingParameterContext = resolveContainingParameterContext(parameterContext, parameter, parameterContextLookup); | ||
|
|
||
| dto.setInherited(!containingParameterContext.getIdentifier().equals(parameterContext.getIdentifier())); | ||
|
|
||
|
|
@@ -1631,6 +1630,51 @@ public ParameterDTO createParameterDto(final ParameterContext parameterContext, | |
| return dto; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the {@link ParameterContext} where the given parameter was originally defined. | ||
| * | ||
| * <p>For parameters declared directly on the current context (or whose source id matches the current | ||
| * context's identifier), the current context is returned without consulting any external lookup. For | ||
| * inherited parameters, the source context is found by walking the in-memory inheritance graph reachable | ||
| * from the current context via {@link ParameterContext#getInheritedParameterContexts()}. Only if the | ||
| * source context is not reachable on that graph (which is expected only for legacy callers that pass a | ||
| * registry-backed lookup) does the provided {@link ParameterContextLookup} get consulted as a fallback.</p> | ||
| */ | ||
| private ParameterContext resolveContainingParameterContext(final ParameterContext parameterContext, final Parameter parameter, | ||
| final ParameterContextLookup parameterContextLookup) { | ||
| final String sourceId = parameter.getParameterContextId(); | ||
| if (sourceId == null || sourceId.equals(parameterContext.getIdentifier())) { | ||
| return parameterContext; | ||
| } | ||
|
|
||
| final ParameterContext fromGraph = findInheritedParameterContext(parameterContext, sourceId, new HashSet<>()); | ||
| if (fromGraph != null) { | ||
| return fromGraph; | ||
| } | ||
|
|
||
| return parameterContextLookup.getParameterContext(sourceId); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested fix — guard the return value: final ParameterContext result = parameterContextLookup.getParameterContext(sourceId);
return result != null ? result : parameterContext;Falling back to |
||
| } | ||
|
|
||
| private ParameterContext findInheritedParameterContext(final ParameterContext parameterContext, final String sourceId, final Set<String> visited) { | ||
| if (parameterContext == null || !visited.add(parameterContext.getIdentifier())) { | ||
| return null; | ||
| } | ||
| if (sourceId.equals(parameterContext.getIdentifier())) { | ||
| return parameterContext; | ||
| } | ||
| final List<ParameterContext> inherited = parameterContext.getInheritedParameterContexts(); | ||
| if (inherited == null) { | ||
| return null; | ||
| } | ||
| for (final ParameterContext inheritedContext : inherited) { | ||
| final ParameterContext match = findInheritedParameterContext(inheritedContext, sourceId, visited); | ||
| if (match != null) { | ||
| return match; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| public ReportingTaskDTO createReportingTaskDto(final ReportingTaskNode reportingTaskNode) { | ||
| final BundleCoordinate bundleCoordinate = reportingTaskNode.getBundleCoordinate(); | ||
| final List<Bundle> compatibleBundles = extensionManager.getBundles(reportingTaskNode.getCanonicalClassName()).stream().filter(bundle -> { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: "now resolves" is patch-relative — it describes the code relative to what it used to do rather than its permanent contract. Comments should explain the invariant, not the change (those belong in the commit message).
Suggested rewrite: