Add unit tests for ExternalAPIUtil
[so.git] / bpmn / so-bpmn-infrastructure-common / 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.JSONArray
24 import org.json.JSONObject
25 import org.json.XML
26 import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
27
28 import static org.apache.commons.lang3.StringUtils.*
29 import groovy.xml.XmlUtil
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
33 import org.onap.so.bpmn.common.scripts.MsoUtils
34 import org.onap.aai.domain.yang.SpPartner
35 import org.onap.so.bpmn.common.recipe.ResourceInput
36 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
37 import org.onap.so.bpmn.core.WorkflowException
38 import org.onap.so.bpmn.core.json.JsonUtils
39 import org.onap.so.bpmn.core.UrnPropertiesReader
40 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder
41 import org.onap.so.client.aai.AAIObjectType
42 import org.onap.so.client.aai.AAIResourcesClient
43 import org.onap.so.client.aai.entities.uri.AAIResourceUri
44 import org.onap.so.client.aai.entities.uri.AAIUriFactory
45 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
46 import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory
47 import java.util.Map
48 import java.util.UUID
49 import javax.ws.rs.core.Response
50 import org.onap.so.logger.MsoLogger
51
52 import org.camunda.bpm.engine.runtime.Execution
53 import org.camunda.bpm.engine.delegate.BpmnError
54 import org.camunda.bpm.engine.delegate.DelegateExecution
55 import org.apache.commons.lang3.*
56 import org.apache.commons.codec.binary.Base64
57
58
59 /**
60  * This groovy class supports the <class>Create3rdONAPE2EServiceInstance.bpmn</class> process.
61  * flow for Create E2EServiceInstance in 3rdONAP
62  */
63 public class Create3rdONAPE2EServiceInstance extends AbstractServiceTaskProcessor {
64
65         String Prefix = "CRE3rdONAPESI_"
66
67         ExceptionUtil exceptionUtil = new ExceptionUtil()
68
69         JsonUtils jsonUtil = new JsonUtils()
70
71         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, Create3rdONAPE2EServiceInstance.class)
72
73         public void checkSPPartnerInfo (DelegateExecution execution) {
74                 msoLogger.info(" ***** Started checkSPPartnerInfo *****")
75                 try {
76                         //get bpmn inputs from resource request.
77                         String requestId = execution.getVariable("mso-request-id")
78                         String requestAction = execution.getVariable("requestAction")
79                         msoLogger.info("The requestAction is: " + requestAction)
80                         String recipeParamsFromRequest = execution.getVariable("recipeParams")
81                         msoLogger.info("The recipeParams is: " + recipeParamsFromRequest)
82                         String resourceInput = execution.getVariable("resourceInput")
83                         msoLogger.info("The resourceInput is: " + resourceInput)
84                         //Get ResourceInput Object
85                         ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
86                         String resourceInputPrameters = resourceInputObj.getResourceParameters()
87                         String inputParametersJson = JsonUtils.getJsonValue(resourceInputPrameters, "requestInputs")
88                         JSONObject inputParameters = new JSONObject(inputParametersJson)
89
90                         // set local resourceInput
91                         execution.setVariable(Prefix + "ResourceInput", resourceInputObj)
92
93                         boolean is3rdONAPExist = false
94
95                         if(inputParameters.has("sppartner_url"))
96                         {
97                                 String sppartnerUrl = inputParameters.get("sppartner_url")
98                                 if(!isBlank(sppartnerUrl)) {
99                                         execution.setVariable(Prefix + "SppartnerUrl", sppartnerUrl)
100                                         is3rdONAPExist = true
101                                 }
102                                 else {
103                                         is3rdONAPExist = false
104                                         String msg = "sppartner Url is blank."
105                                         msoLogger.debug(msg)
106                                 }
107                         }
108                         if(inputParameters.has("sppartner_providingServiceUuid"))
109                         {
110                                 String sppartnerUUID= inputParameters.get("sppartner_providingServiceUuid")
111                                 execution.setVariable(Prefix + "SppartnerUUID", sppartnerUUID)
112                                 is3rdONAPExist = true
113                         }
114                         else {
115                                 is3rdONAPExist = false
116                                 String msg = "sppartner providingServiceUuid is blank."
117                                 msoLogger.debug(msg)
118                         }
119                         if(inputParameters.has("sppartner_providingServiceInvariantUuid"))
120                         {
121                                 String sppartnerInvarianteUUID  = inputParameters.get("sppartner_providingServiceInvariantUuid")
122                                 execution.setVariable(Prefix + "SppartnerInvarianteUUID", sppartnerInvarianteUUID)
123                                 is3rdONAPExist = true
124                         }
125                         else {
126                                 is3rdONAPExist = false
127                                 String msg = "sppartner providingServiceInvarianteUuid is blank."
128                                 msoLogger.debug(msg)
129                         }
130
131                         if(inputParameters.has("sppartner_handoverMode"))
132                         {
133                                 String handoverMode = inputParameters.get("sppartner_handoverMode")
134                                 execution.setVariable(Prefix + "HandoverMode", handoverMode)
135                             is3rdONAPExist = true
136                         }
137                         else {
138                                 is3rdONAPExist = false
139                                 String msg = "sppartner handoverMode is blank."
140                                 msoLogger.debug(msg)
141                         }
142
143                         execution.setVariable("Is3rdONAPExist", is3rdONAPExist)
144                         execution.setVariable(Prefix + "ServiceInstanceId", resourceInputObj.getServiceInstanceId())
145                         execution.setVariable("mso-request-id", requestId)
146                         execution.setVariable("mso-service-instance-id", resourceInputObj.getServiceInstanceId())
147
148                 } catch (Exception ex){
149                         String msg = "Exception in checkSPPartnerInfo " + ex.getMessage()
150                         msoLogger.debug(msg)
151 //                      exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
152                 }
153         }
154
155         public void checkLocallCall (DelegateExecution execution) {
156                 msoLogger.info(" ***** Started checkLocallCall *****")
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 = JsonUtils.getJsonValue(incomingRequest, "service.parameters")
165                         String requestInputs = JsonUtils.getJsonValue(serviceParameters, "requestInputs")
166                         JSONObject inputParameters = new JSONObject(requestInputs)
167                         execution.setVariable(Prefix + "ServiceParameters", inputParameters)
168
169                         // CallSource is added only when ONAP SO calling 3rdONAP(External API) SO(Remote call)
170                         boolean isLocalCall = true
171                         String callSource = "UUI"
172                         if(inputParameters.has("CallSource"))
173                         {
174                                 callSource = inputParameters.get("CallSource")
175                                 if("ExternalAPI".equalsIgnoreCase(callSource)) {
176                                         String sppartnerId = inputParameters.get("SppartnerServiceId")
177                                         execution.setVariable(Prefix + "SppartnerServiceId", sppartnerId)
178                                         isLocalCall = false
179                                 }
180                         }
181                         execution.setVariable(Prefix + "CallSource", callSource)
182                         msoLogger.debug("callSource is: " + callSource )
183
184                         execution.setVariable("IsLocalCall", isLocalCall)
185
186                 } catch (Exception ex){
187                         String msg = "Exception in checkLocallCall " + ex.getMessage()
188                         msoLogger.debug(msg)
189 //                      exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
190                 }
191         }
192
193         public void preProcessRequest(DelegateExecution execution){
194                 msoLogger.info(" ***** Started preProcessRequest *****")
195                 String msg = ""
196
197                 try {
198                         ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
199
200                         String globalSubscriberId = resourceInputObj.getGlobalSubscriberId()
201                         if (isBlank(globalSubscriberId)) {
202                                 msg = "Input globalSubscriberId is null"
203                                 msoLogger.error(msg)
204                         }
205                         //set local variable
206                         execution.setVariable("globalSubscriberId", globalSubscriberId)
207                         msoLogger.info("globalSubscriberId:" + globalSubscriberId)
208
209                         String serviceType = resourceInputObj.getServiceType()
210                         if (isBlank(serviceType)) {
211                                 msg = "Input serviceType is null"
212                                 msoLogger.error(msg)
213                         }
214                         execution.setVariable("serviceType", serviceType)
215                         msoLogger.info("serviceType:" + serviceType)
216
217                         String resourceName = resourceInputObj.getResourceInstanceName()
218                         if (isBlank(resourceName)) {
219                                 msg = "Input resourceName is null"
220                                 msoLogger.error(msg)
221                         }
222                         execution.setVariable("resourceName", resourceName)
223                         msoLogger.info("resourceName:" + resourceName)
224
225                         int beginIndex = resourceName.indexOf("_") + 1
226                         String serviceInstanceName = resourceName.substring(beginIndex)
227                         execution.setVariable("serviceInstanceName", serviceInstanceName)
228
229                         String serviceInstanceId = resourceInputObj.getServiceInstanceId()
230                         if (isBlank(serviceInstanceId)) {
231                                 msg = "Input serviceInstanceId is null"
232                                 msoLogger.error(msg)
233                         }
234                         execution.setVariable(Prefix + "ServiceInstanceId", serviceInstanceId)
235                         msoLogger.info("serviceInstanceId:" + serviceInstanceId)
236
237                         String resourceModelInvariantUuid = resourceInputObj.getResourceModelInfo().getModelInvariantUuid()
238                         if (isBlank(resourceModelInvariantUuid)) {
239                                 msg = "Input resourceModelInvariantUuid is null"
240                                 msoLogger.error(msg)
241                         }
242                         execution.setVariable(Prefix + "ResourceModelInvariantUuid", resourceModelInvariantUuid)
243                         msoLogger.info("resourceModelInvariantUuid:" + resourceModelInvariantUuid)
244
245                         String resourceModelUuid = resourceInputObj.getResourceModelInfo().getModelUuid()
246                         if (isBlank(resourceModelUuid)) {
247                                 msg = "Input resourceModelUuid is null"
248                                 msoLogger.error(msg)
249                         }
250                         execution.setVariable(Prefix + "ResourceModelUuid", resourceModelUuid)
251                         msoLogger.info("resourceModelUuid:" + resourceModelUuid)
252
253                         String resourceModelCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
254                         if (isBlank(resourceModelCustomizationUuid)) {
255                                 msg = "Input resourceModelCustomizationUuid is null"
256                                 msoLogger.error(msg)
257                         }
258                         execution.setVariable(Prefix + "ResourceModelCustomizationUuid", resourceModelCustomizationUuid)
259                         msoLogger.info("resourceModelCustomizationUuid:" + resourceModelCustomizationUuid)
260
261                 } catch (Exception ex){
262                         msg = "Exception in preProcessRequest " + ex.getMessage()
263                         msoLogger.debug(msg)
264 //                      exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
265                 }
266         }
267
268         public void prepareUpdateProgress(DelegateExecution execution) {
269                 msoLogger.info(" ***** Started prepareUpdateProgress *****")
270                 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
271                 String operType = resourceInputObj.getOperationType()
272                 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
273                 String ServiceInstanceId = resourceInputObj.getServiceInstanceId()
274                 String modelName = resourceInputObj.getResourceModelInfo().getModelName()
275                 String operationId = resourceInputObj.getOperationId()
276                 String progress = execution.getVariable("progress")
277                 String status = execution.getVariable("status")
278                 String statusDescription = execution.getVariable("statusDescription")
279
280                 String body = """
281                 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
282                         xmlns:ns="http://org.onap.so/requestsdb">
283                         <soapenv:Header/>
284                 <soapenv:Body>
285                     <ns:updateResourceOperationStatus>
286                                <operType>${operType}</operType>
287                                <operationId>${operationId}</operationId>
288                                <progress>${progress}</progress>
289                                <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
290                                <serviceId>${ServiceInstanceId}</serviceId>
291                                <status>${status}</status>
292                                <statusDescription>${statusDescription}</statusDescription>
293                     </ns:updateResourceOperationStatus>
294                 </soapenv:Body>
295                 </soapenv:Envelope>"""
296
297                 setProgressUpdateVariables(execution, body)
298                 msoLogger.info(" ***** Exit prepareUpdateProgress *****")
299         }
300
301         public void allocateCrossONAPResource(DelegateExecution execution) {
302                 msoLogger.info(" ***** Started allocateCrossONAPResource *****")
303
304                 //get TP links from AAI for SOTN handoverMode only
305                 String handoverMode = execution.getVariable(Prefix + "HandoverMode")
306                 if("SOTN".equalsIgnoreCase(handoverMode)) {
307                         // Put TP Link info into serviceParameters
308                         JSONObject inputParameters = execution.getVariable(Prefix + "ServiceParameters")
309                         if(inputParameters.has("remote-access-provider-id")) {
310                                 Map<String, Object> crossTPs = new HashMap<String, Object>();
311                                 crossTPs.put("local-access-provider-id", inputParameters.get("remote-access-provider-id"));
312                                 crossTPs.put("local-access-client-id", inputParameters.get("remote-access-client-id"));
313                                 crossTPs.put("local-access-topology-id", inputParameters.get("remote-access-topology-id"));
314                                 crossTPs.put("local-access-node-id", inputParameters.get("remote-access-node-id"));
315                                 crossTPs.put("local-access-ltp-id", inputParameters.get("remote-access-ltp-id"));
316                                 crossTPs.put("remote-access-provider-id", inputParameters.get("local-access-provider-id"));
317                                 crossTPs.put("remote-access-client-id", inputParameters.get("local-access-client-id"));
318                                 crossTPs.put("remote-access-topology-id", inputParameters.get("local-access-topology-id"));
319                                 crossTPs.put("remote-access-node-id", inputParameters.get("local-access-node-id"));
320                                 crossTPs.put("remote-access-ltp-id", inputParameters.get("local-access-ltp-id"));
321
322                                 inputParameters.put("local-access-provider-id", crossTPs.get("local-access-provider-id"));
323                                 inputParameters.put("local-access-client-id", crossTPs.get("local-access-client-id"));
324                                 inputParameters.put("local-access-topology-id", crossTPs.get("local-access-topology-id"));
325                                 inputParameters.put("local-access-node-id", crossTPs.get("local-access-node-id"));
326                                 inputParameters.put("local-access-ltp-id", crossTPs.get("local-access-ltp-id"));
327                                 inputParameters.put("remote-access-provider-id", crossTPs.get("remote-access-provider-id"));
328                                 inputParameters.put("remote-access-client-id", crossTPs.get("remote-access-client-id"));
329                                 inputParameters.put("remote-access-topology-id", crossTPs.get("remote-access-topology-id"));
330                                 inputParameters.put("remote-access-node-id", crossTPs.get("remote-access-node-id"));
331                                 inputParameters.put("remote-access-ltp-id", crossTPs.get("remote-access-ltp-id"));
332
333                                 execution.setVariable(Prefix + "ServiceParameters", inputParameters)
334                         }
335                         else {
336                                         msoLogger.error("No allocated CrossONAPResource found in ServiceParameters")
337                         }
338                 }
339
340                 msoLogger.info("Exit " + allocateCrossONAPResource)
341         }
342
343         public void prepare3rdONAPRequest(DelegateExecution execution) {
344                 msoLogger.info(" ***** Started prepare3rdONAPRequest *****")
345
346                 String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
347                 String extAPIPath = sppartnerUrl + '/serviceOrder'
348                 execution.setVariable("ExternalAPIURL", extAPIPath)
349
350                 // ExternalAPI message format
351                 String externalId = execution.getVariable("resourceName")
352                 String category = "E2E Service"
353                 String description = "Service Order from SPPartner"
354                 String requestedStartDate = utils.generateCurrentTimeInUtc()
355                 String requestedCompletionDate = utils.generateCurrentTimeInUtc()
356                 String priority = "1" // 0-4 0:highest
357                 String subscriberId = execution.getVariable("globalSubscriberId")
358                 String customerRole = "ONAPcustomer"
359                 String subscriberName = subscriberId
360                 String referredType = "Consumer"
361                 String orderItemId = "1"
362                 String action = "add" //for create
363                 String serviceState = "active"
364                 String serviceName = execution.getVariable("serviceInstanceName")
365                 String serviceUuId = execution.getVariable(Prefix + "SppartnerUUID")
366
367                 Map<String, String> valueMap = new HashMap<>()
368                 valueMap.put("externalId", '"' + externalId + '"')
369                 valueMap.put("category", '"' + category + '"')
370                 valueMap.put("description", '"' + description + '"')
371                 valueMap.put("requestedStartDate", '"' + requestedStartDate + '"')
372                 valueMap.put("requestedCompletionDate", '"' + requestedCompletionDate + '"')
373                 valueMap.put("priority", '"'+ priority + '"')
374                 valueMap.put("subscriberId", '"' + subscriberId + '"')
375                 valueMap.put("customerRole", '"' + customerRole + '"')
376                 valueMap.put("subscriberName", '"' + subscriberName + '"')
377                 valueMap.put("referredType", '"' + referredType + '"')
378                 valueMap.put("orderItemId", '"' + orderItemId + '"')
379                 valueMap.put("action", '"' + action + '"')
380                 valueMap.put("serviceState", '"' + serviceState + '"')
381                 valueMap.put("serviceId", "null") //null for add
382                 valueMap.put("serviceName", '"' + serviceName + '"')
383                 valueMap.put("serviceUuId", '"' + serviceUuId + '"')
384
385                 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
386
387                 // insert CallSource='ExternalAPI' to uuiRequest
388                 Map<String, String> requestInputsMap = new HashMap<>()
389                 requestInputsMap.put("inputName",  '"CallSource"')
390                 requestInputsMap.put("inputValue", '"ExternalAPI"')
391                 String _requestInputs_ = externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
392
393                 requestInputsMap.clear()
394                 String serviceInstanceId = execution.getVariable(Prefix + "ServiceInstanceId")
395                 requestInputsMap.put("inputName", '"SppartnerServiceId"')
396                 requestInputsMap.put("inputValue", '"' + serviceInstanceId + '"')
397                 _requestInputs_ +=  ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
398
399                 requestInputsMap.clear()
400                 String serviceType = execution.getVariable("serviceType")
401                 requestInputsMap.put("inputName", '"serviceType"')
402                 requestInputsMap.put("inputValue", '"' + serviceType + '"')
403                 _requestInputs_ +=  ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
404
405                 // Transfer all uuiRequest incomeParameters to ExternalAPI format
406                 JSONObject inputParameters = execution.getVariable(Prefix + "ServiceParameters")
407                 for(String key : inputParameters.keySet()) {
408                         String inputName = key
409                         String inputValue = inputParameters.opt(key)
410                         requestInputsMap.clear()
411                         requestInputsMap.put("inputName", '"' + inputName+ '"')
412                         requestInputsMap.put("inputValue", '"' + inputValue + '"')
413                         _requestInputs_ += ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
414                 }
415                 valueMap.put("_requestInputs_",  _requestInputs_)
416
417                 String payload = externalAPIUtil.setTemplate(ExternalAPIUtil.PostServiceOrderRequestsTemplate, valueMap)
418                 execution.setVariable(Prefix + "Payload", payload)
419                 msoLogger.info("Exit " + prepare3rdONAPRequest)
420         }
421
422         public void doCreateE2ESIin3rdONAP(DelegateExecution execution) {
423                 msoLogger.info(" ***** Started doCreateE2ESIin3rdONAP *****")
424         try {
425                 String extAPIPath = execution.getVariable("ExternalAPIURL")
426                 String payload = execution.getVariable(Prefix + "Payload")
427                 msoLogger.debug("doCreateE2ESIin3rdONAP externalAPIURL is: " + extAPIPath)
428                 msoLogger.debug("doCreateE2ESIin3rdONAP payload is: " + payload)
429
430                 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
431                 execution.setVariable("ServiceOrderId", "")
432
433                 Response response = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)
434
435                 int responseCode = response.getStatus()
436                 execution.setVariable(Prefix + "PostServiceOrderResponseCode", responseCode)
437                 msoLogger.debug("Post ServiceOrder response code is: " + responseCode)
438
439                 String extApiResponse = response.readEntity(String.class)
440                 JSONObject responseObj = new JSONObject(extApiResponse)
441                 execution.setVariable(Prefix + "PostServiceOrderResponse", extApiResponse)
442
443                 msoLogger.debug("doCreateE2ESIin3rdONAP response body is: " + extApiResponse)
444
445                 //Process Response
446                 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
447                 //200 OK 201 CREATED 202 ACCEPTED
448                 {
449                         msoLogger.debug("Post ServiceOrder Received a Good Response")
450                         String serviceOrderId = responseObj.get("id")
451                         execution.setVariable(Prefix + "SuccessIndicator", true)
452                         execution.setVariable("ServiceOrderId", serviceOrderId)
453                         msoLogger.info("Post ServiceOrderid is: " + serviceOrderId)
454                 }
455                 else{
456                         msoLogger.error("Post ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
457 //                      exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Post ServiceOrder Received a bad response from 3rdONAP External API")
458                 }
459         }catch(Exception e){
460             msoLogger.error("doCreateE2ESIin3rdONAP exception:" + e.getMessage())
461         }
462
463                 msoLogger.info("Exit " + doCreateE2ESIin3rdONAP)
464         }
465
466
467         public void getE2ESIProgressin3rdONAP(DelegateExecution execution) {
468                 msoLogger.info(" ***** Started getE2ESIProgressin3rdONAP *****")
469         try {
470
471                 String extAPIPath = execution.getVariable("ExternalAPIURL")
472                 extAPIPath += "/" + execution.getVariable("ServiceOrderId")
473                 msoLogger.debug("getE2ESIProgressin3rdONAP create externalAPIURL is: " + extAPIPath)
474
475                 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
476
477                 Response response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
478
479                 int responseCode = response.getStatus()
480                 execution.setVariable(Prefix + "GetServiceOrderResponseCode", responseCode)
481                 msoLogger.debug("Get ServiceOrder response code is: " + responseCode)
482
483                 String extApiResponse = response.readEntity(String.class)
484                 JSONObject responseObj = new JSONObject(extApiResponse)
485                 execution.setVariable(Prefix + "GetServiceOrderResponse", extApiResponse)
486
487                 msoLogger.debug("getE2ESIProgressin3rdONAP create response body is: " + extApiResponse)
488
489                 //Process Response //200 OK 201 CREATED 202 ACCEPTED
490                 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
491                 {
492                         msoLogger.debug("Get Create ServiceOrder Received a Good Response")
493
494                         String orderState = responseObj.get("state")
495                         if("REJECTED".equalsIgnoreCase(orderState)) {
496                                 execution.setVariable("progress", 100)
497                                 execution.setVariable("status", "error")
498                                 execution.setVariable("statusDescription", "Create Service Order Status is REJECTED")
499                                 return
500                         }
501
502                         JSONArray items = responseObj.getJSONArray("orderItem")
503                         JSONObject item = items[0]
504                         JSONObject service = item.get("service")
505                         String sppartnerServiceId = service.get("id")
506                         if(sppartnerServiceId == null || sppartnerServiceId.equals("null")) {
507                                 execution.setVariable("progress", 100)
508                                 execution.setVariable("status", "error")
509                                 execution.setVariable("statusDescription", "Create Service Order Status get null sppartnerServiceId")
510                                 msoLogger.error("null sppartnerServiceId while getting progress from externalAPI")
511                                 return
512                         }
513
514                         execution.setVariable(Prefix + "SppartnerServiceId", sppartnerServiceId)
515
516                         String serviceOrderState = item.get("state")
517                         execution.setVariable(Prefix + "SuccessIndicator", true)
518                         execution.setVariable("ServiceOrderState", serviceOrderState)
519
520                         // Get serviceOrder State and process progress
521                         if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState)) {
522                                 execution.setVariable("progress", 15)
523                                 execution.setVariable("status", "processing")
524                                 execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
525                         }
526                         else if("INPROGRESS".equalsIgnoreCase(serviceOrderState)) {
527                                 execution.setVariable("progress", 40)
528                                 execution.setVariable("status", "processing")
529                                 execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
530                         }
531                         else if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
532                                 execution.setVariable("progress", 100)
533                                 execution.setVariable("status", "finished")
534                                 execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
535                         }
536                         else if("FAILED".equalsIgnoreCase(serviceOrderState)) {
537                                 execution.setVariable("progress", 100)
538                                 execution.setVariable("status", "error")
539                                 execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
540                         }
541                         else {
542                                 execution.setVariable("progress", 100)
543                                 execution.setVariable("status", "error")
544                                 execution.setVariable("statusDescription", "Create Service Order Status is unknown")
545                         }
546                 }
547                 else{
548                         msoLogger.debug("Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
549                         execution.setVariable("progress", 100)
550                         execution.setVariable("status", "error")
551                         execution.setVariable("statusDescription", "Get Create ServiceOrder Received a bad response")
552 //                      exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Get Create ServiceOrder Received a bad response from 3rdONAP External API")
553                 }
554
555         }catch(Exception e){            
556             execution.setVariable("progress", 100)
557             execution.setVariable("status", "error")
558             execution.setVariable("statusDescription", "Get Create ServiceOrder Exception")
559             msoLogger.error("getE2ESIProgressin3rdONAP exception:" + e.getMessage())
560         }
561                 msoLogger.info("Exit " + getE2ESIProgressin3rdONAP)
562         }
563
564         /**
565          * delay 5 sec
566          */
567         public void timeDelay(DelegateExecution execution) {
568                 try {
569                         Thread.sleep(5000)
570                 } catch(InterruptedException e) {
571                         msoLogger.error("Time Delay exception" + e)
572                 }
573         }
574
575         public void saveSPPartnerInAAI(DelegateExecution execution) {
576                 msoLogger.info(" ***** Started saveSPPartnerInAAI *****")
577         try {
578                 String sppartnerId = execution.getVariable(Prefix + "SppartnerServiceId")
579                 String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
580                 String callSource = execution.getVariable(Prefix + "CallSource")
581                 String serviceInstanceId = execution.getVariable(Prefix + "ServiceInstanceId")
582                 String globalSubscriberId = execution.getVariable("globalSubscriberId")
583                 String serviceType = execution.getVariable("serviceType")
584                 String resourceModelInvariantUuid = execution.getVariable(Prefix + "ResourceModelInvariantUuid")
585                 String resourceModelUuid = execution.getVariable(Prefix + "ResourceModelUuid")
586                 String resourceModelCustomizationUuid = execution.getVariable(Prefix + "ResourceModelCustomizationUuid")
587                 
588                 SpPartner partner = new SpPartner()
589                 partner.setSpPartnerId(sppartnerId)
590                 partner.setUrl(sppartnerUrl)
591                 partner.setCallsource(callSource)
592                 partner.setModelInvariantId(resourceModelInvariantUuid)
593                 partner.setModelVersionId(resourceModelUuid)
594                 partner.setModelCustomizationId(resourceModelCustomizationUuid)
595
596                 AAIResourcesClient client = new AAIResourcesClient()
597                 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SP_PARTNER, sppartnerId)
598                 client.create(uri, partner)
599
600                 AAIResourceUri siUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
601                 client.connect(uri, siUri)
602         } catch (Exception ex) {
603             String msg = "Exception in Create3rdONAPE2EServiceInstance.saveSPPartnerInAAI. " + ex.getMessage()
604             msoLogger.info(msg)
605 //            throw new BpmnError("MSOWorkflowException")
606         }
607                 msoLogger.info("Exit " + saveSPPartnerInAAI)
608         }
609
610         private void setProgressUpdateVariables(DelegateExecution execution, String body) {
611                 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
612                 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
613                 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
614         }
615
616         public void postProcess(DelegateExecution execution){
617                 msoLogger.info(" ***** Started postProcess *****")
618                 String responseCode = execution.getVariable(Prefix + "PutSppartnerResponseCode")
619                 String responseObj = execution.getVariable(Prefix + "PutSppartnerResponse")
620
621                 msoLogger.info("response from AAI for put sppartner, response code :" + responseCode + "  response object :" + responseObj)
622                 msoLogger.info(" ***** Exit postProcess *****")
623         }
624
625         public void sendSyncResponse (DelegateExecution execution) {
626                 msoLogger.debug(" *** sendSyncResponse *** ")
627
628                 try {
629                         String operationStatus = "finished"
630                         // RESTResponse for main flow
631                         String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
632                         msoLogger.debug(" sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
633                         sendWorkflowResponse(execution, 202, resourceOperationResp)
634                         execution.setVariable("sentSyncResponse", true)
635
636                 } catch (Exception ex) {
637                         String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
638                         msoLogger.debug(msg)
639 //                      exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
640                 }
641                 msoLogger.debug(" ***** Exit sendSyncResopnse *****")
642         }
643 }