Merge "Fix the variables in delete E2E workflow"
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DeleteSDNCNetworkResource.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DeleteSDNCNetworkResource.groovy
index 479e091..9358537 100644
--- a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DeleteSDNCNetworkResource.groovy
+++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DeleteSDNCNetworkResource.groovy
@@ -29,7 +29,6 @@
 import org.apache.http.HttpResponse
 import org.json.JSONArray
 import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient
-import org.openecomp.mso.bpmn.common.recipe.ResourceInput;
 
 import static org.apache.commons.lang3.StringUtils.*;
 import groovy.xml.XmlUtil
@@ -44,6 +43,8 @@
 import org.openecomp.mso.rest.APIResponse;
 import org.openecomp.mso.rest.RESTClient
 import org.openecomp.mso.rest.RESTConfig
+import org.openecomp.mso.bpmn.common.recipe.ResourceInput
+import com.fasterxml.jackson.databind.ObjectMapper
 
 import java.util.List;
 import java.util.UUID;
@@ -74,19 +75,19 @@
         String msg = ""
 
         try {
-            serviceInstanceId = execution.getVariable("serviceInstanceId")
-            serviceInstanceName = execution.getVariable("serviceInstanceName")
-            callbackURL = execution.getVariable("sdncCallbackUrl")
-            requestId = execution.getVariable("msoRequestId")
-            serviceId = execution.getVariable("productFamilyId")
-            subscriptionServiceType = execution.getVariable("subscriptionServiceType")
-            globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
+            String serviceInstanceId = execution.getVariable("serviceInstanceId")
+            String serviceInstanceName = execution.getVariable("serviceInstanceName")
+            String callbackURL = execution.getVariable("sdncCallbackUrl")
+            String requestId = execution.getVariable("msoRequestId")
+            String serviceId = execution.getVariable("productFamilyId")
+            String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
+            String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
             String recipeParamsFromRequest = execution.getVariable("recipeParams")
             String serviceModelInfo = execution.getVariable("serviceModelInfo")
-            modelInvariantUuid = ""
-            modelVersion = ""
-            modelUuid = ""
-            modelName = ""
+            String modelInvariantUuid = ""
+            String modelVersion = ""
+            String modelUuid = ""
+            String modelName = ""
 
             if (!isBlank(serviceModelInfo))
             {
@@ -122,7 +123,7 @@
                 serviceType = ""
             }
 
-            sdncRequestId = UUID.randomUUID().toString()
+            String sdncRequestId = UUID.randomUUID().toString()
 
             String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
 
@@ -140,12 +141,13 @@
 
             operationType = "delete" + operationType + "Instance"
 
-            if(StringUtils.containsIgnoreCase(resourceInputObj.getResourceInstanceName(), "overlay")){
+            ResourceInput resourceInput = new ObjectMapper().readValue(execution.getVariable("resourceInput"), ResourceInput.class)
+            if(StringUtils.containsIgnoreCase(resourceInput.getResourceModelInfo().getModelName(), "overlay")){
                 //This will be resolved in R3.
                 sdnc_svcAction ="deactivate"
                 operationType = "DeActivateDCINetworkInstance"
             }
-            if(StringUtils.containsIgnoreCase(resourceInputObj.getResourceInstanceName(), "underlay")){
+            if(StringUtils.containsIgnoreCase(resourceInput.getResourceModelInfo().getModelName(), "underlay")){
                 //This will be resolved in R3.
                 operationType ="DeleteNetworkInstance"
             }
@@ -195,8 +197,8 @@
             //def sdncRequestId2 = UUID.randomUUID().toString()
             //String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
             execution.setVariable("sdncDelete", sdncDelete)
-            execution.setVariable("sdncDeactivate", sdncDeactivate)
-            utils.log("INFO","sdncDeactivate:\n" + sdncDeactivate, isDebugEnabled)
+//            execution.setVariable("sdncDeactivate", sdncDeactivate)
+//            utils.log("INFO","sdncDeactivate:\n" + sdncDeactivate, isDebugEnabled)
             utils.log("INFO","sdncDelete:\n" + sdncDelete, isDebugEnabled)
 
         } catch (BpmnError e) {
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoDeleteE2EServiceInstance.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoDeleteE2EServiceInstance.groovy
index 2efd86e..ec7370f 100644
--- a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoDeleteE2EServiceInstance.groovy
+++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoDeleteE2EServiceInstance.groovy
@@ -332,11 +332,11 @@
             utils.log("DEBUG", " ***** Inside prepareDecomposeService of create generic e2e service ***** ", isDebugEnabled)
             String modelInvariantUuid = execution.getVariable("model-invariant-id-original")
             String modelVersionId = execution.getVariable("model-version-id-original")
-            //here modelVersion is not set, we use modelUuid to decompose the service.
+
             String serviceModelInfo = """{
             "modelInvariantUuid":"${modelInvariantUuid}",
-            "modelUuid":"${modelVersionId}",
-            "modelVersion":""
+            "modelUuid":"",
+            "modelVersion":"${modelVersionId}"
              }"""
             execution.setVariable("serviceModelInfo", serviceModelInfo)
 
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoDeleteResourcesV1.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoDeleteResourcesV1.groovy
index a7f461b..0fcc41c 100644
--- a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoDeleteResourcesV1.groovy
+++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoDeleteResourcesV1.groovy
@@ -243,7 +243,7 @@
         JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceUuid, action)
         String recipeUri = resourceRecipe.getString("orchestrationUri")
         int recipeTimeout = resourceRecipe.getInt("recipeTimeout")
-        String recipeParamXsd = resourceRecipe.get("paramXSD")
+        String recipeParamXsd = resourceRecipe.isNull("paramXSD") ? "" : resourceRecipe.get("paramXSD")
 
         Resource currentResource = execution.getVariable("currentResource")
 
@@ -255,7 +255,11 @@
         modelInfo.setModelCustomizationUuid(currentResource.getModelInfo().getModelCustomizationUuid())
         modelInfo.setModelUuid(currentResource.getModelInfo().getModelCustomizationUuid())
         modelInfo.setModelInvariantUuid(currentResource.getModelInfo().getModelInvariantUuid())
-        resourceInput.setServiceModelInfo(modelInfo)
+        modelInfo.setModelName(currentResource.getModelInfo().getModelName())
+        modelInfo.setModelVersion(currentResource.getModelInfo().getModelVersion())
+        modelInfo.setModelType(currentResource.getModelInfo().getModelType())
+        modelInfo.setModelInstanceName(currentResource.getModelInfo().getModelInstanceName())
+        resourceInput.setResourceModelInfo(modelInfo)
         resourceInput.setServiceType(serviceType)
 
         String recipeURL = BPMNProperties.getProperty("bpelURL", "http://mso:8080") + recipeUri