2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import org.json.JSONObject
26 import static org.apache.commons.lang3.StringUtils.*
27 import groovy.xml.XmlUtil
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
43 import org.onap.so.logger.MsoLogger
45 import org.camunda.bpm.engine.runtime.Execution
46 import org.camunda.bpm.engine.delegate.BpmnError
47 import org.camunda.bpm.engine.delegate.DelegateExecution
48 import org.apache.commons.lang3.*
49 import org.apache.commons.codec.binary.Base64
50 import org.springframework.web.util.UriUtils
51 import org.onap.so.rest.RESTClient
52 import org.onap.so.rest.RESTConfig
55 * This groovy class supports the <class>Create3rdONAPE2EServiceInstance.bpmn</class> process.
56 * flow for Create E2EServiceInstance in 3rdONAP
58 public class Create3rdONAPE2EServiceInstance extends AbstractServiceTaskProcessor {
60 String Prefix = "CRE3rdONAPESI_"
62 ExceptionUtil exceptionUtil = new ExceptionUtil()
64 JsonUtils jsonUtil = new JsonUtils()
66 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, Create3rdONAPE2EServiceInstance.class)
68 public void checkSPPartnerInfo (DelegateExecution execution) {
69 msoLogger.info(" ***** Started checkSPPartnerInfo *****")
71 //get bpmn inputs from resource request.
72 String requestId = execution.getVariable("mso-request-id")
73 String requestAction = execution.getVariable("requestAction")
74 msoLogger.info("The requestAction is: " + requestAction)
75 String recipeParamsFromRequest = execution.getVariable("recipeParams")
76 msoLogger.info("The recipeParams is: " + recipeParamsFromRequest)
77 String resourceInput = execution.getVariable("resourceInput")
78 msoLogger.info("The resourceInput is: " + resourceInput)
79 //Get ResourceInput Object
80 ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
81 String resourceInputPrameters = resourceInputObj.getResourceParameters()
82 String inputParametersJson = jsonUtil.getJsonValue(resourceInputPrameters, "requestInputs")
83 JSONObject inputParameters = new JSONObject(customizeResourceParam(inputParametersJson))
85 // set local resourceInput
86 execution.setVariable(Prefix + "ResourceInput", resourceInputObj)
88 boolean is3rdONAPExist = false
90 if(inputParameters.has("url"))
92 String sppartnerUrl = inputParameters.get("url")
93 if(!isBlank(sppartnerUrl)) {
94 execution.setVariable(Prefix + "SppartnerUrl", sppartnerUrl)
98 is3rdONAPExist = false
99 String msg = "sppartner Url is blank."
103 if(inputParameters.has("providingServiceInvarianteUuid"))
105 String sppartnerInvarianteUUID = inputParameters.get("providingServiceInvarianteUuid")
106 execution.setVariable(Prefix + "SppartnerInvarianteUUID", sppartnerInvarianteUUID)
107 is3rdONAPExist = true
110 is3rdONAPExist = false
111 String msg = "sppartner providingServiceInvarianteUuid is blank."
114 if(inputParameters.has("providingServiceUuid"))
116 String sppartnerUUID = inputParameters.get("providingServiceUuid")
117 execution.setVariable(Prefix + "SppartnerUUID", sppartnerUUID)
118 is3rdONAPExist = true
121 is3rdONAPExist = false
122 String msg = "sppartner providingServiceUuid is blank."
126 if(inputParameters.has("handoverMode"))
128 String handoverMode = inputParameters.get("handoverMode")
129 execution.setVariable(Prefix + "HandoverMode", handoverMode)
130 is3rdONAPExist = true
133 is3rdONAPExist = false
134 String msg = "sppartner handoverMode is blank."
138 execution.setVariable("Is3rdONAPExist", is3rdONAPExist)
139 execution.setVariable(Prefix + "ServiceInstanceId", resourceInputObj.getServiceInstanceId())
140 execution.setVariable("mso-request-id", requestId)
141 execution.setVariable("mso-service-instance-id", resourceInputObj.getServiceInstanceId())
143 } catch (BpmnError e) {
145 } catch (Exception ex){
146 String msg = "Exception in checkSPPartnerInfo " + ex.getMessage()
148 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
152 public void checkLocallCall (DelegateExecution execution) {
153 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
154 msoLogger.info(" ***** Started checkLocallCall *****")
157 //Get ResourceInput Object
158 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
161 String incomingRequest = resourceInputObj.getRequestsInputs()
162 String serviceParameters = jsonUtil.getJsonValue(incomingRequest, "service.parameters")
163 String requestInputs = JsonUtils.getJsonValue(serviceParameters, "requestInputs")
164 JSONObject inputParameters = new JSONObject(customizeResourceParam(requestInputs))
165 execution.setVariable(Prefix + "ServiceParameters", inputParameters)
167 // CallSource is added only when ONAP SO calling 3rdONAP(External API) SO(Remote call)
168 boolean isLocalCall = true
169 String callSource = "UUI"
170 if(inputParameters.has("CallSource"))
172 callSource = inputParameters.get("CallSource")
173 if("ExternalAPI".equalsIgnoreCase(callSource)) {
174 String sppartnerId = inputParameters.get("SppartnerServiceId")
175 execution.setVariable(Prefix + "SppartnerServiceId", sppartnerId)
179 execution.setVariable(Prefix + "CallSource", callSource)
180 msoLogger.debug("callSource is: " + callSource )
182 execution.setVariable("IsLocalCall", isLocalCall)
184 } catch (Exception ex){
185 String msg = "Exception in checkLocallCall " + ex.getMessage()
187 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
191 public void preProcessRequest(DelegateExecution execution){
192 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
193 msoLogger.info(" ***** Started preProcessRequest *****")
195 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
198 String globalSubscriberId = resourceInputObj.getGlobalSubscriberId()
199 if (isBlank(globalSubscriberId)) {
200 msg = "Input globalSubscriberId is null"
202 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
205 execution.setVariable("globalSubscriberId", globalSubscriberId)
206 msoLogger.info("globalSubscriberId:" + globalSubscriberId)
208 String serviceType = resourceInputObj.getServiceType()
209 if (isBlank(serviceType)) {
210 msg = "Input serviceType is null"
212 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
214 execution.setVariable("serviceType", serviceType)
215 msoLogger.info("serviceType:" + serviceType)
217 String resourceName = resourceInputObj.getResourceInstanceName()
218 if (isBlank(resourceName)) {
219 msg = "Input resourceName is null"
221 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
223 execution.setVariable("resourceName", resourceName)
224 msoLogger.info("resourceName:" + resourceName)
226 int beginIndex = resourceName.indexOf("_") + 1
227 String serviceInstanceName = resourceName.substring(beginIndex)
228 execution.setVariable("serviceInstanceName", serviceInstanceName)
230 String serviceInstanceId = resourceInputObj.getServiceInstanceId()
231 if (isBlank(serviceInstanceId)) {
232 msg = "Input serviceInstanceId is null"
234 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
236 execution.setVariable(Prefix + "ServiceInstanceId", serviceInstanceId)
237 msoLogger.info("serviceInstanceId:" + serviceInstanceId)
239 } catch (BpmnError e) {
241 } catch (Exception ex){
242 String msg = "Exception in preProcessRequest " + ex.getMessage()
244 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
248 public void prepareUpdateProgress(DelegateExecution execution) {
249 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
250 msoLogger.info(" ***** Started prepareUpdateProgress *****")
251 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
252 String operType = resourceInputObj.getOperationType()
253 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
254 String ServiceInstanceId = resourceInputObj.getServiceInstanceId()
255 String modelName = resourceInputObj.getResourceModelInfo().getModelName()
256 String operationId = resourceInputObj.getOperationId()
257 String progress = execution.getVariable("progress")
258 String status = execution.getVariable("status")
259 String statusDescription = execution.getVariable("statusDescription")
262 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
263 xmlns:ns="http://org.openecomp.mso/requestsdb">
266 <ns:updateResourceOperationStatus>
267 <operType>${operType}</operType>
268 <operationId>${operationId}</operationId>
269 <progress>${progress}</progress>
270 <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
271 <serviceId>${ServiceInstanceId}</serviceId>
272 <status>${status}</status>
273 <statusDescription>${statusDescription}</statusDescription>
274 </ns:updateResourceOperationStatus>
276 </soapenv:Envelope>"""
278 setProgressUpdateVariables(execution, body)
279 msoLogger.info(" ***** Exit prepareUpdateProgress *****")
282 public void allocateCrossONAPResource(DelegateExecution execution) {
283 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
284 msoLogger.info(" ***** Started allocateCrossONAPResource *****")
286 //get TP links from AAI for SOTN handoverMode only
287 String handoverMode = execution.getVariable(Prefix + "HandoverMode")
288 if("SOTN".equalsIgnoreCase(handoverMode)) {
289 // Put TP Link info into serviceParameters
290 JSONObject inputParameters = execution.getVariable(Prefix + "ServiceParameters")
292 Map<String, Object> crossTPs = new HashMap<String, Object>();
293 crossTPs.put("local-access-provider-id", inputParameters.get("remote-access-provider-id"));
294 crossTPs.put("local-access-client-id", inputParameters.get("remote-access-client-id"));
295 crossTPs.put("local-access-topology-id", inputParameters.get("remote-access-topology-id"));
296 crossTPs.put("local-access-node-id", inputParameters.get("remote-access-node-id"));
297 crossTPs.put("local-access-ltp-id", inputParameters.get("remote-access-ltp-id"));
298 crossTPs.put("remote-access-provider-id", inputParameters.get("local-access-provider-id"));
299 crossTPs.put("remote-access-client-id", inputParameters.get("local-client-id"));
300 crossTPs.put("remote-access-topology-id", inputParameters.get("local-topology-id"));
301 crossTPs.put("remote-access-node-id", inputParameters.get("local-node-id"));
302 crossTPs.put("remote-access-ltp-id", inputParameters.get("local-ltp-id"));
304 inputParameters.put("local-access-provider-id", crossTPs.get("local-access-provider-id"));
305 inputParameters.put("local-access-client-id", crossTPs.get("local-access-client-id"));
306 inputParameters.put("local-access-topology-id", crossTPs.get("local-access-topology-id"));
307 inputParameters.put("local-access-node-id", crossTPs.get("local-access-node-id"));
308 inputParameters.put("local-access-ltp-id", crossTPs.get("local-access-ltp-id"));
309 inputParameters.put("remote-access-provider-id", crossTPs.get("remote-access-provider-id"));
310 inputParameters.put("remote-access-client-id", crossTPs.get("remote-client-id"));
311 inputParameters.put("remote-access-topology-id", crossTPs.get("remote-topology-id"));
312 inputParameters.put("remote-access-node-id", crossTPs.get("remote-node-id"));
313 inputParameters.put("remote-access-ltp-id", crossTPs.get("remote-ltp-id"));
315 execution.setVariable(Prefix + "ServiceParameters", inputParameters)
318 msoLogger.info("Exit " + allocateCrossONAPResource)
321 public void prepare3rdONAPRequest(DelegateExecution execution) {
322 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
323 msoLogger.info(" ***** Started prepare3rdONAPRequest *****")
325 String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
326 String extAPIPath = sppartnerUrl + 'serviceOrder'
327 execution.setVariable("ExternalAPIURL", extAPIPath)
329 // ExternalAPI message format
330 String externalId = execution.getVariable("resourceName")
331 String category = "E2E Service"
332 String description = "Service Order from SPPartner"
333 String requestedStartDate = utils.generateCurrentTimeInUtc()
334 String requestedCompletionDate = utils.generateCurrentTimeInUtc()
335 String priority = "1" // 0-4 0:highest
336 String subscriberId = execution.getVariable("globalSubscriberId")
337 String customerRole = ""
338 String subscriberName = ""
339 String referredType = "Consumer"
340 String orderItemId = "1"
341 String action = "add" //for create
342 String serviceState = "active"
343 String serviceName = execution.getVariable("serviceInstanceName")
344 String serviceUuId = execution.setVariable(Prefix + "SppartnerUUID")
346 Map<String, String> valueMap = new HashMap<>()
347 valueMap.put("externalId", '"' + externalId + '"')
348 valueMap.put("category", '"' + category + '"')
349 valueMap.put("description", '"' + description + '"')
350 valueMap.put("requestedStartDate", '"' + requestedStartDate + '"')
351 valueMap.put("requestedCompletionDate", '"' + requestedCompletionDate + '"')
352 valueMap.put("priority", '"'+ priority + '"')
353 valueMap.put("subscriberId", '"' + subscriberId + '"')
354 valueMap.put("customerRole", '"' + customerRole + '"')
355 valueMap.put("subscriberName", '"' + subscriberName + '"')
356 valueMap.put("referredType", '"' + referredType + '"')
357 valueMap.put("orderItemId", '"' + orderItemId + '"')
358 valueMap.put("action", '"' + action + '"')
359 valueMap.put("serviceState", '"' + serviceState + '"')
360 valueMap.put("serviceId", '""')//To be confirmed
361 valueMap.put("serviceName", '"' + serviceName + '"')
362 valueMap.put("serviceUuId", '"' + serviceUuId + '"')
364 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(this)
366 // insert CallSource='ExternalAPI' to uuiRequest
367 Map<String, String> requestInputsMap = new HashMap<>()
368 requestInputsMap.put("inputName", "CallSource")
369 requestInputsMap.put("inputValue", "ExternalAPI")
370 String _requestInputs_ = externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
372 requestInputsMap.clear()
373 String serviceInstanceId = execution.getVariable(Prefix + "ServiceInstanceId")
374 requestInputsMap.put("inputName", "SppartnerServiceId")
375 requestInputsMap.put("inputValue", serviceInstanceId)
376 _requestInputs_ += ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
378 requestInputsMap.clear()
379 String serviceType = execution.getVariable("serviceType")
380 requestInputsMap.put("inputName", "serviceType")
381 requestInputsMap.put("inputValue", serviceType)
382 _requestInputs_ += ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
384 // Transfer all uuiRequest incomeParameters to ExternalAPI format
385 JSONObject inputParameters = execution.getVariable(Prefix + "ServiceParameters")
386 for(String key : inputParameters.keySet()) {
387 String inputName = key
388 String inputValue = inputParameters.opt(key)
389 requestInputsMap.clear()
390 requestInputsMap.put("inputName", '"' + inputName+ '"')
391 requestInputsMap.put("inputValue", '"' + inputValue + '"')
392 _requestInputs_ += ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
394 valueMap.put("_requestInputs_", _requestInputs_)
396 String payload = externalAPIUtil.setTemplate(ExternalAPIUtil.PostServiceOrderRequestsTemplate, valueMap)
397 execution.setVariable(Prefix + "Payload", payload)
398 msoLogger.info("Exit " + prepare3rdONAPRequest)
401 public void doCreateE2ESIin3rdONAP(DelegateExecution execution) {
402 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
403 msoLogger.info(" ***** Started doCreateE2ESIin3rdONAP *****")
405 String extAPIPath = execution.getVariable("ExternalAPIURL")
406 String payload = execution.getVariable(Prefix + "Payload")
408 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(this)
410 APIResponse response = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)
412 int responseCode = response.getStatusCode()
413 execution.setVariable(Prefix + "PostServiceOrderResponseCode", responseCode)
414 msoLogger.debug("Post ServiceOrder response code is: " + responseCode)
416 String extApiResponse = response.getResponseBodyAsString()
417 JSONObject responseObj = new JSONObject(extApiResponse)
418 execution.setVariable(Prefix + "PostServiceOrderResponse", extApiResponse)
420 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
421 //200 OK 201 CREATED 202 ACCEPTED
423 msoLogger.debug("Post ServiceOrder Received a Good Response")
424 String serviceOrderId = responseObj.get("ServiceOrderId")
425 execution.setVariable(Prefix + "SuccessIndicator", true)
426 execution.setVariable("serviceOrderId", serviceOrderId)
429 msoLogger.debug("Post ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
430 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Post ServiceOrder Received a bad response from 3rdONAP External API")
433 msoLogger.info("Exit " + doCreateE2ESIin3rdONAP)
437 public void getE2ESIProgressin3rdONAP(DelegateExecution execution) {
438 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
439 msoLogger.info(" ***** Started getE2ESIProgressin3rdONAP *****")
441 String extAPIPath = execution.getVariable("ExternalAPIURL")
442 extAPIPath += "/" + execution.getVariable("ServiceOrderId")
444 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(this)
446 APIResponse response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
448 int responseCode = response.getStatusCode()
449 execution.setVariable(Prefix + "GetServiceOrderResponseCode", responseCode)
450 msoLogger.debug("Get ServiceOrder response code is: " + responseCode)
452 String extApiResponse = response.getResponseBodyAsString()
453 JSONObject responseObj = new JSONObject(extApiResponse)
454 execution.setVariable(Prefix + "GetServiceOrderResponse", extApiResponse)
456 //Process Response //200 OK 201 CREATED 202 ACCEPTED
457 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
459 msoLogger.debug("Get ServiceOrder Received a Good Response")
461 String sppartnerServiceId = responseObj.get("orderIterm.service.id")
462 execution.setVariable(Prefix + "SppartnerServiceId", sppartnerServiceId)
464 String serviceOrderState = responseObj.get("orderIterm.state")
465 execution.setVariable(Prefix + "SuccessIndicator", true)
466 execution.setVariable("serviceOrderState", serviceOrderState)
468 // Get serviceOrder State and process progress
469 if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState)) {
470 execution.setVariable("progress", 15)
471 execution.setVariable("status", "processing")
473 if("INPROGRESS".equalsIgnoreCase(serviceOrderState)) {
474 execution.setVariable("progress", 40)
475 execution.setVariable("status", "processing")
477 if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
478 execution.setVariable("progress", 100)
479 execution.setVariable("status", "finished")
481 if("FAILED".equalsIgnoreCase(serviceOrderState)) {
482 execution.setVariable("progress", 100)
483 execution.setVariable("status", "error")
486 execution.setVariable("progress", 100)
487 execution.setVariable("status", "error")
488 execution.setVariable("statusDescription", "Create Service Order Status is unknown")
490 execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
493 msoLogger.debug("Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
494 execution.setVariable("progress", 100)
495 execution.setVariable("status", "error")
496 execution.setVariable("statusDescription", "Get ServiceOrder Received a bad response")
497 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Get ServiceOrder Received a bad response from 3rdONAP External API")
500 msoLogger.info("Exit " + getE2ESIProgressin3rdONAP)
506 public void timeDelay(DelegateExecution execution) {
507 def isDebugEnabled= execution.getVariable("isDebugLogEnabled")
510 } catch(InterruptedException e) {
511 utils.log("ERROR", "Time Delay exception" + e )
515 public void saveSPPartnerInAAI(DelegateExecution execution) {
516 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
517 msoLogger.info(" ***** Started postCreateE2ESIin3rdONAP *****")
519 String sppartnerId = execution.getVariable(Prefix + "SppartnerServiceId")
520 String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
521 String callSource = execution.getVariable(Prefix + "CallSource")
522 String serviceInstanceId = execution.getVariable(Prefix + "ServiceInstanceId")
523 String globalSubscriberId = execution.getVariable("globalSubscriberId")
524 String serviceType = execution.getVariable("serviceType")
526 AaiUtil aaiUriUtil = new AaiUtil(this)
527 String aai_uri = aaiUriUtil.getBusinessSPPartnerUri(execution)
528 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
531 """<sp-partner xmlns=\"${namespace}\">
532 <id>${sppartnerId}</id>
533 <url>${sppartnerUrl}</url>
534 <callsource>${callSource}</callsource>
537 <related-to>service-instance</related-to>
538 <related-link>/aai/v14/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${serviceType}/service-instances/service-instance/${serviceInstanceId}</related-link>
540 <relationship-key>service-instance.service-instance-id</relationship-key>
541 <relationship-value>${serviceInstanceId}</relationship-value>
545 </sp-partner>""".trim()
546 utils.logAudit(payload)
548 String aai_endpoint = execution.getVariable("URN_aai_endpoint")
549 String serviceAaiPath = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(sppartnerId,"UTF-8")
551 APIResponse response = aaiUriUtil.executeAAIPutCall(execution, serviceAaiPath, payload)
552 int responseCode = response.getStatusCode()
553 execution.setVariable(Prefix + "PutSppartnerResponseCode", responseCode)
554 msoLogger.debug(" Put sppartner response code is: " + responseCode)
556 String aaiResponse = response.getResponseBodyAsString()
557 aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)
558 execution.setVariable(Prefix + "PutSppartnerResponse", aaiResponse)
561 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
562 //200 OK 201 CREATED 202 ACCEPTED
564 msoLogger.debug("PUT sppartner Received a Good Response")
565 execution.setVariable(Prefix + "SuccessIndicator", true)
569 msoLogger.debug("Put sppartner Received a Bad Response Code. Response Code is: " + responseCode)
570 exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
571 throw new BpmnError("MSOWorkflowException")
574 msoLogger.info("Exit " + saveSPPartnerInAAI)
577 private void setProgressUpdateVariables(DelegateExecution execution, String body) {
578 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
579 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
580 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
583 public void postProcess(DelegateExecution execution){
584 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
585 msoLogger.info(" ***** Started postProcess *****")
586 String responseCode = execution.getVariable(Prefix + "PutSppartnerResponseCode")
587 String responseObj = execution.getVariable(Prefix + "PutSppartnerResponse")
589 msoLogger.info("response from AAI for put sppartner, response code :" + responseCode + " response object :" + responseObj)
590 msoLogger.info(" ***** Exit postProcess *****")
593 public void sendSyncResponse (DelegateExecution execution) {
594 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
595 msoLogger.debug(" *** sendSyncResponse *** ")
598 String operationStatus = "finished"
599 // RESTResponse for main flow
600 String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
601 msoLogger.debug(" sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
602 sendWorkflowResponse(execution, 202, resourceOperationResp)
603 execution.setVariable("sentSyncResponse", true)
605 } catch (Exception ex) {
606 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
608 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
610 msoLogger.debug(" ***** Exit sendSyncResopnse *****")
613 String customizeResourceParam(String inputParametersJson) {
614 List<Map<String, Object>> paramList = new ArrayList()
615 JSONObject jsonObject = new JSONObject(inputParametersJson)
616 Iterator iterator = jsonObject.keys()
617 while (iterator.hasNext()) {
618 String key = iterator.next()
619 HashMap<String, String> hashMap = new HashMap()
620 hashMap.put("name", key)
621 hashMap.put("value", jsonObject.get(key))
622 paramList.add(hashMap)
624 Map<String, List<Map<String, Object>>> paramMap = new HashMap()
625 paramMap.put("param", paramList)
627 return new JSONObject(paramMap).toString()