Merge "WorkflowAction refactoring"
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Thu, 18 Jun 2020 10:25:42 +0000 (10:25 +0000)
committerGerrit Code Review <gerrit@onap.org>
Thu, 18 Jun 2020 10:25:42 +0000 (10:25 +0000)
1  2 
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java

@@@ -213,17 -213,8 +213,8 @@@ public class WorkflowAction 
                          orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, true,
                                  cloudOwner, serviceType);
                      }
-                     String key = "";
-                     ModelInfo modelInfo = sIRequest.getRequestDetails().getModelInfo();
-                     if (modelInfo != null) {
-                         if (modelInfo.getModelType().equals(ModelType.service)) {
-                             key = modelInfo.getModelVersionId();
-                         } else {
-                             key = modelInfo.getModelCustomizationId();
-                         }
-                     }
+                     Resource resourceKey = getResourceKey(sIRequest, resourceType);
                      boolean isConfiguration = isConfiguration(orchFlows);
-                     Resource resourceKey = new Resource(resourceType, key, true);
                      if (isConfiguration && !requestAction.equalsIgnoreCase(CREATEINSTANCE)) {
                          List<ExecuteBuildingBlock> configBuildingBlocks = getConfigBuildingBlocks(
                                  new ConfigBuildingBlocksDataObject().setsIRequest(sIRequest).setOrchFlows(orchFlows)
                      }
                      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);
                      }
          }
      }
  
+     private Resource getResourceKey(ServiceInstancesRequest sIRequest, WorkflowType resourceType) {
+         String resourceId = "";
+         ModelInfo modelInfo = sIRequest.getRequestDetails().getModelInfo();
+         if (modelInfo != null) {
+             if (modelInfo.getModelType().equals(ModelType.service)) {
+                 resourceId = modelInfo.getModelVersionId();
+             } else {
+                 resourceId = modelInfo.getModelCustomizationId();
+             }
+         }
+         return new Resource(resourceType, resourceId, true);
+     }
      private String getCloudOwner(CloudConfiguration cloudConfiguration) {
          if (cloudConfiguration != null && cloudConfiguration.getCloudOwner() != null) {
              return cloudConfiguration.getCloudOwner();
  
      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.");
                      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 {