WorkflowAction, traverseNetworkCollection refactoring stage 1 92/109192/2
authorKrzysztof Gajewski <krzysztof.gajewski@nokia.com>
Mon, 15 Jun 2020 16:11:28 +0000 (18:11 +0200)
committerKrzysztof Gajewski <krzysztof.gajewski@nokia.com>
Thu, 18 Jun 2020 08:24:27 +0000 (10:24 +0200)
- extract one function; if logic refactor
- two boolean "ifs" function created

Issue-ID: SO-2634

Signed-off-by: Krzysztof Gajewski <krzysztof.gajewski@nokia.com>
Change-Id: Ia139d0a6f1b470c8e7fab77afc76937dac9f5364
Signed-off-by: Krzysztof Gajewski <krzysztof.gajewski@nokia.com>
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java

index b4eb97a..fe45e13 100644 (file)
@@ -338,8 +338,7 @@ public class WorkflowAction {
                     }
                     flowsToExecute = buildExecuteBuildingBlockList(orchFlows, resourceList, requestId, apiVersion,
                             resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, vnfReplace);
-                    if (!resourceList.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType())
-                            .collect(Collectors.toList()).isEmpty()) {
+                    if (isNetworkCollectionInTheResourceList(resourceList)) {
                         logger.info("Sorting for Vlan Tagging");
                         flowsToExecute = sortExecutionPathByObjectForVlanTagging(flowsToExecute, requestAction);
                     }
@@ -799,7 +798,7 @@ public class WorkflowAction {
 
     protected void traverseNetworkCollection(DelegateExecution execution, List<Resource> resourceList,
             org.onap.so.db.catalog.beans.Service service) {
-        if (service.getVnfCustomizations() == null || service.getVnfCustomizations().isEmpty()) {
+        if (isVnfCustomizationsEmpty(service)) {
             List<CollectionResourceCustomization> customizations = service.getCollectionResourceCustomizations();
             if (customizations.isEmpty()) {
                 logger.debug("No Collections found. CollectionResourceCustomization list is empty.");
@@ -866,23 +865,37 @@ public class WorkflowAction {
                     logger.debug("No Network Collection Customization found");
                 }
             }
-            if (resourceList.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType())
-                    .collect(Collectors.toList()).isEmpty()) {
-                if (service.getNetworkCustomizations() == null) {
-                    logger.debug("No networks were found on this service model");
-                } else {
-                    for (int i = 0; i < service.getNetworkCustomizations().size(); i++) {
-                        resourceList.add(new Resource(WorkflowType.NETWORK,
-                                service.getNetworkCustomizations().get(i).getModelCustomizationUUID(), false));
-                    }
-                }
-            }
+            traverseNetworkCollectionCustomization(resourceList, service);
         } else {
             buildAndThrowException(execution,
                     "Cannot orchestrate Service-Macro-Create without user params with a vnf. Please update ASDC model for new macro orchestration support or add service_recipe records to route to old macro flows");
         }
     }
 
+    private void traverseNetworkCollectionCustomization(List<Resource> resourceList,
+            org.onap.so.db.catalog.beans.Service service) {
+        if (isNetworkCollectionInTheResourceList(resourceList)) {
+            return;
+        }
+        if (service.getNetworkCustomizations() == null) {
+            logger.debug("No networks were found on this service model");
+            return;
+        }
+        for (int i = 0; i < service.getNetworkCustomizations().size(); i++) {
+            resourceList.add(new Resource(WorkflowType.NETWORK,
+                    service.getNetworkCustomizations().get(i).getModelCustomizationUUID(), false));
+        }
+    }
+
+    private boolean isNetworkCollectionInTheResourceList(List<Resource> resourceList) {
+        return !(resourceList.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType())
+                .collect(Collectors.toList()).isEmpty());
+    }
+
+    private boolean isVnfCustomizationsEmpty(org.onap.so.db.catalog.beans.Service service) {
+        return service.getVnfCustomizations() == null || service.getVnfCustomizations().isEmpty();
+    }
+
     protected void traverseAAIService(DelegateExecution execution, List<Resource> resourceList, String resourceId,
             List<Pair<WorkflowType, String>> aaiResourceIds) {
         try {