added generic fabric support to SO
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / Delete3rdONAPE2EServiceInstance.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - SO
4  * ================================================================================
5  * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import org.json.JSONObject
24 import org.json.XML
25
26 import static org.apache.commons.lang3.StringUtils.*
27 import groovy.xml.XmlUtil
28 import groovy.json.*
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
32 import org.onap.so.bpmn.common.scripts.AaiUtil
33 import org.onap.so.bpmn.common.scripts.MsoUtils
34 import org.onap.so.bpmn.common.recipe.ResourceInput
35 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
36 import org.onap.so.bpmn.core.WorkflowException
37 import org.onap.so.bpmn.core.json.JsonUtils
38 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder
39 import org.onap.so.rest.APIResponse
40 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
41 import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory
42 import java.util.UUID
43 import org.onap.so.logger.MsoLogger
44
45 import org.camunda.bpm.engine.runtime.Execution
46 import org.camunda.bpm.engine.delegate.BpmnError
47 import org.camunda.bpm.engine.delegate.DelegateExecution
48 import org.apache.commons.lang3.*
49 import org.apache.commons.codec.binary.Base64
50 import org.springframework.web.util.UriUtils
51 import org.onap.so.rest.RESTClient
52 import org.onap.so.rest.RESTConfig
53
54 /**
55  * This groovy class supports the <class>Delete3rdONAPE2EServiceInstance.bpmn</class> process.
56  * flow for Delete 3rdONAPE2EServiceInstance in 3rdONAP 
57  */
58 public class Delete3rdONAPE2EServiceInstance extends AbstractServiceTaskProcessor {
59
60         String Prefix = "CRE3rdONAPESI_"
61
62         ExceptionUtil exceptionUtil = new ExceptionUtil()
63
64         JsonUtils jsonUtil = new JsonUtils()
65
66         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, Delete3rdONAPE2EServiceInstance.class)
67
68         public void checkSPPartnerInfoFromAAI (DelegateExecution execution) {
69                 msoLogger.info(" ***** Started checkSPPartnerInfo *****")
70                 try {
71                         //get bpmn inputs from resource request.
72                         String requestId = execution.getVariable("mso-request-id")
73                         String requestAction = execution.getVariable("requestAction")
74                         msoLogger.info("The requestAction is: " + requestAction)
75                         String recipeParamsFromRequest = execution.getVariable("recipeParams")
76                         msoLogger.info("The recipeParams is: " + recipeParamsFromRequest)
77                         String resourceInput = execution.getVariable("resourceInput")
78                         msoLogger.info("The resourceInput is: " + resourceInput)
79                         //Get ResourceInput Object
80                         ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)                                       
81                         // set local resourceInput
82                         execution.setVariable(Prefix + "ResourceInput", resourceInputObj)
83                         
84                         String resourceInstanceId = resourceInputObj.getResourceInstancenUuid()
85                         
86                         // Get Sppartner from AAI
87                         AaiUtil aaiUriUtil = new AaiUtil(this)
88                         String aai_uri = aaiUriUtil.getBusinessSPPartnerUri(execution)
89                         String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)                      
90                         String aai_endpoint = execution.getVariable("URN_aai_endpoint")
91                         String serviceAaiPath = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(sppartnerId,"UTF-8")
92                         execution.setVariable(Prefix + "serviceAaiPath", serviceAaiPath)
93                         
94                         getSPPartnerInAAI(execution)
95                         
96                         String callSource = "UUI"
97                         String sppartnerUrl = ""
98                         if(execution.getVariable(Prefix + "SuccessIndicator")) {
99                                 callSource = execution.getVariable(Prefix + "CallSource")
100                         }
101                         
102                         boolean is3rdONAPExist = false  
103                         if(!isBlank(sppartnerUrl)) {                            
104                                 is3rdONAPExist = true
105                         }
106                         
107                         execution.setVariable("Is3rdONAPExist", is3rdONAPExist)
108                         execution.setVariable(Prefix + "ServiceInstanceId", resourceInputObj.getServiceInstanceId())
109                         execution.setVariable("mso-request-id", requestId)
110                         execution.setVariable("mso-service-instance-id", resourceInputObj.getServiceInstanceId())
111
112                 } catch (BpmnError e) {
113                         throw e
114                 } catch (Exception ex){
115                         String msg = "Exception in checkSPPartnerInfoFromAAI " + ex.getMessage()
116                         msoLogger.debug(msg)
117                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
118                 }
119         }
120
121         public void checkLocallCall (DelegateExecution execution) {
122                 msoLogger.info(" ***** Started checkLocallCall *****")
123                 
124                 boolean isLocalCall = true
125                 String callSource = execution.getVariable(Prefix + "CallSource")
126                 if("ExternalAPI".equalsIgnoreCase(callSource)) {
127                         isLocalCall = false
128                 }
129                 execution.setVariable("IsLocalCall", isLocalCall)
130         }
131
132         public void preProcessRequest(DelegateExecution execution){
133                 msoLogger.info(" ***** Started preProcessRequest *****")
134                 try {
135                         ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput")
136                         String msg = ""                 
137
138                         String globalSubscriberId = resourceInputObj.getGlobalSubscriberId()
139                         if (isBlank(globalSubscriberId)) {
140                                 msg = "Input globalSubscriberId is null"
141                                 msoLogger.info( msg)
142                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
143                         }
144                         //set local variable
145                         execution.setVariable("globalSubscriberId", globalSubscriberId)
146                         msoLogger.info( "globalSubscriberId:" + globalSubscriberId)
147
148                         String serviceType = resourceInputObj.getServiceType()
149                         if (isBlank(serviceType)) {
150                                 msg = "Input serviceType is null"
151                                 msoLogger.info( msg)
152                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
153                         }
154                         execution.setVariable("serviceType", serviceType)
155                         msoLogger.info( "serviceType:" + serviceType)
156                         
157                         String operationId = resourceInputObj.getOperationId()                  
158                         if (isBlank(operationId)) {
159                                 msg = "Input operationId is null"
160                                 msoLogger.info( msg)
161                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
162                         }
163                         execution.setVariable("operationId", operationId)
164                         msoLogger.info( "operationId:" + operationId)
165                         
166                         String resourceName = resourceInputObj.getResourceInstanceName()                        
167                         if (isBlank(resourceName)) {
168                                 msg = "Input resourceName is null"
169                                 msoLogger.info( msg)
170                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
171                         }
172                         execution.setVariable("resourceName", resourceName)
173                         msoLogger.info( "resourceInstanceId:" + resourceName)
174                         
175                         String resourceTemplateId = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
176                         if (isBlank(resourceTemplateId)) {
177                                 msg = "Input resourceTemplateId is null"
178                                 msoLogger.info( msg)
179                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
180                         }
181                         execution.setVariable("resourceTemplateId", resourceTemplateId)
182                         msoLogger.info( "resourceTemplateId:" + resourceTemplateId)
183
184                 } catch (BpmnError e) {
185                         throw e
186                 } catch (Exception ex){
187                         String msg = "Exception in preProcessRequest " + ex.getMessage()
188                         msoLogger.debug(msg)
189                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
190                 }
191         }
192
193         public void prepareUpdateProgress(DelegateExecution execution) {
194                 msoLogger.info(" ***** Started prepareUpdateProgress *****")
195                 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
196                 String operType = resourceInputObj.getOperationType()
197                 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
198                 String ServiceInstanceId = resourceInputObj.getServiceInstanceId()
199                 String modelName = resourceInputObj.getResourceModelInfo().getModelName()
200                 String operationId = resourceInputObj.getOperationId()
201                 String progress = execution.getVariable("progress")
202                 String status = execution.getVariable("status")
203                 String statusDescription = execution.getVariable("statusDescription")
204
205                 String body = """
206                 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
207                         xmlns:ns="http://org.openecomp.mso/requestsdb">
208                         <soapenv:Header/>
209                 <soapenv:Body>
210                     <ns:updateResourceOperationStatus>
211                                <operType>${operType}</operType>
212                                <operationId>${operationId}</operationId>
213                                <progress>${progress}</progress>
214                                <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
215                                <serviceId>${ServiceInstanceId}</serviceId>
216                                <status>${status}</status>
217                                <statusDescription>${statusDescription}</statusDescription>
218                     </ns:updateResourceOperationStatus>
219                 </soapenv:Body>
220                 </soapenv:Envelope>"""
221
222                 setProgressUpdateVariables(execution, body)
223                 msoLogger.info(" ***** End prepareUpdateProgress *****")
224         }
225
226         public void prepare3rdONAPRequest(DelegateExecution execution) {
227                 msoLogger.info(" ***** Started prepare3rdONAPRequest *****")
228                 
229                 String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
230                 String extAPIPath = sppartnerUrl + 'serviceOrder'
231                 execution.setVariable("ExternalAPIURL", extAPIPath)
232                 
233                 // ExternalAPI message format
234                 String externalId = execution.getVariable("resourceName")
235                 String category = "E2E Service"
236                 String description = "Service Order from SPPartner"
237                 String requestedStartDate = utils.generateCurrentTimeInUtc()
238                 String requestedCompletionDate = utils.generateCurrentTimeInUtc()
239                 String priority = "1" // 0-4 0:highest
240                 String subscriberId = execution.getVariable("globalSubscriberId")
241                 String customerRole = ""
242                 String subscriberName = ""
243                 String referredType = "Consumer"
244                 String orderItemId = "1"
245                 String action = "delete" //for delete
246                 String serviceState = "active"
247                 String serviceName = ""
248                 String serviceType = execution.getVariable("serviceType")
249                 String serviceId = execution.getVariable(Prefix + "SppartnerId")
250                 
251                 queryServicefrom3rdONAP(execution)
252                 String serviceUuId = execution.getVariable(Prefix + "serviceSpecificationId")           
253                 
254                 Map<String, String> valueMap = new HashMap<>()
255                 valueMap.put("externalId", '"' + externalId + '"')
256                 valueMap.put("category", '"' + category + '"')
257                 valueMap.put("description", '"' + description + '"')
258                 valueMap.put("requestedStartDate", '"' + requestedStartDate + '"')
259                 valueMap.put("requestedCompletionDate", '"' + requestedCompletionDate + '"')
260                 valueMap.put("priority", '"'+ priority + '"')
261                 valueMap.put("subscriberId", '"' + subscriberId + '"')
262                 valueMap.put("customerRole", '"' + customerRole + '"')
263                 valueMap.put("subscriberName", '"' + subscriberName + '"')
264                 valueMap.put("referredType", '"' + referredType + '"')
265                 valueMap.put("orderItemId", '"' + orderItemId + '"')
266                 valueMap.put("action", '"' + action + '"')
267                 valueMap.put("serviceState", '"' + serviceState + '"')
268                 valueMap.put("serviceId", '"' + serviceId + '"')
269                 valueMap.put("serviceName", '"' + serviceName + '"')
270                 valueMap.put("serviceType", '"' + serviceType + '"')
271                 valueMap.put("serviceUuId", '"' + serviceUuId + '"')
272                 
273                 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(this)             
274          
275                 valueMap.put("_requestInputs_",  "")
276                 
277                 String payload = externalAPIUtil.setTemplate(ExternalAPIUtil.PostServiceOrderRequestsTemplate, valueMap)
278                 execution.setVariable(Prefix + "Payload", payload)
279                 msoLogger.info( "Exit " + prepare3rdONAPRequest)
280         }
281         
282         private void queryServicefrom3rdONAP(DelegateExecution execution)
283         {
284                 msoLogger.info(" ***** Started queryServicefrom3rdONAP *****")
285                 
286                 //https://{api_url}/nbi/api/v1/service/{serviceinstanceid}
287                 String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
288                 String extAPIPath = sppartnerUrl + "service/" + execution.setVariable(Prefix + "SppartnerId")
289                 
290                 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(this)
291
292                 APIResponse response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
293
294                 int responseCode = response.getStatusCode()
295                 execution.setVariable(Prefix + "getServiceResponseCode", responseCode)
296                 utils.log("DEBUG", "Get Service response code is: " + responseCode)
297
298                 String extApiResponse = response.getResponseBodyAsString()
299                 JSONObject responseObj = new JSONObject(extApiResponse)
300                 execution.setVariable(Prefix + "getServiceResponse", extApiResponse)
301                 
302                 //Process Response //200 OK 201 CREATED 202 ACCEPTED
303                 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
304                 {
305                         utils.log("DEBUG", "Get Service Received a Good Response")
306                         String serviceUuid = responseObj.get("serviceSpecification.id")
307                         execution.setVariable(Prefix + "serviceSpecificationId", serviceUuid)
308                 }
309                 else{
310                         utils.log("DEBUG", "Get Service Received a Bad Response Code. Response Code is: " + responseCode)
311                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Get Service Received a bad response from 3rdONAP External API")
312                 }
313                 
314                 msoLogger.info( "Exit " + queryServicefrom3rdONAP)
315         }
316
317         public void doDeleteE2ESIin3rdONAP(DelegateExecution execution) {
318                 msoLogger.info(" ***** Started doDeleteE2ESIin3rdONAP *****")
319                 
320                 String extAPIPath = execution.getVariable("ExternalAPIURL")
321                 String payload = execution.getVariable(Prefix + "Payload")
322                 
323                 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(this)
324
325                 APIResponse response = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)
326
327                 int responseCode = response.getStatusCode()
328                 execution.setVariable(Prefix + "postServiceOrderResponseCode", responseCode)
329                 msoLogger.debug("Post ServiceOrder response code is: " + responseCode)
330
331                 String extApiResponse = response.getResponseBodyAsString()
332                 JSONObject responseObj = new JSONObject(extApiResponse)
333                 execution.setVariable(Prefix + "postServiceOrderResponse", extApiResponse)
334                 //Process Response
335                 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
336                         //200 OK 201 CREATED 202 ACCEPTED
337                 {
338                         msoLogger.debug("Post ServiceOrder Received a Good Response")
339                         String serviceOrderId = responseObj.get("ServiceOrderId")
340                         execution.setVariable(Prefix + "SuccessIndicator", true)
341                         execution.setVariable("serviceOrderId", serviceOrderId)
342                 }
343                 else{
344                         msoLogger.debug("Post ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
345                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Post ServiceOrder Received a bad response from 3rdONAP External API")
346                 }
347                 
348                 msoLogger.info( "Exit " + doDeleteE2ESIin3rdONAP)
349         }
350         
351
352         public void getE2ESIProgressin3rdONAP(DelegateExecution execution) {
353                 msoLogger.info(" ***** Started getE2ESIProgressin3rdONAP *****")
354                 
355                 String extAPIPath = execution.getVariable("ExternalAPIURL")
356                 extAPIPath += "/" + execution.getVariable("ServiceOrderId")
357                 
358                 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(this)
359
360                 APIResponse response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
361
362                 int responseCode = response.getStatusCode()
363                 execution.setVariable(Prefix + "getServiceOrderResponseCode", responseCode)
364                 msoLogger.debug("Get ServiceOrder response code is: " + responseCode)
365
366                 String extApiResponse = response.getResponseBodyAsString()
367                 JSONObject responseObj = new JSONObject(extApiResponse)
368                 execution.setVariable(Prefix + "getServiceOrderResponse", extApiResponse)
369                 
370                 //Process Response //200 OK 201 CREATED 202 ACCEPTED
371                 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )                  
372                 {
373                         msoLogger.debug("Get ServiceOrder Received a Good Response")
374                         String serviceOrderState = responseObj.get("State")
375                         execution.setVariable(Prefix + "SuccessIndicator", true)
376                         execution.setVariable("serviceOrderState", serviceOrderState)                   
377                         
378                         // Get serviceOrder State and process progress
379                         if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState)) {
380                                 execution.setVariable("progress", 15)
381                                 execution.setVariable("status", "processing")                           
382                         }
383                         if("INPROGRESS".equalsIgnoreCase(serviceOrderState)) {
384                                 execution.setVariable("progress", 40)
385                                 execution.setVariable("status", "processing")
386                         }
387                         if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
388                                 execution.setVariable("progress", 100)
389                                 execution.setVariable("status", "finished")
390                         }
391                         if("FAILED".equalsIgnoreCase(serviceOrderState)) {
392                                 execution.setVariable("progress", 100)
393                                 execution.setVariable("status", "error")
394                         }
395                         else {
396                                 execution.setVariable("progress", 100)
397                                 execution.setVariable("status", "error")
398                                 execution.setVariable("statusDescription", "Delete Service Order Status is unknown")
399                         }
400                         execution.setVariable("statusDescription", "Delete Service Order Status is " + serviceOrderState)
401                 }
402                 else{                   
403                         msoLogger.debug("Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
404                         execution.setVariable("progress", 100)
405                         execution.setVariable("status", "error")
406                         execution.setVariable("statusDescription", "Get ServiceOrder Received a bad response")
407                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Get ServiceOrder Received a bad response from 3rdONAP External API")
408                 }               
409                 
410                 msoLogger.info( "Exit " + getE2ESIProgressin3rdONAP)
411         }
412         
413         /**
414          * delay 5 sec
415          */
416         public void timeDelay(DelegateExecution execution) {
417                 try {
418                         Thread.sleep(5000)
419                 } catch(InterruptedException e) {
420                         utils.log("ERROR", "Time Delay exception" + e )
421                 }
422         }
423
424         private void getSPPartnerInAAI(DelegateExecution execution) {
425                 msoLogger.info(" ***** Started postDeleteE2ESIin3rdONAP *****") 
426                 
427                 AaiUtil aaiUriUtil = new AaiUtil(this)
428                 String serviceAaiPath = execution.getVariable(Prefix + "serviceAaiPath")                
429                 APIResponse response = aaiUriUtil.executeAAIGetCall(execution, serviceAaiPath)
430                 int responseCode = response.getStatusCode()
431                 execution.setVariable(Prefix + "GetSppartnerResponseCode", responseCode)
432                 msoLogger.debug("  Get sppartner response code is: " + responseCode)
433
434                 String aaiResponse = response.getResponseBodyAsString()
435                 aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)
436                 aaiResponse = aaiResponse.replaceAll("&", "&amp;")
437                 execution.setVariable(Prefix + "GetSppartnerResponse", aaiResponse)
438
439                 //Process Response
440                 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
441                         //200 OK 201 CREATED 202 ACCEPTED
442                 {
443                         msoLogger.debug("GET sppartner Received a Good Response")
444                         execution.setVariable(Prefix + "SuccessIndicator", true)
445                         execution.setVariable(Prefix + "FoundIndicator", true)
446                         
447                         String sppartnerId = utils.getNodeText1(aaiResponse, "sppartner-id")
448                         execution.setVariable(Prefix + "SppartnerId", sppartnerId)
449                         msoLogger.debug(" SppartnerId is: " + sppartnerId)
450                         String sppartnerUrl = utils.getNodeText1(aaiResponse, "sppartner-url")
451                         execution.setVariable(Prefix + "SppartnerUrl", sppartnerUrl)
452                         msoLogger.debug(" SppartnerUrl is: " + sppartnerUrl)
453                         String callSource = utils.getNodeText1(aaiResponse, "sppartner-callsource")
454                         execution.setVariable(Prefix + "CallSource", callSource)
455                         msoLogger.debug(" CallSource is: " + callSource)
456                         String sppartnerVersion = utils.getNodeText1(aaiResponse, "resource-version")
457                         execution.setVariable(Prefix + "SppartnerVersion", sppartnerVersion)
458                         msoLogger.debug(" Resource Version is: " + sppartnerVersion)
459                 }
460                 else
461                 {
462                         msoLogger.debug("Get sppartner Received a Bad Response Code. Response Code is: " + responseCode)
463                         exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
464                         throw new BpmnError("MSOWorkflowException")
465                 }
466                 
467                 msoLogger.info( "Exit " + deleteSPPartnerInAAI)
468         }
469         
470         public void deleteSPPartnerInAAI(DelegateExecution execution) {
471                 msoLogger.info(" ***** Started postDeleteE2ESIin3rdONAP *****")
472                 
473                 String sppartnerId = execution.getVariable(Prefix + "SppartnerId")
474                 String sppartnerUrl = execution.getVariable(Prefix + "sppartnerUrl")
475                 String sppartnerVersion = execution.getVariable(Prefix + "sppartnerVersion")
476                 
477                 AaiUtil aaiUriUtil = new AaiUtil(this)
478                 String serviceAaiPath = execution.getVariable(Prefix + "serviceAaiPath") + "?resource-version=${sppartnerVersion}"
479                 APIResponse response = aaiUriUtil.executeAAIDeleteCall(execution, serviceAaiPath)
480                 int responseCode = response.getStatusCode()
481                 execution.setVariable(Prefix + "DeleteSppartnerResponseCode", responseCode)
482                 msoLogger.debug("  Get sppartner response code is: " + responseCode)
483
484                 String aaiResponse = response.getResponseBodyAsString()
485                 aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)
486                 execution.setVariable(Prefix + "DeleteSppartnerResponse", aaiResponse)
487
488                 //Process Response
489                 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
490                         //200 OK 201 CREATED 202 ACCEPTED
491                 {
492                         msoLogger.debug("Delete sppartner Received a Good Response")
493                         execution.setVariable(Prefix + "SuccessIndicator", true)
494                 }
495                 else if(responseCode == 404){
496                         msoLogger.debug(" Delete sppartner Received a Not Found (404) Response")
497                         execution.setVariable(Prefix + "FoundIndicator", false)
498                 }
499                 else
500                 {
501                         msoLogger.debug("Delete sppartner Received a Bad Response Code. Response Code is: " + responseCode)
502                         exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
503                         throw new BpmnError("MSOWorkflowException")
504                 }
505                 
506                 msoLogger.info( "Exit " + deleteSPPartnerInAAI)
507         }
508         
509         private void setProgressUpdateVariables(DelegateExecution execution, String body) {
510                 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
511                 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
512                 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
513         }       
514
515         public void postProcess(DelegateExecution execution){
516                 msoLogger.info(" ***** Started postProcess *****")
517                 String responseCode = execution.getVariable(Prefix + "putSppartnerResponseCode")
518                 String responseObj = execution.getVariable(Prefix + "putSppartnerResponse")
519
520                 msoLogger.info("response from AAI for put sppartner, response code :" + responseCode + "  response object :" + responseObj)
521                 msoLogger.info(" ***** Exit postProcess *****")
522         }
523
524         public void sendSyncResponse (DelegateExecution execution) {
525                 msoLogger.debug(" *** sendSyncResponse *** ")
526
527                 try {
528                         String operationStatus = "finished"
529                         // RESTResponse for main flow
530                         String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
531                         msoLogger.debug(" sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
532                         sendWorkflowResponse(execution, 202, resourceOperationResp)
533                         execution.setVariable("sentSyncResponse", true)
534
535                 } catch (Exception ex) {
536                         String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
537                         msoLogger.debug(msg)
538                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
539                 }
540                 msoLogger.debug(" ***** Exit sendSyncResopnse *****")
541         }
542 }