simonbence commented on a change in pull request #4123: NIFI-7188: Adding
filter capabilities into search & prerequisite refactors
URL: https://github.com/apache/nifi/pull/4123#discussion_r402151889
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerSearchService.java
##########
@@ -16,688 +16,222 @@
*/
package org.apache.nifi.web.controller;
-import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.nifi.authorization.Authorizer;
import org.apache.nifi.authorization.RequestAction;
+import org.apache.nifi.authorization.resource.Authorizable;
import org.apache.nifi.authorization.user.NiFiUser;
-import org.apache.nifi.authorization.user.NiFiUserUtils;
-import org.apache.nifi.components.PropertyDescriptor;
-import org.apache.nifi.components.validation.ValidationStatus;
-import org.apache.nifi.connectable.Connectable;
import org.apache.nifi.connectable.Connection;
import org.apache.nifi.connectable.Funnel;
import org.apache.nifi.connectable.Port;
import org.apache.nifi.controller.FlowController;
import org.apache.nifi.controller.ProcessorNode;
-import org.apache.nifi.controller.ScheduledState;
import org.apache.nifi.controller.label.Label;
-import org.apache.nifi.controller.queue.FlowFileQueue;
import org.apache.nifi.controller.service.ControllerServiceNode;
-import org.apache.nifi.flowfile.FlowFilePrioritizer;
import org.apache.nifi.groups.ProcessGroup;
import org.apache.nifi.groups.RemoteProcessGroup;
-import org.apache.nifi.nar.NarCloseable;
import org.apache.nifi.parameter.Parameter;
import org.apache.nifi.parameter.ParameterContext;
-import org.apache.nifi.parameter.ParameterContextManager;
-import org.apache.nifi.processor.DataUnit;
-import org.apache.nifi.processor.Processor;
-import org.apache.nifi.processor.Relationship;
-import org.apache.nifi.registry.ComponentVariableRegistry;
-import org.apache.nifi.registry.VariableDescriptor;
-import org.apache.nifi.registry.VariableRegistry;
-import org.apache.nifi.remote.PublicPort;
-import org.apache.nifi.scheduling.ExecutionNode;
-import org.apache.nifi.scheduling.SchedulingStrategy;
-import org.apache.nifi.search.SearchContext;
-import org.apache.nifi.search.SearchResult;
-import org.apache.nifi.search.Searchable;
import org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO;
-import org.apache.nifi.web.api.dto.search.SearchResultGroupDTO;
import org.apache.nifi.web.api.dto.search.SearchResultsDTO;
+import org.apache.nifi.web.search.ComponentMatcher;
+import org.apache.nifi.web.search.query.SearchQuery;
+import
org.apache.nifi.web.search.resultenrichment.ComponentSearchResultEnricher;
+import
org.apache.nifi.web.search.resultenrichment.ComponentSearchResultEnricherFactory;
-import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
+import java.util.Optional;
/**
* NiFi web controller's helper service that implements component search.
*/
public class ControllerSearchService {
+ private final static String FILTER_NAME_GROUP = "group";
+ private final static String FILTER_NAME_SCOPE = "scope";
+ private final static String FILTER_SCOPE_VALUE_HERE = "here";
+
private FlowController flowController;
private Authorizer authorizer;
- private VariableRegistry variableRegistry;
+ private ComponentSearchResultEnricherFactory resultEnricherFactory;
+
+ private ComponentMatcher<ProcessorNode> matcherForProcessor;
+ private ComponentMatcher<ProcessGroup> matcherForProcessGroup;
+ private ComponentMatcher<Connection> matcherForConnection;
+ private ComponentMatcher<RemoteProcessGroup> matcherForRemoteProcessGroup;
+ private ComponentMatcher<Port> matcherForPort;
+ private ComponentMatcher<Funnel> matcherForFunnel;
+ private ComponentMatcher<ParameterContext> matcherForParameterContext;
+ private ComponentMatcher<Parameter> matcherForParameter;
+ private ComponentMatcher<Label> matcherForLabel;
+ private ComponentMatcher<ControllerServiceNode>
matcherForControllerServiceNode;
/**
- * Searches term in the controller beginning from a given process group.
+ * Searches all parameter contexts and parameters.
*
+ * @param searchQuery Details of the search
* @param results Search results
- * @param search The search term
- * @param group The init process group
*/
- public void search(final SearchResultsDTO results, final String search,
final ProcessGroup group) {
- final NiFiUser user = NiFiUserUtils.getNiFiUser();
-
- if (group.isAuthorized(authorizer, RequestAction.READ, user)) {
- final ComponentSearchResultDTO groupMatch = search(search, group);
- if (groupMatch != null) {
- // get the parent group, not the current one
- groupMatch.setParentGroup(buildResultGroup(group.getParent(),
user));
-
groupMatch.setVersionedGroup(buildVersionedGroup(group.getParent(), user));
- results.getProcessGroupResults().add(groupMatch);
- }
- }
-
- for (final ProcessorNode procNode : group.getProcessors()) {
- if (procNode.isAuthorized(authorizer, RequestAction.READ, user)) {
- final ComponentSearchResultDTO match = search(search,
procNode);
- if (match != null) {
- match.setGroupId(group.getIdentifier());
- match.setParentGroup(buildResultGroup(group, user));
- match.setVersionedGroup(buildVersionedGroup(group, user));
- results.getProcessorResults().add(match);
- }
- }
- }
-
- for (final Connection connection : group.getConnections()) {
- if (connection.isAuthorized(authorizer, RequestAction.READ, user))
{
- final ComponentSearchResultDTO match = search(search,
connection);
- if (match != null) {
- match.setGroupId(group.getIdentifier());
- match.setParentGroup(buildResultGroup(group, user));
- match.setVersionedGroup(buildVersionedGroup(group, user));
- results.getConnectionResults().add(match);
- }
- }
- }
-
- for (final RemoteProcessGroup remoteGroup :
group.getRemoteProcessGroups()) {
- if (remoteGroup.isAuthorized(authorizer, RequestAction.READ,
user)) {
- final ComponentSearchResultDTO match = search(search,
remoteGroup);
- if (match != null) {
- match.setGroupId(group.getIdentifier());
- match.setParentGroup(buildResultGroup(group, user));
- match.setVersionedGroup(buildVersionedGroup(group, user));
- results.getRemoteProcessGroupResults().add(match);
- }
- }
- }
-
- for (final Port port : group.getInputPorts()) {
- if (port.isAuthorized(authorizer, RequestAction.READ, user)) {
- final ComponentSearchResultDTO match = search(search, port);
- if (match != null) {
- match.setGroupId(group.getIdentifier());
- match.setParentGroup(buildResultGroup(group, user));
- match.setVersionedGroup(buildVersionedGroup(group, user));
- results.getInputPortResults().add(match);
- }
- }
+ public void search(final SearchQuery searchQuery, final SearchResultsDTO
results) {
+ if (searchQuery.hasFilter(FILTER_NAME_SCOPE) &&
FILTER_SCOPE_VALUE_HERE.equals(searchQuery.getFilter(FILTER_NAME_SCOPE))) {
+ searchInProcessGroup(results, searchQuery,
searchQuery.getActiveGroup());
+ } else {
+ searchInProcessGroup(results, searchQuery,
searchQuery.getRootGroup());
}
+ }
- for (final Port port : group.getOutputPorts()) {
- if (port.isAuthorized(authorizer, RequestAction.READ, user)) {
- final ComponentSearchResultDTO match = search(search, port);
- if (match != null) {
- match.setGroupId(group.getIdentifier());
- match.setParentGroup(buildResultGroup(group, user));
- match.setVersionedGroup(buildVersionedGroup(group, user));
- results.getOutputPortResults().add(match);
- }
- }
- }
+ private void searchInProcessGroup(final SearchResultsDTO results, final
SearchQuery searchQuery, final ProcessGroup scope) {
+ final NiFiUser user = searchQuery.getUser();
+ final ComponentSearchResultEnricher resultEnricher =
resultEnricherFactory.getComponentResultEnricher(scope, user);
+ final ComponentSearchResultEnricher groupResultEnricher =
resultEnricherFactory.getProcessGroupResultEnricher(scope, user);
- for (final Funnel funnel : group.getFunnels()) {
- if (funnel.isAuthorized(authorizer, RequestAction.READ, user)) {
- final ComponentSearchResultDTO match = search(search, funnel);
- if (match != null) {
- match.setGroupId(group.getIdentifier());
- match.setParentGroup(buildResultGroup(group, user));
- match.setVersionedGroup(buildVersionedGroup(group, user));
- results.getFunnelResults().add(match);
- }
+ if (appliesToGroupFilter(searchQuery, scope)) {
+ if (scope.getParent() != null) {
Review comment:
This came from the original implementation. In this PR I strived to keep the
existing functionality the same in most cases so I would find it better to
change this under a separate ticket. However, I find it reasonable to allow
users to search in the variable registry for root process group as well.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services