Merge "Fix logging in groovy file"
[so.git] / bpmn / so-bpmn-infrastructure-flows / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / Create3rdONAPE2EServiceInstance.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
44 import org.camunda.bpm.engine.runtime.Execution
45 import org.camunda.bpm.engine.delegate.BpmnError
46 import org.camunda.bpm.engine.delegate.DelegateExecution
47 import org.apache.commons.lang3.*
48 import org.apache.commons.codec.binary.Base64;
49 import org.springframework.web.util.UriUtils
50 import org.onap.so.rest.RESTClient
51 import org.onap.so.rest.RESTConfig
52
53 /**
54  * This groovy class supports the <class>Create3rdONAPE2EServiceInstance.bpmn</class> process.
55  * flow for Create E2EServiceInstance in 3rdONAP 
56  */
57 public class Create3rdONAPE2EServiceInstance extends AbstractServiceTaskProcessor {
58
59         String Prefix="CRE3rdONAPESI_"
60
61         ExceptionUtil exceptionUtil = new ExceptionUtil()
62
63         JsonUtils jsonUtil = new JsonUtils()
64
65         public void checkSPPartnerInfo (DelegateExecution execution) {
66                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
67                 utils.log("INFO"," ***** Started checkSPPartnerInfo *****",  isDebugEnabled)
68                 try {
69                         //get bpmn inputs from resource request.
70                         String requestId = execution.getVariable("mso-request-id")
71                         String requestAction = execution.getVariable("requestAction")
72                         utils.log("INFO","The requestAction is: " + requestAction,  isDebugEnabled)
73                         String recipeParamsFromRequest = execution.getVariable("recipeParams")
74                         utils.log("INFO","The recipeParams is: " + recipeParamsFromRequest,  isDebugEnabled)
75                         String resourceInput = execution.getVariable("resourceInput")
76                         utils.log("INFO","The resourceInput is: " + resourceInput,  isDebugEnabled)
77                         //Get ResourceInput Object
78                         ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)                       
79                         String resourceInputPrameters = resourceInputObj.getResourceParameters()
80                         String inputParametersJson = jsonUtil.getJsonValue(resourceInputPrameters, "requestInputs")
81                         JSONObject inputParameters = new JSONObject(customizeResourceParam(inputParametersJson))
82                         
83                         // set local resourceInput
84                         execution.setVariable(Prefix + "resourceInput", resourceInputObj)
85                         
86                         boolean is3rdONAPExist = false
87
88                         if(inputParameters.has("id"))
89                         {
90                                 String sppartnerId = inputParameters.get("id")
91                         }
92                         if(inputParameters.has("url"))
93                         {
94                                 String sppartnerUrl = inputParameters.get("url")
95                                 if(!isBlank(sppartnerUrl)) {
96                                         execution.setVariable(Prefix + "sppartnerUrl", sppartnerUrl)
97                                         is3rdONAPExist = true
98                                 }
99                                 else {
100                                         is3rdONAPExist = false
101                                         String msg = "sppartner Url is blank."
102                                         utils.log("DEBUG", msg, isDebugEnabled)
103                                 }
104                         }
105                         if(inputParameters.has("providingServiceInvarianteUuid"))
106                         {
107                                 String sppartnerInvarianteUUID = inputParameters.get("providingServiceInvarianteUuid")
108                                 execution.setVariable(Prefix + "sppartnerInvarianteUUID", sppartnerInvarianteUUID)
109                                 is3rdONAPExist = true
110                         }
111                         else {
112                                 is3rdONAPExist = false
113                                 String msg = "sppartner providingServiceInvarianteUuid is blank."
114                                 utils.log("DEBUG", msg, isDebugEnabled)
115                         }
116                         if(inputParameters.has("providingServiceUuid"))
117                         {
118                                 String sppartnerUUID = inputParameters.get("providingServiceUuid")
119                                 execution.setVariable(Prefix + "sppartnerUUID", sppartnerUUID)
120                                 is3rdONAPExist = true
121                         }
122                         else {
123                                 is3rdONAPExist = false
124                                 String msg = "sppartner providingServiceUuid is blank."
125                                 utils.log("DEBUG", msg, isDebugEnabled)
126                         }
127                         
128                         if(inputParameters.has("handoverMode"))
129                         {
130                                 String handoverMode = inputParameters.get("handoverMode")
131                                 execution.setVariable(Prefix + "handoverMode", handoverMode)
132                             is3rdONAPExist = true
133                         }
134                         else {
135                                 is3rdONAPExist = false
136                                 String msg = "sppartner handoverMode is blank."
137                                 utils.log("DEBUG", msg, isDebugEnabled)
138                         }
139                         
140                         execution.setVariable("Is3rdONAPExist", is3rdONAPExist)
141                         execution.setVariable(Prefix + "serviceInstanceId", resourceInputObj.getServiceInstanceId())
142                         execution.setVariable("mso-request-id", requestId)
143                         execution.setVariable("mso-service-instance-id", resourceInputObj.getServiceInstanceId())
144
145                 } catch (BpmnError e) {
146                         throw e;
147                 } catch (Exception ex){
148                         String msg = "Exception in checkSPPartnerInfo " + ex.getMessage()
149                         utils.log("DEBUG", msg, isDebugEnabled)
150                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
151                 }
152         }
153
154         public void checkLocallCall (DelegateExecution execution) {
155                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
156                 utils.log("INFO"," ***** Started checkLocallCall *****",  isDebugEnabled)
157                 try {
158                                         
159                         //Get ResourceInput Object
160                         ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput")                        
161
162                         //uuiRequest
163                         String incomingRequest = resourceInputObj.getRequestsInputs()
164                         String serviceParameters = jsonUtil.getJsonValue(incomingRequest, "service.parameters")
165                         JSONObject inputParameters = new JSONObject(customizeResourceParam(serviceParameters))
166                         execution.setVariable(Prefix + "serviceParameters", inputParameters)
167                         
168                         // CallSource is added only when ONAP SO calling 3rdONAP SO(Remote call)
169                         boolean isLocalCall = true
170                         if(inputParameters.has("CallSource"))
171                         {
172                                 String callSource = inputParameters.get("CallSource")
173                                 if("3rdONAP".equalsIgnoreCase(callSource)) {
174                                         isLocalCall = false
175                                 }
176                                 execution.setVariable(Prefix + "CallSource", callSource)
177                                 utils.log("DEBUG", "callSource is: " + callSource , isDebugEnabled)
178                                 isLocalCall = true
179                         }
180                         
181                         execution.setVariable("IsLocalCall", isLocalCall)
182
183                 } catch (BpmnError e) {
184                         throw e;
185                 } catch (Exception ex){
186                         String msg = "Exception in checkLocallCall " + ex.getMessage()
187                         utils.log("DEBUG", msg, isDebugEnabled)
188                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
189                 }
190         }
191
192         public void preProcessRequest(DelegateExecution execution){
193                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
194                 utils.log("INFO"," ***** Started preProcessRequest *****",  isDebugEnabled)
195                 try {
196                         ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput")
197                         String msg = ""
198
199                         String globalSubscriberId = resourceInputObj.getGlobalSubscriberId()
200                         if (isBlank(globalSubscriberId)) {
201                                 msg = "Input globalSubscriberId is null"
202                                 utils.log("INFO", msg, isDebugEnabled)
203                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
204                         }
205                         //set local variable
206                         execution.setVariable("globalSubscriberId", globalSubscriberId);
207                         utils.log("INFO", "globalSubscriberId:" + globalSubscriberId, isDebugEnabled)
208
209                         String serviceType = resourceInputObj.getServiceType()
210                         if (isBlank(serviceType)) {
211                                 msg = "Input serviceType is null"
212                                 utils.log("INFO", msg, isDebugEnabled)
213                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
214                         }
215                         execution.setVariable("serviceType", serviceType)
216                         utils.log("INFO", "serviceType:" + serviceType, isDebugEnabled)
217                         
218                         String resourceName = resourceInputObj.getResourceInstanceName();
219                         if (isBlank(resourceName)) {
220                                 msg = "Input resourceName is null"
221                                 utils.log("INFO", msg, isDebugEnabled)
222                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
223                         }
224                         execution.setVariable("resourceName", resourceName)
225                         utils.log("INFO", "resourceName:" + resourceName, isDebugEnabled)
226                         
227                         int beginIndex = resourceName.indexOf("_") + 1
228                         String serviceInstanceName = resourceName.substring(beginIndex)
229                         execution.setVariable("serviceInstanceName", serviceInstanceName)
230                         
231                         String serviceInstanceId = resourceInputObj.getServiceInstanceId();
232                         if (isBlank(serviceInstanceId)) {
233                                 msg = "Input serviceInstanceId is null"
234                                 utils.log("INFO", msg, isDebugEnabled)
235                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
236                         }
237                         execution.setVariable("serviceInstanceId", serviceInstanceId)
238                         utils.log("INFO", "serviceInstanceId:" + serviceInstanceId, isDebugEnabled)
239
240                 } catch (BpmnError e) {
241                         throw e;
242                 } catch (Exception ex){
243                         String msg = "Exception in preProcessRequest " + ex.getMessage()
244                         utils.log("DEBUG", msg, isDebugEnabled)
245                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
246                 }
247         }
248
249         public void prepareUpdateProgress(DelegateExecution execution) {
250                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
251                 utils.log("INFO"," ***** Started prepareUpdateProgress *****",  isDebugEnabled)
252                 ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput")
253                 String operType = resourceInputObj.getOperationType()
254                 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
255                 String ServiceInstanceId = resourceInputObj.getServiceInstanceId()
256                 String modelName = resourceInputObj.getResourceModelInfo().getModelName()
257                 String operationId = resourceInputObj.getOperationId()
258                 String progress = execution.getVariable("progress")
259                 String status = execution.getVariable("status")
260                 String statusDescription = execution.getVariable("statusDescription")
261
262                 String body = """
263                 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
264                         xmlns:ns="http://org.openecomp.mso/requestsdb">
265                         <soapenv:Header/>
266                 <soapenv:Body>
267                     <ns:updateResourceOperationStatus>
268                                <operType>${operType}</operType>
269                                <operationId>${operationId}</operationId>
270                                <progress>${progress}</progress>
271                                <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
272                                <serviceId>${ServiceInstanceId}</serviceId>
273                                <status>${status}</status>
274                                <statusDescription>${statusDescription}</statusDescription>
275                     </ns:updateResourceOperationStatus>
276                 </soapenv:Body>
277                 </soapenv:Envelope>""";
278
279                 setProgressUpdateVariables(execution, body)
280                 utils.log("INFO"," ***** End prepareUpdateProgress *****",  isDebugEnabled)
281         }
282
283         public void allocateCrossONAPResource(DelegateExecution execution) {
284                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
285                 utils.log("INFO"," ***** Started allocateCrossONAPResource *****",  isDebugEnabled)
286                 
287                 //get TP links from AAI for SOTN handoverMode only
288                 String handoverMode = execution.getVariable(Prefix + "handoverMode")
289                 if("SOTN".equalsIgnoreCase(handoverMode)) {
290                         //to do get tp link in AAI
291                         
292                         
293                         // Put TP Link info into serviceParameters
294                         String accessProviderId = ""
295                         String accessClientId = ""
296                         String accessTopologyId = ""
297                         String accessNodeId = ""
298                         String accessLtpId = ""
299                         JSONObject inputParameters = execution.getVariable(Prefix + "serviceParameters")                        
300                         inputParameters.put("access-provider-id", accessProviderId)
301                         inputParameters.put("access-client-id", accessClientId)
302                         inputParameters.put("access-topology-id", accessTopologyId)
303                         inputParameters.put("access-node-id", accessNodeId)
304                         inputParameters.put("access-ltp-id", accessLtpId)
305                         execution.setVariable(Prefix + "serviceParameters", inputParameters)
306                 }
307                 
308                 utils.log("INFO", "Exited " + allocateCrossONAPResource, isDebugEnabled)
309         }
310
311         public void prepare3rdONAPRequest(DelegateExecution execution) {
312                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
313                 utils.log("INFO"," ***** Started prepare3rdONAPRequest *****",  isDebugEnabled)
314                 
315                 String sppartnerUrl = execution.getVariable(Prefix + "sppartnerUrl")
316                 String extAPIPath = sppartnerUrl + 'serviceOrder'
317                 execution.setVariable("ExternalAPIURL", extAPIPath)
318                 
319                 // ExternalAPI message format
320                 String externalId = execution.getVariable("resourceName")
321                 String category = "Network Service"
322                 String description = "Service Order from SPPartner"
323                 String requestedStartDate = utils.generateCurrentTimeInUtc()
324                 String requestedCompletionDate = utils.generateCurrentTimeInUtc()
325                 String priority = "1" // 0-4 0:highest
326                 String subscriberId = execution.getVariable("globalSubscriberId")
327                 String customerRole = ""
328                 String subscriberName = ""
329                 String referredType = execution.getVariable("serviceType")
330                 String orderItemId = "1"
331                 String action = "add" //for create
332                 String serviceState = "active"
333                 String serviceName = execution.getVariable("serviceInstanceName")
334                 String serviceId = execution.getVariable("serviceInstanceId")
335                 
336                 Map<String, String> valueMap = new HashMap<>()
337                 valueMap.put("externalId", '"' + externalId + '"')
338                 valueMap.put("category", '"' + category + '"')
339                 valueMap.put("description", '"' + description + '"')
340                 valueMap.put("requestedStartDate", '"' + requestedStartDate + '"')
341                 valueMap.put("requestedCompletionDate", '"' + requestedCompletionDate + '"')
342                 valueMap.put("priority", '"'+ priority + '"')
343                 valueMap.put("subscriberId", '"' + subscriberId + '"')
344                 valueMap.put("customerRole", '"' + customerRole + '"')
345                 valueMap.put("subscriberName", '"' + subscriberName + '"')
346                 valueMap.put("referredType", '"' + referredType + '"')
347                 valueMap.put("orderItemId", '"' + orderItemId + '"')
348                 valueMap.put("action", '"' + action + '"')
349                 valueMap.put("serviceState", '"' + serviceState + '"')
350                 valueMap.put("serviceName", '"' + serviceName + '"')
351                 valueMap.put("serviceId", '"' + serviceId + '"')
352                 
353                 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(this)
354                 
355                 // insert CallSource='3rdONAP' to uuiRequest            
356                 Map<String, String> callSourceMap = new HashMap<>()
357                 callSourceMap.put("inputName", "CallSource")
358                 callSourceMap.put("inputValue", "3rdONAP")
359                 String _requestInputs_ = externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, callSourceMap)
360                 
361                 // Transfer all uuiRequest incomeParameters to ExternalAPI format
362                 JSONObject inputParameters = execution.getVariable(Prefix + "serviceParameters")
363                 for(String key : inputParameters.keySet()) {                    
364                         String inputName = key;
365                         String inputValue = inputParameters.opt(key);
366                         Map<String, String> requestInputsMap = new HashMap<>()
367                         requestInputsMap.put("inputName", '"' + inputName+ '"')
368                         requestInputsMap.put("inputValue", '"' + inputValue + '"')
369                         _requestInputs_ += ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
370                 }                
371                 valueMap.put("_requestInputs_",  _requestInputs_)
372                 
373                 String payload = externalAPIUtil.setTemplate(ExternalAPIUtil.PostServiceOrderRequestsTemplate, valueMap)
374                 execution.setVariable(Prefix + "payload", payload)
375                 utils.log("INFO", "Exited " + prepare3rdONAPRequest, isDebugEnabled)
376         }
377
378         public void doCreateE2ESIin3rdONAP(DelegateExecution execution) {
379                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
380                 utils.log("INFO"," ***** Started doCreateE2ESIin3rdONAP *****",  isDebugEnabled)
381                 
382                 String extAPIPath = execution.getVariable("ExternalAPIURL")
383                 String payload = execution.getVariable(Prefix + "payload")
384                 
385                 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(this)
386
387                 APIResponse response = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)
388
389                 int responseCode = response.getStatusCode()
390                 execution.setVariable(Prefix + "postServiceOrderResponseCode", responseCode)
391                 utils.log("DEBUG", "Post ServiceOrder response code is: " + responseCode, isDebugEnabled)
392
393                 String extApiResponse = response.getResponseBodyAsString()
394                 JSONObject responseObj = new JSONObject(extApiResponse)
395                 execution.setVariable(Prefix + "postServiceOrderResponse", extApiResponse)
396                 //Process Response
397                 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
398                         //200 OK 201 CREATED 202 ACCEPTED
399                 {
400                         utils.log("DEBUG", "Post ServiceOrder Received a Good Response", isDebugEnabled)
401                         String serviceOrderId = responseObj.get("ServiceOrderId")
402                         execution.setVariable(Prefix + "SuccessIndicator", true)
403                         execution.setVariable("serviceOrderId", serviceOrderId)
404                 }
405                 else{
406                         utils.log("DEBUG", "Post ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode, isDebugEnabled)
407                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Post ServiceOrder Received a bad response from 3rdONAP External API")
408                 }
409                 
410                 utils.log("INFO", "Exited " + doCreateE2ESIin3rdONAP, isDebugEnabled)
411         }
412         
413
414         public void getE2ESIProgressin3rdONAP(DelegateExecution execution) {
415                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
416                 utils.log("INFO"," ***** Started getE2ESIProgressin3rdONAP *****",  isDebugEnabled)
417                 
418                 String extAPIPath = execution.getVariable("ExternalAPIURL")
419                 extAPIPath += "/" + execution.getVariable("ServiceOrderId")
420                 
421                 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(this)
422
423                 APIResponse response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
424
425                 int responseCode = response.getStatusCode()
426                 execution.setVariable(Prefix + "getServiceOrderResponseCode", responseCode)
427                 utils.log("DEBUG", "Get ServiceOrder response code is: " + responseCode, isDebugEnabled)
428
429                 String extApiResponse = response.getResponseBodyAsString()
430                 JSONObject responseObj = new JSONObject(extApiResponse)
431                 execution.setVariable(Prefix + "getServiceOrderResponse", extApiResponse)
432                 
433                 //Process Response //200 OK 201 CREATED 202 ACCEPTED
434                 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )                  
435                 {
436                         utils.log("DEBUG", "Get ServiceOrder Received a Good Response", isDebugEnabled)
437                         String serviceOrderState = responseObj.get("State")
438                         execution.setVariable(Prefix + "SuccessIndicator", true)
439                         execution.setVariable("serviceOrderState", serviceOrderState)                   
440                         
441                         // Get serviceOrder State and process progress
442                         if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState)) {
443                                 execution.setVariable("progress", 15)
444                                 execution.setVariable("status", "processing")                           
445                         }
446                         if("INPROGRESS".equalsIgnoreCase(serviceOrderState)) {
447                                 execution.setVariable("progress", 40)
448                                 execution.setVariable("status", "processing")
449                         }
450                         if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
451                                 execution.setVariable("progress", 100)
452                                 execution.setVariable("status", "finished")
453                         }
454                         if("FAILED".equalsIgnoreCase(serviceOrderState)) {
455                                 execution.setVariable("progress", 100)
456                                 execution.setVariable("status", "error")
457                         }
458                         else {
459                                 execution.setVariable("progress", 100)
460                                 execution.setVariable("status", "error")
461                                 execution.setVariable("statusDescription", "Create Service Order Status is unknown")
462                         }
463                         execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
464                 }
465                 else{                   
466                         utils.log("DEBUG", "Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode, isDebugEnabled)
467                         execution.setVariable("progress", 100)
468                         execution.setVariable("status", "error")
469                         execution.setVariable("statusDescription", "Get ServiceOrder Received a bad response")
470                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Get ServiceOrder Received a bad response from 3rdONAP External API")
471                 }               
472                 
473                 utils.log("INFO", "Exited " + getE2ESIProgressin3rdONAP, isDebugEnabled)
474         }
475         
476         /**
477          * delay 5 sec
478          */
479         public void timeDelay(DelegateExecution execution) {
480                 def isDebugEnabled= execution.getVariable("isDebugLogEnabled")
481                 try {
482                         Thread.sleep(5000);
483                 } catch(InterruptedException e) {
484                         utils.log("ERROR", "Time Delay exception" + e , isDebugEnabled)
485                 }
486         }
487
488         public void saveSPPartnerInAAI(DelegateExecution execution) {
489                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
490                 utils.log("INFO"," ***** Started postCreateE2ESIin3rdONAP *****",  isDebugEnabled)      
491                 
492                 String sppartnerId = UUID.randomUUID().toString()
493                 String sppartnerUrl = execution.getVariable(Prefix + "sppartnerUrl")
494                 String serviceInstanceId = execution.getVariable("serviceInstanceId")
495                 
496                 AaiUtil aaiUriUtil = new AaiUtil(this)
497                 String aai_uri = aaiUriUtil.getBusinessSPPartnerUri(execution)
498                 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
499                 
500                 String payload =
501                                 """<sp-partner xmlns=\"${namespace}\">
502                                 <id>${sppartnerId}</id>
503                                 <url>${sppartnerUrl}</url>
504                                         <service-instance>                                      
505                                             <service-instance-id>${serviceInstanceId}</service-instance-id>                                 
506                                     </service-instance>
507                                         </sp-partner>""".trim()
508                 utils.logAudit(payload)
509                 
510                 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
511                 String serviceAaiPath = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(sppartnerId,"UTF-8")
512                 
513                 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, serviceAaiPath, payload)
514                 int responseCode = response.getStatusCode()
515                 execution.setVariable(Prefix + "putSppartnerResponseCode", responseCode)
516                 utils.log("DEBUG", "  Put sppartner response code is: " + responseCode, isDebugEnabled)
517
518                 String aaiResponse = response.getResponseBodyAsString()
519                 aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)
520                 execution.setVariable(Prefix + "putSppartnerResponse", aaiResponse)
521
522                 //Process Response
523                 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
524                         //200 OK 201 CREATED 202 ACCEPTED
525                 {
526                         utils.log("DEBUG", "PUT sppartner Received a Good Response", isDebugEnabled)
527                         execution.setVariable(Prefix + "SuccessIndicator", true)
528                 }
529                 else
530                 {
531                         utils.log("DEBUG", "Put sppartner Received a Bad Response Code. Response Code is: " + responseCode, isDebugEnabled)
532                         exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
533                         throw new BpmnError("MSOWorkflowException")
534                 }
535                 
536                 utils.log("INFO", "Exited " + saveSPPartnerInAAI, isDebugEnabled)
537         }
538
539         private void setProgressUpdateVariables(DelegateExecution execution, String body) {
540                 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
541                 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
542                 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
543         }       
544
545         public void postProcess(DelegateExecution execution){
546                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
547                 utils.log("INFO"," ***** Started postProcess *****",  isDebugEnabled)
548                 String responseCode = execution.getVariable(Prefix + "putSppartnerResponseCode")
549                 String responseObj = execution.getVariable(Prefix + "putSppartnerResponse")
550
551                 utils.log("INFO","response from AAI for put sppartner, response code :" + responseCode + "  response object :" + responseObj,  isDebugEnabled)
552                 utils.log("INFO"," ***** Exit postProcess *****",  isDebugEnabled)
553         }
554
555         public void sendSyncResponse (DelegateExecution execution) {
556                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
557                 utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled)
558
559                 try {
560                         String operationStatus = "finished"
561                         // RESTResponse for main flow
562                         String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
563                         utils.log("DEBUG", " sendSyncResponse to APIH:" + "\n" + resourceOperationResp, isDebugEnabled)
564                         sendWorkflowResponse(execution, 202, resourceOperationResp)
565                         execution.setVariable("sentSyncResponse", true)
566
567                 } catch (Exception ex) {
568                         String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
569                         utils.log("DEBUG", msg, isDebugEnabled)
570                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
571                 }
572                 utils.log("DEBUG"," ***** Exit sendSyncResopnse *****",  isDebugEnabled)
573         }
574         
575         String customizeResourceParam(String inputParametersJson) {
576                 List<Map<String, Object>> paramList = new ArrayList();
577                 JSONObject jsonObject = new JSONObject(inputParametersJson);
578                 Iterator iterator = jsonObject.keys();
579                 while (iterator.hasNext()) {
580                         String key = iterator.next();
581                         HashMap<String, String> hashMap = new HashMap();
582                         hashMap.put("name", key);
583                         hashMap.put("value", jsonObject.get(key))
584                         paramList.add(hashMap)
585                 }
586                 Map<String, List<Map<String, Object>>> paramMap = new HashMap();
587                 paramMap.put("param", paramList);
588
589                 return  new JSONObject(paramMap).toString();
590         }
591 }