private List filterEvents()

in nifi-extension-bundles/nifi-extension-utils/nifi-reporting-utils/src/main/java/org/apache/nifi/reporting/util/provenance/ProvenanceEventConsumer.java [273:359]


    private List<ProvenanceEventRecord> filterEvents(ComponentMapHolder componentMapHolder, List<ProvenanceEventRecord> provenanceEvents) {
        if (isFilteringEnabled()) {
            List<ProvenanceEventRecord> filteredEvents = new ArrayList<>();

            for (ProvenanceEventRecord provenanceEventRecord : provenanceEvents) {

                if (!eventTypesExclude.isEmpty() && eventTypesExclude.contains(provenanceEventRecord.getEventType())) {
                    continue;
                }

                if (!eventTypes.isEmpty() && !eventTypes.contains(provenanceEventRecord.getEventType())) {
                    continue;
                }

                final String componentId = provenanceEventRecord.getComponentId();
                if (!componentIdsExclude.isEmpty()) {
                    if (componentIdsExclude.contains(componentId)) {
                        continue;
                    }
                    // If we aren't excluding it based on component ID, let's see if this component has a parent process group IDs
                    // that is being excluded
                    if (componentMapHolder == null) {
                        continue;
                    }
                    final String processGroupId = componentMapHolder.getProcessGroupId(componentId, provenanceEventRecord.getComponentType());
                    if (!isEmpty(processGroupId)) {

                        // Check if the process group or any parent process group is specified as a target component ID.
                        if (componentIdsExclude.contains(processGroupId)) {
                            continue;
                        }
                        ParentProcessGroupSearchNode parentProcessGroup = componentMapHolder.getProcessGroupParent(processGroupId);
                        while (parentProcessGroup != null && !componentIdsExclude.contains(parentProcessGroup.getId())) {
                            parentProcessGroup = parentProcessGroup.getParent();
                        }
                        if (parentProcessGroup != null) {
                            continue;
                        }
                    }
                }

                if (!componentIds.isEmpty() && !componentIds.contains(componentId)) {
                    // If we aren't filtering it out based on component ID, let's see if this component has a parent process group IDs
                    // that is being filtered on
                    if (componentMapHolder == null) {
                        continue;
                    }
                    final String processGroupId = componentMapHolder.getProcessGroupId(componentId, provenanceEventRecord.getComponentType());
                    if (isEmpty(processGroupId)) {
                        continue;
                    }
                    if (!componentIds.contains(processGroupId)) {
                        ParentProcessGroupSearchNode parentProcessGroup = componentMapHolder.getProcessGroupParent(processGroupId);
                        while (parentProcessGroup != null && !componentIds.contains(parentProcessGroup.getId())) {
                            parentProcessGroup = parentProcessGroup.getParent();
                        }
                        if (parentProcessGroup == null) {
                            continue;
                        }
                    }
                }

                if (componentTypeRegexExclude != null && componentTypeRegexExclude.matcher(provenanceEventRecord.getComponentType()).matches()) {
                    continue;
                }

                if (componentTypeRegex != null && !componentTypeRegex.matcher(provenanceEventRecord.getComponentType()).matches()) {
                    continue;
                }

                final String componentName = componentMapHolder.getComponentName(provenanceEventRecord.getComponentId());
                if (componentNameRegexExclude != null && componentName != null && componentNameRegexExclude.matcher(componentName).matches()) {
                    continue;
                }

                if (componentNameRegex != null && componentName != null && !componentNameRegex.matcher(componentName).matches()) {
                    continue;
                }

                filteredEvents.add(provenanceEventRecord);
            }

            return filteredEvents;
        } else {
            return provenanceEvents;
        }
    }