WorkflowAction, traverseNetworkCollection refactoring stage 2

- extract one function to traverseNetworkCollectionResourceCustomization

Issue-ID: SO-2634
Signed-off-by: Krzysztof Gajewski <krzysztof.gajewski@nokia.com>
Change-Id: I869174d8e022603374fa86ba4405ea2611b4dfd1
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java
index ac33d7a..95f10c3 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java
@@ -809,65 +809,7 @@
             } else {
                 CollectionResourceCustomization collectionResourceCustomization =
                         findCatalogNetworkCollection(execution, service);
-                if (collectionResourceCustomization != null) {
-                    resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION,
-                            collectionResourceCustomization.getModelCustomizationUUID(), false));
-                    logger.debug("Found a network collection");
-                    if (collectionResourceCustomization.getCollectionResource() != null) {
-                        if (collectionResourceCustomization.getCollectionResource().getInstanceGroup() != null) {
-                            String toscaNodeType = collectionResourceCustomization.getCollectionResource()
-                                    .getInstanceGroup().getToscaNodeType();
-                            if (toscaNodeType != null && toscaNodeType.contains(NETWORKCOLLECTION)) {
-                                int minNetworks = 0;
-                                org.onap.so.db.catalog.beans.InstanceGroup instanceGroup =
-                                        collectionResourceCustomization.getCollectionResource().getInstanceGroup();
-                                CollectionResourceInstanceGroupCustomization collectionInstCust = null;
-                                if (!instanceGroup.getCollectionInstanceGroupCustomizations().isEmpty()) {
-                                    for (CollectionResourceInstanceGroupCustomization collectionInstanceGroupTemp : instanceGroup
-                                            .getCollectionInstanceGroupCustomizations()) {
-                                        if (collectionInstanceGroupTemp.getModelCustomizationUUID().equalsIgnoreCase(
-                                                collectionResourceCustomization.getModelCustomizationUUID())) {
-                                            collectionInstCust = collectionInstanceGroupTemp;
-                                            break;
-                                        }
-                                    }
-                                    if (collectionInstCust != null
-                                            && collectionInstCust.getSubInterfaceNetworkQuantity() != null) {
-                                        minNetworks = collectionInstCust.getSubInterfaceNetworkQuantity();
-                                    }
-                                }
-                                logger.debug("minNetworks: {}", minNetworks);
-                                CollectionNetworkResourceCustomization collectionNetworkResourceCust = null;
-                                for (CollectionNetworkResourceCustomization collectionNetworkTemp : instanceGroup
-                                        .getCollectionNetworkResourceCustomizations()) {
-                                    if (collectionNetworkTemp.getNetworkResourceCustomization()
-                                            .getModelCustomizationUUID().equalsIgnoreCase(
-                                                    collectionResourceCustomization.getModelCustomizationUUID())) {
-                                        collectionNetworkResourceCust = collectionNetworkTemp;
-                                        break;
-                                    }
-                                }
-                                for (int i = 0; i < minNetworks; i++) {
-                                    if (collectionNetworkResourceCust != null && collectionInstCust != null) {
-                                        Resource resource = new Resource(WorkflowType.VIRTUAL_LINK,
-                                                collectionNetworkResourceCust.getModelCustomizationUUID(), false);
-                                        resource.setVirtualLinkKey(Integer.toString(i));
-                                        resourceList.add(resource);
-                                    }
-                                }
-                            } else {
-                                logger.debug("Instance Group tosca node type does not contain NetworkCollection:  {}",
-                                        toscaNodeType);
-                            }
-                        } else {
-                            logger.debug("No Instance Group found for network collection.");
-                        }
-                    } else {
-                        logger.debug("No Network Collection found. collectionResource is null");
-                    }
-                } else {
-                    logger.debug("No Network Collection Customization found");
-                }
+                traverseNetworkCollectionResourceCustomization(resourceList, collectionResourceCustomization);
             }
             traverseNetworkCollectionCustomization(resourceList, service);
         } else {
@@ -876,6 +818,68 @@
         }
     }
 
+    private void traverseNetworkCollectionResourceCustomization(List<Resource> resourceList,
+            CollectionResourceCustomization collectionResourceCustomization) {
+        if (collectionResourceCustomization != null) {
+            resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION,
+                    collectionResourceCustomization.getModelCustomizationUUID(), false));
+            logger.debug("Found a network collection");
+            if (collectionResourceCustomization.getCollectionResource() != null) {
+                if (collectionResourceCustomization.getCollectionResource().getInstanceGroup() != null) {
+                    String toscaNodeType = collectionResourceCustomization.getCollectionResource().getInstanceGroup()
+                            .getToscaNodeType();
+                    if (toscaNodeType != null && toscaNodeType.contains(NETWORKCOLLECTION)) {
+                        int minNetworks = 0;
+                        org.onap.so.db.catalog.beans.InstanceGroup instanceGroup =
+                                collectionResourceCustomization.getCollectionResource().getInstanceGroup();
+                        CollectionResourceInstanceGroupCustomization collectionInstCust = null;
+                        if (!instanceGroup.getCollectionInstanceGroupCustomizations().isEmpty()) {
+                            for (CollectionResourceInstanceGroupCustomization collectionInstanceGroupTemp : instanceGroup
+                                    .getCollectionInstanceGroupCustomizations()) {
+                                if (collectionInstanceGroupTemp.getModelCustomizationUUID().equalsIgnoreCase(
+                                        collectionResourceCustomization.getModelCustomizationUUID())) {
+                                    collectionInstCust = collectionInstanceGroupTemp;
+                                    break;
+                                }
+                            }
+                            if (collectionInstCust != null
+                                    && collectionInstCust.getSubInterfaceNetworkQuantity() != null) {
+                                minNetworks = collectionInstCust.getSubInterfaceNetworkQuantity();
+                            }
+                        }
+                        logger.debug("minNetworks: {}", minNetworks);
+                        CollectionNetworkResourceCustomization collectionNetworkResourceCust = null;
+                        for (CollectionNetworkResourceCustomization collectionNetworkTemp : instanceGroup
+                                .getCollectionNetworkResourceCustomizations()) {
+                            if (collectionNetworkTemp.getNetworkResourceCustomization().getModelCustomizationUUID()
+                                    .equalsIgnoreCase(collectionResourceCustomization.getModelCustomizationUUID())) {
+                                collectionNetworkResourceCust = collectionNetworkTemp;
+                                break;
+                            }
+                        }
+                        for (int i = 0; i < minNetworks; i++) {
+                            if (collectionNetworkResourceCust != null && collectionInstCust != null) {
+                                Resource resource = new Resource(WorkflowType.VIRTUAL_LINK,
+                                        collectionNetworkResourceCust.getModelCustomizationUUID(), false);
+                                resource.setVirtualLinkKey(Integer.toString(i));
+                                resourceList.add(resource);
+                            }
+                        }
+                    } else {
+                        logger.debug("Instance Group tosca node type does not contain NetworkCollection:  {}",
+                                toscaNodeType);
+                    }
+                } else {
+                    logger.debug("No Instance Group found for network collection.");
+                }
+            } else {
+                logger.debug("No Network Collection found. collectionResource is null");
+            }
+        } else {
+            logger.debug("No Network Collection Customization found");
+        }
+    }
+
     private void traverseNetworkCollectionCustomization(List<Resource> resourceList,
             org.onap.so.db.catalog.beans.Service service) {
         if (isNetworkCollectionInTheResourceList(resourceList)) {