Update resource instance id for Decomposed service

Update resourceinstanceid for Decomposed service

Change-Id: Iaadd8b6d3fb861058eed56cbf33b3a0dc6a060d0
Issue-ID: SO-587
Signed-off-by: c00149107 <chenchuanyu@huawei.com>
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 71aea02..2efd86e 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
@@ -355,8 +355,26 @@
         try {
             ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
             List<Resource> deleteResourceList = serviceDecomposition.getServiceResources()
+            String serviceRelationShip = execution.getVariable("serviceRelationShip")
+            def jsonSlurper = new JsonSlurper()
+            def jsonOutput = new JsonOutput()         
+            List relationShipList =  jsonSlurper.parseText(serviceRelationShip)
+                            
+ 
+            //Set the real resource instance id to the decomosed resource list
+            for(Resource resource: deleteResourceList){
+            	//reset the resource instance id , because in the decompose flow ,its a random one.
+            	resource.setResourceId("");
+                //match the resource-instance-name and the model name
+                if (relationShipList != null) {
+                    relationShipList.each {
+                	   if(StringUtils.containsIgnoreCase(it.resourceType, resource.getModelInfo().getModelName())){
+                	       resource.setResourceId(it.resourceInstanceId);
+                	   }                        
+                    }
+                }
+            }
             execution.setVariable("deleteResourceList", deleteResourceList)
-            execution.setVariable("resourceInstanceIDs", execution.getVariable("serviceRelationShip"))
         } catch (Exception ex) {
             String exceptionMessage = "Bpmn error encountered in  create generic e2e service flow. processDecomposition() - " + ex.getMessage()
             utils.log("DEBUG", exceptionMessage, isDebugEnabled)
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 63ecb45..a7f461b 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
@@ -239,8 +239,8 @@
         String resourceInstanceId = execution.getVariable("resourceInstanceId")
         String resourceUuid = execution.getVariable("resourceUuid")
 
-        String requestAction = execution.getVariable("operationType")
-        JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceUuid, requestAction)
+        String action = "deleteInstance"
+        JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceUuid, action)
         String recipeUri = resourceRecipe.getString("orchestrationUri")
         int recipeTimeout = resourceRecipe.getInt("recipeTimeout")
         String recipeParamXsd = resourceRecipe.get("paramXSD")
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/resources/subprocess/DoDeleteResourcesV1.bpmn b/bpmn/MSOInfrastructureBPMN/src/main/resources/subprocess/DoDeleteResourcesV1.bpmn
index f74dab1..2b9b874 100644
--- a/bpmn/MSOInfrastructureBPMN/src/main/resources/subprocess/DoDeleteResourcesV1.bpmn
+++ b/bpmn/MSOInfrastructureBPMN/src/main/resources/subprocess/DoDeleteResourcesV1.bpmn
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.11.3">
+<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.10.0">
   <bpmn:process id="DoDeleteResourcesV1" name="DoDeleteResourcesV1" isExecutable="true">
     <bpmn:startEvent id="StartEvent_1" name="Start Resource Delete">
       <bpmn:outgoing>SequenceFlow_0stqur4</bpmn:outgoing>
@@ -9,9 +9,8 @@
       <bpmn:incoming>SequenceFlow_13nyd1j</bpmn:incoming>
       <bpmn:outgoing>SequenceFlow_1qm7owo</bpmn:outgoing>
       <bpmn:script><![CDATA[import org.openecomp.mso.bpmn.infrastructure.scripts.*
-String resourceName = execution.getVariable("resourceType")
 def ddrs = new DoDeleteResourcesV1()
-ddrs.preResourceDelete(execution, resourceName )]]></bpmn:script>
+ddrs.preResourceDelete(execution)]]></bpmn:script>
     </bpmn:scriptTask>
     <bpmn:scriptTask id="ScriptTask_15zy0jf" name="Execute Delete Resource Recipe" scriptFormat="groovy">
       <bpmn:incoming>SequenceFlow_1qm7owo</bpmn:incoming>