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_r390380984
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/search/attributematchers/BasicAttributeMatcher.java
 ##########
 @@ -0,0 +1,55 @@
+/*
+ * 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.nifi.connectable.Connectable;
+import org.apache.nifi.web.search.query.SearchQuery;
+
+import java.util.List;
+
+import static 
org.apache.nifi.web.search.attributematchers.AttributeMatcher.addIfMatching;
+
+public class BasicAttributeMatcher<T extends Connectable> implements 
AttributeMatcher<T> {
 
 Review comment:
   Usually it's better to avoid boolean flags (especially if they have no 
business logic implications).
   I'm wondering if it wouldn't be better to use polymorphism instead, like 
this:
   ```java
   public class BasicAttributeMatcher<T extends Connectable> implements 
AttributeMatcher<T> {
       private static final String LABEL_ID = "Id";
       private static final String LABEL_VERSION_CONTROL_ID = "Version Control 
ID";
   
       @Override
       public void match(final T component, final SearchQuery query, final 
List<String> matches) {
           final String searchTerm = query.getTerm();
   
           addIfMatching(searchTerm, component.getIdentifier(), LABEL_ID, 
matches);
           addIfMatching(searchTerm, 
component.getVersionedComponentId().orElse(null), LABEL_VERSION_CONTROL_ID, 
matches);
       }
   }
   
   public class ExtendedAttributeMatcher<T extends Connectable> extends 
BasicAttributeMatcher<T> {
       private static final String LABEL_NAME = "Name";
       private static final String LABEL_COMMENTS = "Comments";
   
       @Override
       public void match(final T component, final SearchQuery query, final 
List<String> matches) {
           super.match(component, query, matches);
   
           final String searchTerm = query.getTerm();
   
           addIfMatching(searchTerm, component.getName(), LABEL_NAME, matches);
           addIfMatching(searchTerm, component.getComments(), LABEL_COMMENTS, 
matches);
       }
   }
   ```

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

Reply via email to