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_r392328379
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/search/attributematchers/PortScheduledStateMatcher.java
 ##########
 @@ -0,0 +1,52 @@
+/*
+ * 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.connectable.Port;
+import org.apache.nifi.controller.ScheduledState;
+import org.apache.nifi.web.search.query.SearchQuery;
+
+import java.util.List;
+
+public class PortScheduledStateMatcher implements AttributeMatcher<Port> {
+    private static final String SEARCH_TERM_DISABLED = "disabled";
+    private static final String SEARCH_TERM_INVALID = "invalid";
+    private static final String SEARCH_TERM_RUNNING = "running";
+    private static final String SEARCH_TERM_STOPPED = "stopped";
+
+    private static final String MATCH_PREFIX = "Run status: ";
+    private static final String MATCH_DISABLED = "Disabled";
+    private static final String MATCH_INVALID = "Invalid";
+    private static final String MATCH_RUNNING = "Running";
+    private static final String MATCH_STOPPED = "Stopped";
+
+    @Override
+    public void match(final Port component, final SearchQuery query, final 
List<String> matches) {
+        final String searchTerm = query.getTerm();
+
+        if (ScheduledState.DISABLED.equals(component.getScheduledState()) && 
StringUtils.containsIgnoreCase(SEARCH_TERM_DISABLED, searchTerm)) {
 
 Review comment:
   This if-else branching is not logically the same as the original.
   For example in your case the second branch might get evaluated if the 
scheduled state is `DISABLED` but there's no `"disabled"` (or something like 
that) in the search term.
   
   With the original logic it was not the case - If the component was 
`DISABLED`, the other cases did not get evaluated period.
   
   Doesn't seem to be too significant but maybe (not sure) _disabled_ 
components _can_ be _invalid_ (and/or _stopped_) at the same time, and you 
probably don't want those to come up when you are looking for invalid/stopped 
components in general.

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