tpalfy 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_r391141901
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/search/attributematchers/PropertyMatcher.java
 ##########
 @@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.search.attributematchers;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.ProcessorNode;
+import org.apache.nifi.web.search.query.SearchQuery;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static 
org.apache.nifi.web.search.attributematchers.AttributeMatcher.addIfMatching;
+
+public class PropertyMatcher implements AttributeMatcher<ProcessorNode> {
+    private static final String LABEL_NAME = "Property name";
+    private static final String LABEL_VALUE = "Property value";
+    private static final String LABEL_DESCRIPTION = "Property description";
+
+    private final static String FILTER_NAME_PROPERTIES = "properties";
+    private final static Set<String> FILTER_VALUES_PROPERTIES_EXCLUSION = new 
HashSet<>(Arrays.asList("no", "none", "false", "exclude", "0"));
+
+    @Override
+    public void match(final ProcessorNode component, final SearchQuery query, 
final List<String> matches) {
+        final String searchTerm = query.getTerm();
+
+        if (!propertiesAreFilteredOut(query)) {
+            for (final Map.Entry<PropertyDescriptor, String> entry : 
component.getRawPropertyValues().entrySet()) {
+                final PropertyDescriptor descriptor = entry.getKey();
+                addIfMatching(searchTerm, descriptor.getName(), LABEL_NAME, 
matches);
+                addIfMatching(searchTerm, descriptor.getDescription(), 
LABEL_DESCRIPTION, matches);
+
+                // never include sensitive properties values in search results
+                if (!descriptor.isSensitive()) {
+                    final String value = (entry.getValue() == null)
+                        ? descriptor.getDefaultValue()
+                        : entry.getValue();
+
+                    // evaluate if the value matches the search criteria
+                    if (StringUtils.containsIgnoreCase(value, searchTerm)) {
+                        matches.add(new 
StringBuilder(LABEL_VALUE).append(SEPARATOR).append(descriptor.getName()).append("
 - ").append(value).toString());
 
 Review comment:
   Again, unnecessary `StringBuilder`.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to