NIFI-8771: This closes #5205. Ensure that we consider root process group level Controller Services when determining whether or not the dataflow is empty

Signed-off-by: Joe Witt <joewitt@apache.org>
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java
index 754ae90..cbb25f2 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java
@@ -683,6 +683,7 @@
                 && CollectionUtils.isEmpty(contents.getOutputPorts())
                 && CollectionUtils.isEmpty(contents.getProcessGroups())
                 && CollectionUtils.isEmpty(contents.getRemoteProcessGroups())
+                && CollectionUtils.isEmpty(contents.getControllerServices())
                 && parameterContextId == null;
     }
 
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/serialization/FlowFromDOMFactory.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/serialization/FlowFromDOMFactory.java
index b8dba8a..f44fb0d 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/serialization/FlowFromDOMFactory.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/serialization/FlowFromDOMFactory.java
@@ -215,6 +215,7 @@
         final Set<LabelDTO> labels = new HashSet<>();
         final Set<ProcessGroupDTO> processGroups = new HashSet<>();
         final Set<RemoteProcessGroupDTO> remoteProcessGroups = new HashSet<>();
+        final Set<ControllerServiceDTO> controllerServices = new HashSet<>();
 
         NodeList nodeList = DomUtils.getChildNodesByTagName(element, "processor");
         for (int i = 0; i < nodeList.getLength(); i++) {
@@ -256,6 +257,11 @@
             connections.add(getConnection((Element) nodeList.item(i)));
         }
 
+        nodeList = DomUtils.getChildNodesByTagName(element, "controllerService");
+        for (int i=0; i < nodeList.getLength(); i++) {
+            controllerServices.add(getControllerService((Element) nodeList.item(i), encryptor, encodingVersion));
+        }
+
         final FlowSnippetDTO groupContents = new FlowSnippetDTO();
         groupContents.setConnections(connections);
         groupContents.setFunnels(funnels);
@@ -265,6 +271,7 @@
         groupContents.setProcessGroups(processGroups);
         groupContents.setProcessors(processors);
         groupContents.setRemoteProcessGroups(remoteProcessGroups);
+        groupContents.setControllerServices(controllerServices);
 
         dto.setContents(groupContents);
         return dto;