2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
 
   6  * ================================================================================
 
   7  * Modifications Copyright (c) 2019 Samsung
 
   8  * ================================================================================
 
   9  * Licensed under the Apache License, Version 2.0 (the "License")
 
  10  * you may not use this file except in compliance with the License.
 
  11  * You may obtain a copy of the License at
 
  13  *      http://www.apache.org/licenses/LICENSE-2.0
 
  15  * Unless required by applicable law or agreed to in writing, software
 
  16  * distributed under the License is distributed on an "AS IS" BASIS,
 
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  18  * See the License for the specific language governing permissions and
 
  19  * limitations under the License.
 
  20  * ============LICENSE_END=========================================================
 
  23 package org.onap.so.bpmn.infrastructure.scripts
 
  25 import com.google.gson.JsonObject
 
  26 import org.json.JSONArray
 
  27 import org.json.JSONObject
 
  29 import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
 
  31 import static org.apache.commons.lang3.StringUtils.*
 
  32 import groovy.xml.XmlUtil
 
  33 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 
  34 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 
  35 import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
 
  36 import org.onap.so.bpmn.common.scripts.MsoUtils
 
  37 import org.onap.aai.domain.yang.SpPartner
 
  38 import org.onap.so.bpmn.common.recipe.ResourceInput
 
  39 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
 
  40 import org.onap.so.bpmn.core.WorkflowException
 
  41 import org.onap.so.bpmn.core.json.JsonUtils
 
  42 import org.onap.so.bpmn.core.UrnPropertiesReader
 
  43 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder
 
  44 import org.onap.so.client.aai.AAIObjectType
 
  45 import org.onap.so.client.aai.AAIResourcesClient
 
  46 import org.onap.so.client.aai.entities.uri.AAIResourceUri
 
  47 import org.onap.so.client.aai.entities.uri.AAIUriFactory
 
  48 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
 
  49 import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory
 
  52 import javax.ws.rs.core.Response
 
  53 import org.slf4j.Logger
 
  54 import org.slf4j.LoggerFactory
 
  56 import org.camunda.bpm.engine.runtime.Execution
 
  57 import org.camunda.bpm.engine.delegate.BpmnError
 
  58 import org.camunda.bpm.engine.delegate.DelegateExecution
 
  59 import org.apache.commons.lang3.*
 
  60 import org.apache.commons.codec.binary.Base64
 
  64  * This groovy class supports the <class>Create3rdONAPE2EServiceInstance.bpmn</class> process.
 
  65  * flow for Create E2EServiceInstance in 3rdONAP
 
  67 public class Create3rdONAPE2EServiceInstance extends AbstractServiceTaskProcessor {
 
  69         String Prefix = "CRE3rdONAPESI_"
 
  71         ExceptionUtil exceptionUtil = new ExceptionUtil()
 
  73         JsonUtils jsonUtil = new JsonUtils()
 
  75     private static final Logger logger = LoggerFactory.getLogger( Create3rdONAPE2EServiceInstance.class)
 
  77         public void checkSPPartnerInfo (DelegateExecution execution) {
 
  78                 logger.info(" ***** Started checkSPPartnerInfo *****")
 
  80                         //get bpmn inputs from resource request.
 
  81                         String requestId = execution.getVariable("mso-request-id")
 
  82                         String requestAction = execution.getVariable("requestAction")
 
  83                         logger.info("The requestAction is: " + requestAction)
 
  84                         String recipeParamsFromRequest = execution.getVariable("recipeParams")
 
  85                         logger.info("The recipeParams is: " + recipeParamsFromRequest)
 
  86                         String resourceInput = execution.getVariable("resourceInput")
 
  87                         logger.info("The resourceInput is: " + resourceInput)
 
  88                         //Get ResourceInput Object
 
  89                         ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
 
  90                         String resourceInputPrameters = resourceInputObj.getResourceParameters()
 
  91                         String inputParametersJson = JsonUtils.getJsonValue(resourceInputPrameters, "requestInputs")
 
  92                         JSONObject inputParameters = new JSONObject(inputParametersJson)
 
  94                         // set local resourceInput
 
  95                         execution.setVariable(Prefix + "ResourceInput", resourceInputObj)
 
  97                         String spPartnerModelName = UrnPropertiesReader.getVariable("sp-partner.modelName")
 
  98                         boolean is3rdONAPExist = false
 
 100                         if(inputParameters.has(spPartnerModelName + "_url"))
 
 102                                 String sppartnerUrl = inputParameters.get(spPartnerModelName + "_url")
 
 103                                 if(!isBlank(sppartnerUrl)) {
 
 104                                         execution.setVariable(Prefix + "SppartnerUrl", sppartnerUrl)
 
 105                                         is3rdONAPExist = true
 
 108                                         is3rdONAPExist = false
 
 109                                         String msg = "sppartner Url is blank."
 
 113                         if(inputParameters.has(spPartnerModelName + "_providingServiceUuid"))
 
 115                                 String sppartnerUUID= inputParameters.get(spPartnerModelName + "_providingServiceUuid")
 
 116                                 execution.setVariable(Prefix + "SppartnerUUID", sppartnerUUID)
 
 117                                 is3rdONAPExist = true
 
 120                                 is3rdONAPExist = false
 
 121                                 String msg = "sppartner providingServiceUuid is blank."
 
 124                         if(inputParameters.has(spPartnerModelName + "_providingServiceInvariantUuid"))
 
 126                                 String sppartnerInvarianteUUID  = inputParameters.get(spPartnerModelName + "_providingServiceInvariantUuid")
 
 127                                 execution.setVariable(Prefix + "SppartnerInvarianteUUID", sppartnerInvarianteUUID)
 
 128                                 is3rdONAPExist = true
 
 131                                 is3rdONAPExist = false
 
 132                                 String msg = "sppartner providingServiceInvarianteUuid is blank."
 
 136                         if(inputParameters.has(spPartnerModelName + "_handoverMode"))
 
 138                                 String handoverMode = inputParameters.get(spPartnerModelName + "_handoverMode")
 
 139                                 execution.setVariable(Prefix + "HandoverMode", handoverMode)
 
 140                             is3rdONAPExist = true
 
 143                                 is3rdONAPExist = false
 
 144                                 String msg = "sppartner handoverMode is blank."
 
 148                         execution.setVariable("Is3rdONAPExist", is3rdONAPExist)
 
 149                         execution.setVariable(Prefix + "ServiceInstanceId", resourceInputObj.getServiceInstanceId())
 
 150                         execution.setVariable("mso-request-id", requestId)
 
 151                         execution.setVariable("mso-service-instance-id", resourceInputObj.getServiceInstanceId())
 
 153                 } catch (Exception ex){
 
 154                         String msg = "Exception in checkSPPartnerInfo " + ex.getMessage()
 
 156 //                      exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 160         public void checkLocallCall (DelegateExecution execution) {
 
 161                 logger.info(" ***** Started checkLocallCall *****")
 
 164                         //Get ResourceInput Object
 
 165                         ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
 
 168                         String incomingRequest = resourceInputObj.getRequestsInputs()
 
 169                         String serviceParameters = JsonUtils.getJsonValue(incomingRequest, "service.parameters")
 
 170                         String requestInputs = JsonUtils.getJsonValue(serviceParameters, "requestInputs")
 
 171                         JSONObject inputParameters = new JSONObject(requestInputs)
 
 172                         execution.setVariable(Prefix + "ServiceParameters", inputParameters.toString())
 
 174                         // CallSource is added only when ONAP SO calling 3rdONAP(External API) SO(Remote call)
 
 175                         boolean isLocalCall = true
 
 176                         String callSource = "UUI"
 
 177                         if(inputParameters.has("CallSource"))
 
 179                                 callSource = inputParameters.get("CallSource")
 
 180                                 if("ExternalAPI".equalsIgnoreCase(callSource)) {
 
 181                                         String sppartnerId = inputParameters.get("SppartnerServiceId")
 
 182                                         execution.setVariable(Prefix + "SppartnerServiceId", sppartnerId)
 
 186                         execution.setVariable(Prefix + "CallSource", callSource)
 
 187                         logger.info("callSource is: " + callSource )
 
 189                         execution.setVariable("IsLocalCall", isLocalCall)
 
 191                 } catch (Exception ex){
 
 192                         String msg = "Exception in checkLocallCall " + ex.getMessage()
 
 194 //                      exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 198         public void preProcessRequest(DelegateExecution execution){
 
 199                 logger.info(" ***** Started preProcessRequest *****")
 
 203                         ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
 
 205                         String globalSubscriberId = resourceInputObj.getGlobalSubscriberId()
 
 206                         if (isBlank(globalSubscriberId)) {
 
 207                                 msg = "Input globalSubscriberId is null"
 
 211                         execution.setVariable("globalSubscriberId", globalSubscriberId)
 
 212                         logger.info("globalSubscriberId:" + globalSubscriberId)
 
 214                         String serviceType = resourceInputObj.getServiceType()
 
 215                         if (isBlank(serviceType)) {
 
 216                                 msg = "Input serviceType is null"
 
 219                         execution.setVariable("serviceType", serviceType)
 
 220                         logger.info("serviceType:" + serviceType)
 
 222                         String resourceName = resourceInputObj.getResourceInstanceName()
 
 223                         if (isBlank(resourceName)) {
 
 224                                 msg = "Input resourceName is null"
 
 227                         execution.setVariable("resourceName", resourceName)
 
 228                         logger.info("resourceName:" + resourceName)
 
 230                         int beginIndex = resourceName.indexOf("_") + 1
 
 231                         String serviceInstanceName = resourceName.substring(beginIndex)
 
 232                         execution.setVariable("serviceInstanceName", serviceInstanceName)
 
 234                         String serviceInstanceId = resourceInputObj.getServiceInstanceId()
 
 235                         if (isBlank(serviceInstanceId)) {
 
 236                                 msg = "Input serviceInstanceId is null"
 
 239                         execution.setVariable(Prefix + "ServiceInstanceId", serviceInstanceId)
 
 240                         logger.info("serviceInstanceId:" + serviceInstanceId)
 
 242                         String resourceModelInvariantUuid = resourceInputObj.getResourceModelInfo().getModelInvariantUuid()
 
 243                         if (isBlank(resourceModelInvariantUuid)) {
 
 244                                 msg = "Input resourceModelInvariantUuid is null"
 
 247                         execution.setVariable(Prefix + "ResourceModelInvariantUuid", resourceModelInvariantUuid)
 
 248                         logger.info("resourceModelInvariantUuid:" + resourceModelInvariantUuid)
 
 250                         String resourceModelUuid = resourceInputObj.getResourceModelInfo().getModelUuid()
 
 251                         if (isBlank(resourceModelUuid)) {
 
 252                                 msg = "Input resourceModelUuid is null"
 
 255                         execution.setVariable(Prefix + "ResourceModelUuid", resourceModelUuid)
 
 256                         logger.info("resourceModelUuid:" + resourceModelUuid)
 
 258                         String resourceModelCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
 
 259                         if (isBlank(resourceModelCustomizationUuid)) {
 
 260                                 msg = "Input resourceModelCustomizationUuid is null"
 
 263                         execution.setVariable(Prefix + "ResourceModelCustomizationUuid", resourceModelCustomizationUuid)
 
 264                         logger.info("resourceModelCustomizationUuid:" + resourceModelCustomizationUuid)
 
 266                 } catch (Exception ex){
 
 267                         msg = "Exception in preProcessRequest " + ex.getMessage()
 
 269 //                      exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 273         public void prepareUpdateProgress(DelegateExecution execution) {
 
 274                 logger.info(" ***** Started prepareUpdateProgress *****")
 
 275                 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
 
 276                 String operType = resourceInputObj.getOperationType()
 
 277                 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
 
 278                 String ServiceInstanceId = resourceInputObj.getServiceInstanceId()
 
 279                 String modelName = resourceInputObj.getResourceModelInfo().getModelName()
 
 280                 String operationId = resourceInputObj.getOperationId()
 
 281                 String progress = execution.getVariable("progress")
 
 282                 String status = execution.getVariable("status")
 
 283                 String statusDescription = execution.getVariable("statusDescription")
 
 286                 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 
 287                         xmlns:ns="http://org.onap.so/requestsdb">
 
 290                     <ns:updateResourceOperationStatus>
 
 291                                <operType>${operType}</operType>
 
 292                                <operationId>${operationId}</operationId>
 
 293                                <progress>${progress}</progress>
 
 294                                <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
 
 295                                <serviceId>${ServiceInstanceId}</serviceId>
 
 296                                <status>${status}</status>
 
 297                                <statusDescription>${statusDescription}</statusDescription>
 
 298                     </ns:updateResourceOperationStatus>
 
 300                 </soapenv:Envelope>"""
 
 302                 setProgressUpdateVariables(execution, body)
 
 303                 logger.info(" ***** Exit prepareUpdateProgress *****")
 
 306         public void allocateCrossONAPResource(DelegateExecution execution) {
 
 307                 logger.info(" ***** Started allocateCrossONAPResource *****")
 
 309                 //get TP links from AAI for SOTN handoverMode only
 
 310                 String handoverMode = execution.getVariable(Prefix + "HandoverMode")
 
 311                 if("SOTN".equalsIgnoreCase(handoverMode)) {
 
 312                         // Put TP Link info into serviceParameters
 
 313                         JSONObject inputParameters = new JSONObject(execution.getVariable(Prefix + "ServiceParameters"))
 
 314                         if(inputParameters.has("remote-access-provider-id")) {
 
 315                                 Map<String, Object> crossTPs = new HashMap<String, Object>()
 
 316                                 crossTPs.put("local-access-provider-id", inputParameters.get("remote-access-provider-id"))
 
 317                                 crossTPs.put("local-access-client-id", inputParameters.get("remote-access-client-id"))
 
 318                                 crossTPs.put("local-access-topology-id", inputParameters.get("remote-access-topology-id"))
 
 319                                 crossTPs.put("local-access-node-id", inputParameters.get("remote-access-node-id"))
 
 320                                 crossTPs.put("local-access-ltp-id", inputParameters.get("remote-access-ltp-id"))
 
 321                                 crossTPs.put("remote-access-provider-id", inputParameters.get("local-access-provider-id"))
 
 322                                 crossTPs.put("remote-access-client-id", inputParameters.get("local-access-client-id"))
 
 323                                 crossTPs.put("remote-access-topology-id", inputParameters.get("local-access-topology-id"))
 
 324                                 crossTPs.put("remote-access-node-id", inputParameters.get("local-access-node-id"))
 
 325                                 crossTPs.put("remote-access-ltp-id", inputParameters.get("local-access-ltp-id"))
 
 327                                 inputParameters.put("local-access-provider-id", crossTPs.get("local-access-provider-id"))
 
 328                                 inputParameters.put("local-access-client-id", crossTPs.get("local-access-client-id"))
 
 329                                 inputParameters.put("local-access-topology-id", crossTPs.get("local-access-topology-id"))
 
 330                                 inputParameters.put("local-access-node-id", crossTPs.get("local-access-node-id"))
 
 331                                 inputParameters.put("local-access-ltp-id", crossTPs.get("local-access-ltp-id"))
 
 332                                 inputParameters.put("remote-access-provider-id", crossTPs.get("remote-access-provider-id"))
 
 333                                 inputParameters.put("remote-access-client-id", crossTPs.get("remote-access-client-id"))
 
 334                                 inputParameters.put("remote-access-topology-id", crossTPs.get("remote-access-topology-id"))
 
 335                                 inputParameters.put("remote-access-node-id", crossTPs.get("remote-access-node-id"))
 
 336                                 inputParameters.put("remote-access-ltp-id", crossTPs.get("remote-access-ltp-id"))
 
 338                                 execution.setVariable(Prefix + "ServiceParameters", inputParameters.toString())
 
 341                                         logger.error("No allocated CrossONAPResource found in ServiceParameters")
 
 345                 logger.info("Exit  allocateCrossONAPResource")
 
 348         public void prepare3rdONAPRequest(DelegateExecution execution) {
 
 349                 logger.info(" ***** Started prepare3rdONAPRequest *****")
 
 351                 String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
 
 352                 String extAPIPath = UrnPropertiesReader.getVariable("extapi.endpoint", execution) + '/serviceOrder'
 
 353                 execution.setVariable("ExternalAPIURL", extAPIPath)
 
 354                 execution.setVariable("SPPartnerUrl",sppartnerUrl)
 
 356                 // ExternalAPI message format
 
 357                 String externalId = execution.getVariable("resourceName")
 
 358                 String serviceType = execution.getVariable("serviceType")
 
 359                 String category = "E2E Service"
 
 360                 String description = "Service Order from SPPartner"
 
 361                 String requestedStartDate = utils.generateCurrentTimeInUtc()
 
 362                 String requestedCompletionDate = utils.generateCurrentTimeInUtc()
 
 363                 String priority = "1" // 0-4 0:highest
 
 364                 String subscriberId = execution.getVariable("globalSubscriberId")
 
 365                 String customerRole = "ONAPcustomer"
 
 366                 // Below SO will pass serviceType as subscriberName and externalAPI will use
 
 367                 // the same serviceType in another domain instead of model name
 
 368                 String subscriberName = serviceType
 
 369                 String referredType = "Consumer"
 
 370                 String orderItemId = "1"
 
 371                 String action = "add" //for create
 
 372                 String serviceState = "active"
 
 373                 String serviceName = execution.getVariable("serviceInstanceName")
 
 374                 String serviceUuId = execution.getVariable(Prefix + "SppartnerUUID")
 
 376                 Map<String, String> valueMap = new HashMap<>()
 
 377                 valueMap.put("externalId", '"' + externalId + '"')
 
 378                 valueMap.put("category", '"' + category + '"')
 
 379                 valueMap.put("description", '"' + description + '"')
 
 380                 valueMap.put("requestedStartDate", '"' + requestedStartDate + '"')
 
 381                 valueMap.put("requestedCompletionDate", '"' + requestedCompletionDate + '"')
 
 382                 valueMap.put("priority", '"'+ priority + '"')
 
 383                 valueMap.put("subscriberId", '"' + subscriberId + '"')
 
 384                 valueMap.put("customerRole", '"' + customerRole + '"')
 
 385                 valueMap.put("subscriberName", '"' + subscriberName + '"')
 
 386                 valueMap.put("referredType", '"' + referredType + '"')
 
 387                 valueMap.put("orderItemId", '"' + orderItemId + '"')
 
 388                 valueMap.put("action", '"' + action + '"')
 
 389                 valueMap.put("serviceState", '"' + serviceState + '"')
 
 390                 valueMap.put("serviceId", "null") //null for add
 
 391                 valueMap.put("serviceName", '"' + serviceName + '"')
 
 392                 valueMap.put("serviceUuId", '"' + serviceUuId + '"')
 
 394                 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
 
 396                 // insert CallSource='ExternalAPI' to uuiRequest
 
 397                 Map<String, String> requestInputsMap = new HashMap<>()
 
 398                 requestInputsMap.put("inputName",  '"CallSource"')
 
 399                 requestInputsMap.put("inputValue", '"ExternalAPI"')
 
 400                 String _requestInputs_ = externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
 
 402                 requestInputsMap.clear()
 
 403                 String serviceInstanceId = execution.getVariable(Prefix + "ServiceInstanceId")
 
 404                 requestInputsMap.put("inputName", '"SppartnerServiceId"')
 
 405                 requestInputsMap.put("inputValue", '"' + serviceInstanceId + '"')
 
 406                 _requestInputs_ +=  ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
 
 408                 requestInputsMap.clear()
 
 409                 requestInputsMap.put("inputName", '"serviceType"')
 
 410                 requestInputsMap.put("inputValue", '"' + serviceType + '"')
 
 411                 _requestInputs_ +=  ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
 
 413                 // Transfer all uuiRequest incomeParameters to ExternalAPI format
 
 414                 JSONObject inputParameters = new JSONObject(execution.getVariable(Prefix + "ServiceParameters"))
 
 415                 for(String key : inputParameters.keySet()) {
 
 416                         String inputName = key
 
 417                         String inputValue = inputParameters.opt(key)
 
 418                         requestInputsMap.clear()
 
 419                         requestInputsMap.put("inputName", '"' + inputName+ '"')
 
 420                         requestInputsMap.put("inputValue", '"' + inputValue + '"')
 
 421                         _requestInputs_ += ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
 
 423                 valueMap.put("_requestInputs_",  _requestInputs_)
 
 425                 String payload = externalAPIUtil.setTemplate(ExternalAPIUtil.PostServiceOrderRequestsTemplate, valueMap)
 
 426                 execution.setVariable(Prefix + "Payload", payload)
 
 427                 logger.info(" ***** Exit prepare3rdONAPRequest *****")
 
 430         public void doCreateE2ESIin3rdONAP(DelegateExecution execution) {
 
 431                 logger.info(" ***** Started doCreateE2ESIin3rdONAP *****")
 
 433                 String extAPIPath = execution.getVariable("ExternalAPIURL")
 
 434                 String payload = execution.getVariable(Prefix + "Payload")
 
 435                 logger.debug("doCreateE2ESIin3rdONAP externalAPIURL is: " + extAPIPath)
 
 436                 logger.debug("doCreateE2ESIin3rdONAP payload is: " + payload)
 
 438                 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
 
 439                 execution.setVariable("ServiceOrderId", "")
 
 441                 Response response = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)
 
 443                 int responseCode = response.getStatus()
 
 444                 execution.setVariable(Prefix + "PostServiceOrderResponseCode", responseCode)
 
 445                 logger.debug("Post ServiceOrder response code is: " + responseCode)
 
 447                 String extApiResponse = response.readEntity(String.class)
 
 448                 JSONObject responseObj = new JSONObject(extApiResponse)
 
 449                 execution.setVariable(Prefix + "PostServiceOrderResponse", extApiResponse)
 
 451                 logger.debug("doCreateE2ESIin3rdONAP response body is: " + extApiResponse)
 
 454                 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
 
 455                 //200 OK 201 CREATED 202 ACCEPTED
 
 457                         logger.debug("Post ServiceOrder Received a Good Response")
 
 458                         String serviceOrderId = responseObj.get("id")
 
 459                         execution.setVariable(Prefix + "SuccessIndicator", true)
 
 460                         execution.setVariable("ServiceOrderId", serviceOrderId)
 
 461                         logger.info("Post ServiceOrderid is: " + serviceOrderId)
 
 464                         logger.error("Post ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
 
 465 //                      exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Post ServiceOrder Received a bad response from 3rdONAP External API")
 
 468             logger.error("doCreateE2ESIin3rdONAP exception:" + e.getMessage())
 
 471                 logger.info(" ***** Exit doCreateE2ESIin3rdONAP *****")
 
 475         public void getE2ESIProgressin3rdONAP(DelegateExecution execution) {
 
 476                 logger.info(" ***** Started getE2ESIProgressin3rdONAP *****")
 
 479                 String extAPIPath = execution.getVariable("ExternalAPIURL")
 
 480                 extAPIPath += "/" + execution.getVariable("ServiceOrderId")
 
 481                 logger.debug("getE2ESIProgressin3rdONAP create externalAPIURL is: " + extAPIPath)
 
 483                 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
 
 485                 Response response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
 
 487                 int responseCode = response.getStatus()
 
 488                 execution.setVariable(Prefix + "GetServiceOrderResponseCode", responseCode)
 
 489                 logger.debug("Get ServiceOrder response code is: " + responseCode)
 
 491                 String extApiResponse = response.readEntity(String.class)
 
 492                 JSONObject responseObj = new JSONObject(extApiResponse)
 
 493                 execution.setVariable(Prefix + "GetServiceOrderResponse", extApiResponse)
 
 495                 logger.debug("getE2ESIProgressin3rdONAP create response body is: " + extApiResponse)
 
 497                 //Process Response //200 OK 201 CREATED 202 ACCEPTED
 
 498                 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
 
 500                         logger.debug("Get Create ServiceOrder Received a Good Response")
 
 502                         String orderState = responseObj.get("state")
 
 503                         if("REJECTED".equalsIgnoreCase(orderState)) {
 
 504                                 execution.setVariable("progress", 100)
 
 505                                 execution.setVariable("status", "error")
 
 506                                 execution.setVariable("statusDescription", "Create Service Order Status is REJECTED")
 
 510                         JSONArray items = responseObj.getJSONArray("orderItem")
 
 511                         JSONObject item = items.get(0)
 
 512                         JSONObject service = item.get("service")
 
 513                         String sppartnerServiceId = service.get("id")
 
 514                         if(sppartnerServiceId == null || sppartnerServiceId.equals("null")) {
 
 515                                 execution.setVariable("progress", 100)
 
 516                                 execution.setVariable("status", "error")
 
 517                                 execution.setVariable("statusDescription", "Create Service Order Status get null sppartnerServiceId")
 
 518                                 logger.error("null sppartnerServiceId while getting progress from externalAPI")
 
 522                         execution.setVariable(Prefix + "SppartnerServiceId", sppartnerServiceId)
 
 524                         String serviceOrderState = item.get("state")
 
 525                         execution.setVariable(Prefix + "SuccessIndicator", true)
 
 526                         execution.setVariable("ServiceOrderState", serviceOrderState)
 
 528                         // Get serviceOrder State and process progress
 
 529                         if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState)) {
 
 530                                 execution.setVariable("progress", 15)
 
 531                                 execution.setVariable("status", "processing")
 
 532                                 execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
 
 534                         else if("INPROGRESS".equalsIgnoreCase(serviceOrderState)) {
 
 535                                 execution.setVariable("progress", 40)
 
 536                                 execution.setVariable("status", "processing")
 
 537                                 execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
 
 539                         else if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
 
 540                                 execution.setVariable("progress", 100)
 
 541                                 execution.setVariable("status", "finished")
 
 542                                 execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
 
 544                         else if("FAILED".equalsIgnoreCase(serviceOrderState)) {
 
 545                                 execution.setVariable("progress", 100)
 
 546                                 execution.setVariable("status", "error")
 
 547                                 execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
 
 550                                 execution.setVariable("progress", 100)
 
 551                                 execution.setVariable("status", "error")
 
 552                                 execution.setVariable("statusDescription", "Create Service Order Status is unknown")
 
 556                         logger.debug("Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
 
 557                         execution.setVariable("progress", 100)
 
 558                         execution.setVariable("status", "error")
 
 559                         execution.setVariable("statusDescription", "Get Create ServiceOrder Received a bad response")
 
 560 //                      exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Get Create ServiceOrder Received a bad response from 3rdONAP External API")
 
 564             execution.setVariable("progress", 100)
 
 565             execution.setVariable("status", "error")
 
 566             execution.setVariable("statusDescription", "Get Create ServiceOrder Exception")
 
 567             logger.error("getE2ESIProgressin3rdONAP exception:" + e.getMessage())
 
 569                 logger.info(" ***** Exit getE2ESIProgressin3rdONAP *****")
 
 575         public void timeDelay(DelegateExecution execution) {
 
 577                         logger.debug("going to sleep for 5 sec")
 
 579                         logger.debug("wakeup after 5 sec")
 
 580                 } catch(InterruptedException e) {
 
 581                         logger.error("Time Delay exception" + e)
 
 585         public void saveSPPartnerInAAI(DelegateExecution execution) {
 
 586                 logger.info(" ***** Started saveSPPartnerInAAI *****")
 
 588                 String sppartnerId = execution.getVariable(Prefix + "SppartnerServiceId")
 
 589                 String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
 
 590                 String callSource = execution.getVariable(Prefix + "CallSource")
 
 591                 String serviceInstanceId = execution.getVariable(Prefix + "ServiceInstanceId")
 
 592                 String globalSubscriberId = execution.getVariable("globalSubscriberId")
 
 593                 String serviceType = execution.getVariable("serviceType")
 
 594                 String resourceModelInvariantUuid = execution.getVariable(Prefix + "ResourceModelInvariantUuid")
 
 595                 String resourceModelUuid = execution.getVariable(Prefix + "ResourceModelUuid")
 
 596                 String resourceModelCustomizationUuid = execution.getVariable(Prefix + "ResourceModelCustomizationUuid")
 
 598                 SpPartner partner = new SpPartner()
 
 599                 partner.setSpPartnerId(sppartnerId)
 
 600                 partner.setUrl(sppartnerUrl)
 
 601                 partner.setCallsource(callSource)
 
 602                 partner.setModelInvariantId(resourceModelInvariantUuid)
 
 603                 partner.setModelVersionId(resourceModelUuid)
 
 604                 partner.setModelCustomizationId(resourceModelCustomizationUuid)
 
 606                 AAIResourcesClient client = new AAIResourcesClient()
 
 607                 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SP_PARTNER, sppartnerId)
 
 608                 logger.info("sending request to create sp-partner: " +  uri.toString())
 
 609                 logger.info("requestbody: " + partner)
 
 610                 client.create(uri, partner)
 
 612                 AAIResourceUri siUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
 
 613                 client.connect(uri, siUri)
 
 614         } catch (Exception ex) {
 
 615             String msg = "Exception in Create3rdONAPE2EServiceInstance.saveSPPartnerInAAI. " + ex.getMessage()
 
 617 //            throw new BpmnError("MSOWorkflowException")
 
 619                 logger.info(" ***** Exit saveSPPartnerInAAI *****")
 
 622         private void setProgressUpdateVariables(DelegateExecution execution, String body) {
 
 623                 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
 
 624                 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
 
 625                 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
 
 628         public void postProcess(DelegateExecution execution){
 
 629                 logger.info(" ***** Started postProcess *****")
 
 630                 String responseCode = execution.getVariable(Prefix + "PutSppartnerResponseCode")
 
 631                 String responseObj = execution.getVariable(Prefix + "PutSppartnerResponse")
 
 633                 logger.info("response from AAI for put sppartner, response code :" + responseCode + "  response object :" + responseObj)
 
 634                 logger.info(" ***** Exit postProcess *****")
 
 637         public void sendSyncResponse (DelegateExecution execution) {
 
 638                 logger.debug(" *** sendSyncResponse *** ")
 
 641                         String operationStatus = "finished"
 
 642                         // RESTResponse for main flow
 
 643                         String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
 
 644                         logger.debug(" sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
 
 645                         sendWorkflowResponse(execution, 202, resourceOperationResp)
 
 646                         execution.setVariable("sentSyncResponse", true)
 
 648                 } catch (Exception ex) {
 
 649                         String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
 
 651 //                      exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 653                 logger.debug(" ***** Exit sendSyncResopnse *****")