Cleaned up content of MsoLogger
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / onap / so / bpmn / common / scripts / SDNCAdapterUtils.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. 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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22
23 package org.onap.so.bpmn.common.scripts;
24
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.aai.domain.yang.L3Network
28 import org.onap.so.bpmn.core.WorkflowException
29 import org.onap.so.bpmn.core.json.JsonUtils;
30 import org.springframework.web.util.UriUtils
31 import org.onap.so.bpmn.core.UrnPropertiesReader
32 import org.onap.so.logger.MessageEnum
33 import org.onap.so.logger.MsoLogger
34 import org.slf4j.Logger
35 import org.slf4j.LoggerFactory
36
37
38
39
40 /**
41  * @version 1.0
42  *
43  */
44 class SDNCAdapterUtils {
45     private static final Logger logger = LoggerFactory.getLogger( SDNCAdapterUtils.class);
46
47
48         ExceptionUtil exceptionUtil = new ExceptionUtil()
49         JsonUtils jsonUtil = new JsonUtils()
50
51         private AbstractServiceTaskProcessor taskProcessor
52
53         public SDNCAdapterUtils(AbstractServiceTaskProcessor taskProcessor) {
54                 this.taskProcessor = taskProcessor
55         }
56
57         String SDNCAdapterFeatureRequest(DelegateExecution execution, String requestName, String action, String callbackURL, String serviceOperation, String timeoutValueInMinutes) {
58                 def utils=new MsoUtils()
59
60                 def prefix = execution.getVariable('prefix')
61                 def request = taskProcessor.getVariable(execution, requestName)
62                 def requestInformation = utils.getNodeXml(request, 'request-information', false)
63                 def serviceInformation = utils.getNodeXml(request, 'service-information', false)
64                 def featureInformation = utils.getNodeXml(request, 'feature-information', false)
65                 def featureParameters = utils.getNodeXml(request, 'feature-parameters', false)
66
67                 def requestId = execution.getVariable('testReqId') // for junits
68                 if(requestId==null){
69                         requestId = execution.getVariable("mso-request-id") + "-" +     System.currentTimeMillis()
70                 }
71
72                 def svcInstanceId = execution.getVariable("mso-service-instance-id")
73
74                 def nnsRequestInformation = utils.removeXmlNamespaces(requestInformation)
75                 def nnsServiceInformation = utils.removeXmlNamespaces(serviceInformation)
76                 def nnsFeatureInformation = utils.removeXmlNamespaces(featureInformation)
77                 def nnsFeatureParameters = utils.removeXmlNamespaces(featureParameters)
78
79                 String sdncAdapterFeatureRequest = """
80                                 <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1"
81                                                 xmlns:sdncadapter="http://domain2.openecomp.com/workflow/sdnc/adapter/schema/v1">
82                                         <sdncadapter:RequestHeader>
83                                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(requestId)}</sdncadapter:RequestId>
84                                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstanceId)}</sdncadapter:SvcInstanceId>
85                                                 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
86                                                 <sdncadapter:SvcOperation>${MsoUtils.xmlEscape(serviceOperation)}</sdncadapter:SvcOperation>
87                                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
88                                         </sdncadapter:RequestHeader>
89                                         <sdncadapterworkflow:SDNCRequestData>
90                                                 ${nnsRequestInformation}
91                                                 ${nnsServiceInformation}
92                                                 ${nnsFeatureInformation}
93                                                 ${nnsFeatureParameters}
94                                         </sdncadapterworkflow:SDNCRequestData>
95                                         <sdncadapterworkflow:SDNCTimeOutValueInMinutes>${MsoUtils.xmlEscape(timeoutValueInMinutes)}</sdncadapterworkflow:SDNCTimeOutValueInMinutes>
96                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
97                         """
98                 sdncAdapterFeatureRequest = utils.removeXmlPreamble(utils.formatXML(sdncAdapterFeatureRequest))
99                 return sdncAdapterFeatureRequest
100         }
101
102         String SDNCAdapterActivateVnfRequest(DelegateExecution execution, String action, String callbackURL, String serviceOperation, String msoAction, String timeoutValueInMinutes) {
103                 def utils=new MsoUtils()
104
105                 def prefix = execution.getVariable('prefix')
106                 def request = taskProcessor.getVariable(execution, prefix+'Request')
107                 def requestInformation = utils.getNodeXml(request, 'request-information', false)
108                 def serviceInformation = utils.getNodeXml(request, 'service-information', false)
109                 def vnfInformationList = utils.getNodeXml(request, 'vnf-information-list', false)
110
111                 def requestId = execution.getVariable('testReqId') // for junits
112                 if(requestId==null){
113                         requestId = execution.getVariable("mso-request-id") + "-" +     System.currentTimeMillis()
114                 }
115
116                 def svcInstanceId = execution.getVariable("mso-service-instance-id")
117
118                 def nnsRequestInformation = utils.removeXmlNamespaces(requestInformation)
119                 def nnsServiceInformation = utils.removeXmlNamespaces(serviceInformation)
120                 def nnsVnfInformationList = utils.removeXmlNamespaces(vnfInformationList)
121
122                 String sdncAdapterActivateVnfRequest = """
123                                 <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1"
124                                                 xmlns:sdncadapter="http://domain2.openecomp.com/workflow/sdnc/adapter/schema/v1">
125                                         <sdncadapter:RequestHeader>
126                                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(requestId)}</sdncadapter:RequestId>
127                                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstanceId)}</sdncadapter:SvcInstanceId>
128                                                 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
129                                                 <sdncadapter:SvcOperation>${MsoUtils.xmlEscape(serviceOperation)}</sdncadapter:SvcOperation>
130                                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
131                                                 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(msoAction)}</sdncadapter:MsoAction>
132                                         </sdncadapter:RequestHeader>
133                                         <sdncadapterworkflow:SDNCRequestData>
134                                                 ${nnsRequestInformation}
135                                                 ${nnsServiceInformation}
136                                                 ${nnsVnfInformationList}
137                                         </sdncadapterworkflow:SDNCRequestData>
138                                         <sdncadapterworkflow:SDNCTimeOutValueInMinutes>${MsoUtils.xmlEscape(timeoutValueInMinutes)}</sdncadapterworkflow:SDNCTimeOutValueInMinutes>
139                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
140                         """
141                 sdncAdapterActivateVnfRequest = utils.removeXmlPreamble(utils.formatXML(sdncAdapterActivateVnfRequest))
142                 return sdncAdapterActivateVnfRequest
143         }
144
145         String SDNCAdapterL3ToHigherLayerRequest(DelegateExecution execution, String action, String callbackURL, String serviceOperation, String timeoutValueInMinutes) {
146                 def utils=new MsoUtils()
147
148                 def prefix = execution.getVariable('prefix')
149                 def request = taskProcessor.getVariable(execution, prefix+'Request')
150
151                 String requestInformation = """<request-information>
152                                                                                 <request-id>${MsoUtils.xmlEscape(execution.getVariable("mso-request-id"))}</request-id>
153                                                                                 <request-action>torepl</request-action>
154                                                                                 <source>${MsoUtils.xmlEscape(execution.getVariable(prefix+"source"))}</source>
155                                                                                 <notification-url>${MsoUtils.xmlEscape(execution.getVariable(prefix+"notificationUrl"))}</notification-url>
156                                                                         </request-information>"""
157
158                 // Change the value of the 'request-information'.'request-action' element
159                 def xml = new XmlSlurper().parseText(requestInformation)
160                 if("assign".equalsIgnoreCase(action)){
161                         xml.'request-action'.replaceBody('createTrinityBonding')
162                 }else if("activate".equalsIgnoreCase(action)){
163                         xml.'request-action'.replaceBody('activateTrinityBonding')
164                 }else if("delete".equalsIgnoreCase(action)){
165                         xml.'request-action'.replaceBody('deleteTrinityBonding')
166                 }
167                 requestInformation = utils.removeXmlPreamble(groovy.xml.XmlUtil.serialize(xml))
168                 def nnsRequestInformation = utils.removeXmlNamespaces(requestInformation)
169
170                 def requestId = execution.getVariable('testReqId') // for junits
171                 if(requestId==null){
172                         requestId = execution.getVariable("mso-request-id") + "-" +     System.currentTimeMillis()
173                 }
174
175                 def svcInstanceId = execution.getVariable("mso-service-instance-id")
176
177                 //Build Service Information
178                 // Send serviceName from CANOPI to sdnc for service-type
179                 String serviceInformation = """<service-information>
180                                                                               <service-type>${MsoUtils.xmlEscape(execution.getVariable(prefix+"serviceName"))}</service-type>
181                                                                               <service-instance-id>${MsoUtils.xmlEscape(svcInstanceId)}</service-instance-id>
182                                                                               <subscriber-name>${MsoUtils.xmlEscape(execution.getVariable(prefix+"subscriberName"))}</subscriber-name>
183                                                                               <subscriber-global-id>${MsoUtils.xmlEscape(execution.getVariable(prefix+"subscriberGlobalId"))}</subscriber-global-id>
184                                                                         </service-information>"""
185
186                 //Build Additional Information - vpn or vni
187                 // Send serviceType from CANOPI to SDNC for nbnc-request-information service-type
188                 def service = execution.getVariable(prefix+"serviceType")
189                 def customerId = execution.getVariable(prefix+"customerId")
190                 def vpnId = execution.getVariable(prefix+"vpnId")
191                 def vpnRt = execution.getVariable(prefix+"vpnRt")
192                 def vpnService = execution.getVariable(prefix+"vpnService")
193                 def vpnRegion = execution.getVariable(prefix+"vpnRegion")
194                 def additionalInfo = ""
195                 if("assign".equalsIgnoreCase(action)){
196                         additionalInfo = """<vpn-data-list>
197                                                                         <vpn-id>${MsoUtils.xmlEscape(vpnId)}</vpn-id>
198                                                                         <vpn-rt>${MsoUtils.xmlEscape(vpnRt)}</vpn-rt>
199                                                                         <vpn-service>${MsoUtils.xmlEscape(vpnService)}</vpn-service>
200                                                                         <vpn-region>${MsoUtils.xmlEscape(vpnRegion)}</vpn-region>
201                                                                 </vpn-data-list>"""
202                 }else if("activate".equalsIgnoreCase(action) || "delete".equalsIgnoreCase(action)){
203                         def vniId = execution.getVariable(prefix+'vniId')
204                         additionalInfo = "<vni-id>${MsoUtils.xmlEscape(vniId)}</vni-id>"
205                 }
206
207                 //Set Interface Status
208                 def interfaceStatus = "DISABLE"
209                 if("activate".equalsIgnoreCase(action)){
210                         interfaceStatus = "ENABLE"
211                 }
212
213                 //Build SDNC Adapter Request
214                 String sdncAdapterL3ToHLRequest = """
215                                 <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1"
216                                                 xmlns:sdncadapter="http://domain2.openecomp.com/workflow/sdnc/adapter/schema/v1">
217                                         <sdncadapter:RequestHeader>
218                                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(requestId)}</sdncadapter:RequestId>
219                                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstanceId)}</sdncadapter:SvcInstanceId>
220                                                 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
221                                                 <sdncadapter:SvcOperation>${MsoUtils.xmlEscape(serviceOperation)}</sdncadapter:SvcOperation>
222                                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
223                                         </sdncadapter:RequestHeader>
224                                         <sdncadapterworkflow:SDNCRequestData>
225                                                 ${nnsRequestInformation}
226                                                 ${serviceInformation}
227                                 <nbnc-request-information>
228                                                         <service-type>${MsoUtils.xmlEscape(service)}</service-type>
229                                                         <customer-id>${MsoUtils.xmlEscape(customerId)}</customer-id>
230                                                         <interface-status>${MsoUtils.xmlEscape(interfaceStatus)}</interface-status>
231                                                         ${additionalInfo}
232                                                 </nbnc-request-information>
233                                         </sdncadapterworkflow:SDNCRequestData>
234                                         <sdncadapterworkflow:SDNCTimeOutValueInMinutes>${MsoUtils.xmlEscape(timeoutValueInMinutes)}</sdncadapterworkflow:SDNCTimeOutValueInMinutes>
235                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
236                         """
237                 sdncAdapterL3ToHLRequest = utils.removeXmlPreamble(utils.formatXML(sdncAdapterL3ToHLRequest))
238
239                 return sdncAdapterL3ToHLRequest
240         }
241
242
243
244         private void SDNCAdapterActivateRequest(DelegateExecution execution, String resultVar, String svcAction,
245                         String svcOperation, String additionalData) {
246                         def utils=new MsoUtils()
247
248                         def prefix = execution.getVariable('prefix')
249                         def request = taskProcessor.getVariable(execution, prefix+'Request')
250                         def requestInformation = utils.getNodeXml(request, 'request-information', false)
251                         def serviceInformation = utils.getNodeXml(request, 'service-information', false)
252                         def serviceParameters = utils.getNodeXml(request, 'service-parameters', false)
253
254                         def requestId = execution.getVariable('testReqId') // for junits
255                         if(requestId==null){
256                                 requestId = execution.getVariable("mso-request-id") + "-" +  System.currentTimeMillis()
257                         }
258
259                         def svcInstanceId = execution.getVariable("mso-service-instance-id")
260                         def msoAction = 'gammainternet'
261
262                         def timeoutInMinutes = UrnPropertiesReader.getVariable('mso.sdnc.timeout.firewall.minutes',execution)
263
264                         def callbackUrl = (String)UrnPropertiesReader.getVariable('mso.workflow.sdncadapter.callback',execution)
265                         if (callbackUrl == null || callbackUrl.trim() == "") {
266                                 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
267                                                 'mso:workflow:sdncadapter:callback URN is not set', "BPMN",
268                                                 MsoLogger.ErrorCode.UnknownError.getValue());
269                                 workflowException(execution, 'Internal Error', 9999) // TODO: what message and error code?
270                         }
271
272                         def l2HomingInformation = utils.getNodeXml(serviceParameters, 'l2-homing-information', false)
273                         def internetEvcAccessInformation = utils.getNodeXml(serviceParameters, 'internet-evc-access-information', false)
274                         def vrLan = utils.getNodeXml(serviceParameters, 'vr-lan', false)
275                         def upceVmsServiceInformation = utils.getNodeXml(serviceParameters, 'ucpe-vms-service-information', false)
276
277
278                         def nnsRequestInformation = utils.removeXmlNamespaces(requestInformation)
279                         def nnsServiceInformation = utils.removeXmlNamespaces(serviceInformation)
280                         def nnsl2HomingInformation = utils.removeXmlNamespaces(l2HomingInformation)
281                         def nnsInternetEvcAccessInformation = utils.removeXmlNamespaces(internetEvcAccessInformation)
282                         def nnsVrLan = utils.removeXmlNamespaces(vrLan)
283                         def nnsUpceVmsServiceInformation = utils.removeXmlNamespaces(upceVmsServiceInformation)
284
285                         if (additionalData == null) {
286                                 additionalData = ""
287                         }
288
289                         boolean isAic3 = execution.getVariable("isAic3")
290
291                         if(isAic3) {
292                                 nnsl2HomingInformation = updateHomingInfo(nnsl2HomingInformation, "AIC3.0")
293                         }
294                         else {
295                                 nnsl2HomingInformation = updateHomingInfo(nnsl2HomingInformation, "AIC2.X")
296                         }
297
298                         String content = """
299                                 <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1"
300                                                 xmlns:sdncadapter="http://domain2.openecomp.com/workflow/sdnc/adapter/schema/v1">
301                                         <sdncadapter:RequestHeader>
302                                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(requestId)}</sdncadapter:RequestId>
303                                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstanceId)}</sdncadapter:SvcInstanceId>
304                                                 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(svcAction)}</sdncadapter:SvcAction>
305                                                 <sdncadapter:SvcOperation>${MsoUtils.xmlEscape(svcOperation)}</sdncadapter:SvcOperation>
306                                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
307                                                 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(msoAction)}</sdncadapter:MsoAction>
308                                         </sdncadapter:RequestHeader>
309                                         <sdncadapterworkflow:SDNCRequestData>
310                                                 ${additionalData}
311                                                 ${nnsRequestInformation}
312                                                 ${nnsServiceInformation}
313                                                 ${nnsl2HomingInformation}
314                                                 ${nnsInternetEvcAccessInformation}
315                                                 ${nnsVrLan}
316                                                 ${nnsUpceVmsServiceInformation}
317                                         </sdncadapterworkflow:SDNCRequestData>
318                                                 <sdncadapterworkflow:SDNCTimeOutValueInMinutes>${MsoUtils.xmlEscape(timeoutInMinutes)}</sdncadapterworkflow:SDNCTimeOutValueInMinutes>
319                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
320                         """
321
322                         content = utils.removeXmlPreamble(utils.formatXML(content))
323                         execution.setVariable(resultVar, content)
324         }
325
326         /**
327          * Builds an SDNC "reserve" request and stores it in the specified execution
328          * variable.
329          * @param execution the execution
330          * @param action the type of action: reserve, turnup, etc
331          * @param resultVar the execution variable in which the result will be stored
332          */
333         public void sdncReservePrep(DelegateExecution execution, String action, String resultVar) {
334                 sdncReservePrep(execution, action, resultVar, false)
335         }
336
337         /**
338          * Builds an SDNC "reserve" request and stores it in the specified execution
339          * variable.
340          * @param execution the execution
341          * @param action the type of action: reserve, turnup, etc
342          * @param resultVar the execution variable in which the result will be stored
343          * @param isAic3 boolean to indicate whether request is for AIC3.0
344          */
345         public void sdncReservePrep(DelegateExecution execution, String action, String resultVar, boolean isAic3) {
346                 sdncPrep(execution, resultVar, action , 'service-configuration-operation', null, isAic3, this.taskProcessor)
347         }
348
349         /**
350          * Builds a basic SDNC request and stores it in the specified execution variable.
351          * @param execution the execution
352          * @param resultVar the execution variable in which the result will be stored
353          * @param svcAction the svcAction element value
354          * @param svcOperation the svcOperation element value
355          * @param additionalData additional XML content to be inserted into the
356          *        RequestData element (may be null)
357          */
358         public void sdncPrep(DelegateExecution execution, String resultVar, String svcAction,
359                 String svcOperation, String additionalData, AbstractServiceTaskProcessor taskProcessor) {
360                 sdncPrep(execution, resultVar, svcAction, svcOperation, additionalData, false, taskProcessor)
361         }
362
363         /**
364          * Builds a basic SDNC request and stores it in the specified execution variable.
365          * @param execution the execution
366          * @param resultVar the execution variable in which the result will be stored
367          * @param svcAction the svcAction element value
368          * @param svcOperation the svcOperation element value
369          * @param additionalData additional XML content to be inserted into the RequestData element (may be null)
370          * @param isAic3 boolean to indicate whether request is for AIC3.0
371          */
372         public void sdncPrep(DelegateExecution execution, String resultVar, String svcAction,
373                         String svcOperation, String additionalData, boolean isAic3, AbstractServiceTaskProcessor taskProcessor) {
374                 def method = getClass().getSimpleName() + '.sdncPrep(' +
375                         'execution=' + execution.getId() +
376                         ', resultVar=' + resultVar +
377                         ', svcAction=' + svcAction +
378                         ', svcOperation=' + svcOperation +
379                         ', additionalData=' + (additionalData == null ? "no" : "yes") +
380                         ')'
381
382                 logger.trace('Entered ' + method)
383                 MsoUtils utils = taskProcessor.utils
384                 try {
385                         def prefix = execution.getVariable('prefix')
386                         def request = taskProcessor.getVariable(execution, prefix+'Request')
387                         def requestInformation = utils.getNodeXml(request, 'request-information', false)
388                         def serviceInformation = utils.getNodeXml(request, 'service-information', false)
389                         def serviceParameters = utils.getChildNodes(request, 'service-parameters')
390                         def requestAction = utils.getNodeText(request, 'request-action')
391
392                         def timeoutInMinutes = UrnPropertiesReader.getVariable('mso.sdnc.timeout.firewall.minutes',execution)
393
394                         def requestId = execution.getVariable('testReqId') // for junits
395                         if(requestId==null){
396                                 requestId = execution.getVariable("mso-request-id") + "-" +     System.currentTimeMillis()
397                         }
398
399                         def svcInstanceId = execution.getVariable("mso-service-instance-id")
400                         def msoAction = 'gammainternet'
401
402                         def callbackUrl = (String)UrnPropertiesReader.getVariable('mso.workflow.sdncadapter.callback',execution)
403                         if (callbackUrl == null || callbackUrl.trim() == "") {
404                                 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
405                                                 'mso:workflow:sdncadapter:callback URN is not set', "BPMN",
406                                                 MsoLogger.ErrorCode.UnknownError.getValue());
407                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Internal Error - During PreProcess Request")
408                         }
409
410                         def l2HomingInformation = utils.getNodeXml(request, 'l2-homing-information', false)
411                         def internetEvcAccessInformation = utils.getNodeXml(request, 'internet-evc-access-information', false)
412                         def vrLan = utils.getNodeXml(request, 'vr-lan', false)
413                         def upceVmsServiceInfo = utils.getNodeXml(request, 'ucpe-vms-service-information', false)
414                         def vnfInformationList = utils.getNodeXml(request, 'vnf-information-list', false)
415
416                         def nnsRequestInformation = utils.removeXmlNamespaces(requestInformation)
417                         def nnsServiceInformation = utils.removeXmlNamespaces(serviceInformation)
418                         def nnsl2HomingInformation = utils.removeXmlNamespaces(l2HomingInformation)
419                         def nnsInternetEvcAccessInformation = utils.removeXmlNamespaces(internetEvcAccessInformation)
420                         def nnsVrLan = utils.removeXmlNamespaces(vrLan)
421                         def nnsUpceVmsServiceInfo = utils.removeXmlNamespaces(upceVmsServiceInfo)
422                         def nnsVnfInformationList = utils.removeXmlNamespaces(vrLan)
423                         def nnsinternetSvcChangeDetails = ""
424
425                         if(requestAction!=null && requestAction.equals("ChangeLayer3ServiceProvRequest")){
426                                 def internetSvcChangeDetails = utils.removeXmlNamespaces(serviceParameters)
427                                 nnsinternetSvcChangeDetails = """<internet-service-change-details>
428                                                         ${internetSvcChangeDetails}
429                                                 </internet-service-change-details>"""
430                         }
431
432                         if (additionalData == null) {
433                                 additionalData = ""
434                         }
435
436                         if(isAic3) {
437                                 nnsl2HomingInformation = updateHomingInfo(nnsl2HomingInformation, "AIC3.0")
438                         }
439                         else {
440                                 nnsl2HomingInformation = updateHomingInfo(nnsl2HomingInformation, "AIC2.X")
441                         }
442
443
444                         String content = """
445                                 <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1"
446                                                 xmlns:sdncadapter="http://domain2.openecomp.com/workflow/sdnc/adapter/schema/v1">
447                                         <sdncadapter:RequestHeader>
448                                                 <sdncadapter:RequestId>${MsoUtils.xmlEscape(requestId)}</sdncadapter:RequestId>
449                                                 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstanceId)}</sdncadapter:SvcInstanceId>
450                                                 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(svcAction)}</sdncadapter:SvcAction>
451                                                 <sdncadapter:SvcOperation>${MsoUtils.xmlEscape(svcOperation)}</sdncadapter:SvcOperation>
452                                                 <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackUrl)}</sdncadapter:CallbackUrl>
453                                                 <sdncadapter:MsoAction>${MsoUtils.xmlEscape(msoAction)}</sdncadapter:MsoAction>
454                                         </sdncadapter:RequestHeader>
455                                         <sdncadapterworkflow:SDNCRequestData>
456                                                 ${additionalData}
457                                                 ${nnsRequestInformation}
458                                                 ${nnsServiceInformation}
459                                                 ${nnsl2HomingInformation}
460                                                 ${nnsInternetEvcAccessInformation}
461                                                 ${nnsVrLan}
462                                                 ${nnsUpceVmsServiceInfo}
463                                                 ${nnsVnfInformationList}
464                                                 ${nnsinternetSvcChangeDetails}
465                                         </sdncadapterworkflow:SDNCRequestData>
466                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>
467                         """
468
469                         content = utils.removeXmlPreamble(utils.formatXML(content))
470                         execution.setVariable(resultVar, content)
471                         logger.debug(resultVar + ' = ' + System.lineSeparator() + content)
472
473                         logger.trace('Exited ' + method)
474                 } catch (BpmnError e) {
475                         throw e;
476                 } catch (Exception e) {
477                         logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
478                                         'Caught exception in ' + method, "BPMN",
479                                         MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
480                         exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error")
481                 }
482         }
483
484         public String updateHomingInfo(String homingInfo, String aicVersion) {
485                 String newHomingInfo
486                 if(homingInfo == null || homingInfo.trim().length() == 0) {
487                         newHomingInfo = "<l2-homing-information><aic-version>" + aicVersion + "</aic-version></l2-homing-information>"
488                 }
489                 else {
490                         newHomingInfo = homingInfo.substring(0, homingInfo.indexOf("</l2-homing-information>")) + "<aic-version>" + aicVersion + "</aic-version></l2-homing-information>"
491                 }
492         }
493
494         /**
495          * Builds a topology SDNC request and return String request.
496          * As V2 will use 1607-style request, region instead of aic clli code
497          * @param execution, the execution
498          * @param requestXML, the incoming request for the flow
499          * @param serviceInstanceId, the serviceIntance (if available)
500          * @param callbackUrl, the call back url
501          * @param action, the action element value
502          * @param requestAction the svcOperation element value
503          * @param cloudRegionId the aai's cloud-region-id
504          * @param networkId the aai's network-id
505          * @param additionalData additional XML content to be inserted into the
506          *   RequestData element (may be null)
507          */
508          public String sdncTopologyRequestV2 (DelegateExecution execution, String requestXML, String serviceInstanceId, String callbackUrl, String action, String requestAction, String cloudRegionId, networkId, L3Network queryAAIResponse, String additionalData) {
509                  def utils=new MsoUtils()
510
511                  // SNDC is expecting request Id for header as unique each call.
512                  String hdrRequestId = ""
513                  String testHdrRequestId = execution.getVariable("testMessageId")  // for test purposes.
514                  if (testHdrRequestId == null) {
515                          hdrRequestId = UUID.randomUUID()  // generate unique
516                  } else {
517                          hdrRequestId = testHdrRequestId
518                  }
519
520                  String requestId = ""
521                  try {
522                          requestId = execution.getVariable("mso-request-id")
523                  } catch (Exception ex) {
524                          requestId = utils.getNodeText(requestXML, "request-id")
525                  }
526
527                  String aicCloudRegion = cloudRegionId
528                  String tenantId = ""
529                  if (utils.nodeExists(requestXML, "tenant-id")) {
530                          tenantId = utils.getNodeText(requestXML, "tenant-id")
531                  }
532                  String networkType = ""
533                  if (utils.nodeExists(requestXML, "network-type")) {
534                          networkType = utils.getNodeText(requestXML, "network-type")
535                  }
536
537                  // Replace/Use the value of network-type from aai query (vs input) during Delete Network flows.
538                  if (queryAAIResponse != null) {
539                      networkType = queryAAIResponse.getNetworkType()
540                  }
541
542                  String serviceId = ""
543                  if (utils.nodeExists(requestXML, "service-id")) {
544                          serviceId = utils.getNodeText(requestXML, "service-id")
545                  }
546                  String networkName = ""
547                  // Replace/Use the value of network-name from aai query (vs input) if it was already set in AAI
548                  if (queryAAIResponse != null) {
549                          networkName = queryAAIResponse.getNetworkName()
550                  }
551                  if (networkName.isEmpty() && utils.nodeExists(requestXML, "network-name")) {
552                          networkName = utils.getNodeText(requestXML, "network-name")
553                  }
554                  String source = ""
555                  if (utils.nodeExists(requestXML, "source")) {
556                          source = utils.getNodeText(requestXML, "source")
557                  }
558
559                  // get resourceLink from subflow execution variable
560                  String serviceType = ""
561                  String subscriberName = ""
562                  String siRelatedLink = execution.getVariable("GENGSI_siResourceLink")
563                  if (siRelatedLink != null) {
564                          // get service type
565                          int serviceStart = siRelatedLink.indexOf("service-subscription/")
566                          int serviceEnd = siRelatedLink.indexOf("/service-instances/")
567                          serviceType = siRelatedLink.substring(serviceStart + 21, serviceEnd)
568                          serviceType = UriUtils.decode(serviceType,"UTF-8")
569                          // get subscriber name
570                          int subscriberNameStart = siRelatedLink.indexOf("customers/customer/")
571                          int subscriberNameEnd = siRelatedLink.indexOf("/service-subscriptions/")
572                      subscriberName = siRelatedLink.substring(subscriberNameStart + 19, subscriberNameEnd)
573                          subscriberName = UriUtils.decode(subscriberName,"UTF-8")
574                  }else{
575                          serviceType = execution.getVariable("serviceType")
576                          subscriberName = execution.getVariable("subscriberName")
577                  }
578
579                  String content =
580                         """<aetgt:SDNCAdapterWorkflowRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
581                                                   xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
582                                                   xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1"
583                                                   xmlns:ns5="http://org.onap/so/request/types/v1">
584                                            <sdncadapter:RequestHeader>
585                                                   <sdncadapter:RequestId>${MsoUtils.xmlEscape(hdrRequestId)}</sdncadapter:RequestId>
586                                                   <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
587                                                   <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
588                                                   <sdncadapter:SvcOperation>network-topology-operation</sdncadapter:SvcOperation>
589                                                   <sdncadapter:CallbackUrl>sdncCallback</sdncadapter:CallbackUrl>
590                                            </sdncadapter:RequestHeader>
591                                            <sdncadapterworkflow:SDNCRequestData>
592                                               <request-information>
593                                                     <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
594                                                     <request-action>${MsoUtils.xmlEscape(requestAction)}</request-action>
595                                                     <source>${MsoUtils.xmlEscape(source)}</source>
596                                                     <notification-url></notification-url>
597                                                     <order-number></order-number>
598                                                     <order-version></order-version>
599                                                  </request-information>
600                                                  <service-information>
601                                                     <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
602                                                                 <service-type>${MsoUtils.xmlEscape(serviceType)}</service-type>
603                                                     <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
604                                                     <subscriber-name>${MsoUtils.xmlEscape(subscriberName)}</subscriber-name>
605                                                  </service-information>
606                                                  <network-request-information>
607                                                     <network-id>${MsoUtils.xmlEscape(networkId)}</network-id>
608                                                     <network-type>${MsoUtils.xmlEscape(networkType)}</network-type>
609                                                     <network-name>${MsoUtils.xmlEscape(networkName)}</network-name>
610                                                     <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
611                                                     <aic-cloud-region>${MsoUtils.xmlEscape(aicCloudRegion)}</aic-cloud-region>
612                                                  </network-request-information>
613                                            </sdncadapterworkflow:SDNCRequestData>
614                                    </aetgt:SDNCAdapterWorkflowRequest>""".trim()
615
616                         return content
617          }
618
619          /**
620           * Builds a topology SDNC request and return String request.
621           * As V2 will use 1607-style request, region instead of aic clli code
622           * @param execution, the execution
623           * @param requestXML, the incoming request for the flow
624           * @param serviceInstanceId, the serviceIntance (if available)
625           * @param callbackUrl, the call back url
626           * @param action, the action element value
627           * @param requestAction the svcOperation element value
628           * @param cloudRegionId the aai's cloud-region-id
629           * @param networkId the aai's network-id
630           * @param additionalData additional XML content to be inserted into the
631           *   RequestData element (may be null)
632           */
633           public String sdncTopologyRequestRsrc (DelegateExecution execution, String requestXML, String serviceInstanceId, String callbackUrl, String action, String requestAction, String cloudRegionId, networkId, String additionalData) {
634                   def utils=new MsoUtils()
635
636                   // SNDC is expecting request Id for header as unique each call.
637                   String hdrRequestId = ""
638                   String testHdrRequestId = execution.getVariable("testMessageId")  // for test purposes.
639                   if (testHdrRequestId == null) {
640                       hdrRequestId = UUID.randomUUID()  // generate unique
641                   } else {
642                       hdrRequestId = testHdrRequestId
643                   }
644
645                   String requestId = ""
646                   String testRequestId = execution.getVariable("testMessageId")  // for test purposes.
647                   if (testRequestId == null) {
648                           requestId = execution.getVariable("mso-request-id")
649                           if (requestId == null) {
650                                   requestId = execution.getVariable("msoRequestId")
651                           }
652                   } else {
653                           requestId = testRequestId
654                   }
655
656                   String aicCloudRegion = cloudRegionId
657                   String tenantId = ""
658                   if (utils.nodeExists(requestXML, "tenant-id")) {
659                           tenantId = utils.getNodeText(requestXML, "tenant-id")
660                   }
661                   String networkType = ""
662                   if (utils.nodeExists(requestXML, "network-type")) {
663                           networkType = utils.getNodeText(requestXML, "network-type")
664                   }
665
666                   String subscriptionServiceType = ""
667                   if (utils.nodeExists(requestXML, "subscription-service-type")) {
668                           subscriptionServiceType = utils.getNodeText(requestXML, "subscription-service-type")
669                   }
670
671                   String globalCustomerId = ""
672                   if (utils.nodeExists(requestXML, "global-customer-id")) {
673                           globalCustomerId = utils.getNodeText(requestXML, "global-customer-id")
674                   }
675
676                   String serviceId = ""
677                   if (utils.nodeExists(requestXML, "service-id")) {
678                           serviceId = utils.getNodeText(requestXML, "service-id")
679                   }
680                   String networkName = ""
681                   if (utils.nodeExists(requestXML, "network-name")) {
682                           networkName = utils.getNodeText(requestXML, "network-name")
683                   }
684                   String source = ""
685                   if (utils.nodeExists(requestXML, "source")) {
686                           source = utils.getNodeText(requestXML, "source")
687                   }
688
689                   // get resourceLink from subflow execution variable
690                   String serviceType = ""
691                   String subscriberName = ""
692                   String siRelatedLink = execution.getVariable("GENGSI_siResourceLink")
693                   if (siRelatedLink != null) {
694                           // get service type
695                           int serviceStart = siRelatedLink.indexOf("service-subscription/")
696                           int serviceEnd = siRelatedLink.indexOf("/service-instances/")
697                           serviceType = siRelatedLink.substring(serviceStart + 21, serviceEnd)
698                           serviceType = UriUtils.decode(serviceType,"UTF-8")
699                           // get subscriber name
700                           int subscriberNameStart = siRelatedLink.indexOf("customers/customer/")
701                           int subscriberNameEnd = siRelatedLink.indexOf("/service-subscriptions/")
702                           subscriberName = siRelatedLink.substring(subscriberNameStart + 19, subscriberNameEnd)
703                           subscriberName = UriUtils.decode(subscriberName,"UTF-8")
704                   }
705
706                   // network-information from 'networkModelInfo' // verify the DB Catalog response
707                   String networkModelInfo = utils.getNodeXml(requestXML, "networkModelInfo", false).replace("tag0:","").replace(":tag0","")
708                   String modelInvariantUuid = utils.getNodeText(networkModelInfo, "modelInvariantUuid") !=null ?
709                                               utils.getNodeText(networkModelInfo, "modelInvariantUuid") : ""
710                   String modelCustomizationUuid = utils.getNodeText(networkModelInfo, "modelCustomizationUuid")  !=null ?
711                                                   utils.getNodeText(networkModelInfo, "modelCustomizationUuid")  : ""
712                   String modelUuid = utils.getNodeText(networkModelInfo, "modelUuid") !=null ?
713                                      utils.getNodeText(networkModelInfo, "modelUuid") : ""
714                   String modelVersion = utils.getNodeText(networkModelInfo, "modelVersion") !=null ?
715                                             utils.getNodeText(networkModelInfo, "modelVersion") : ""
716                   String modelName = utils.getNodeText(networkModelInfo, "modelName") !=null ?
717                                      utils.getNodeText(networkModelInfo, "modelName") : ""
718
719                  // service-information from 'networkModelInfo' // verify the DB Catalog response
720                  String serviceModelInfo = utils.getNodeXml(requestXML, "serviceModelInfo", false).replace("tag0:","").replace(":tag0","")
721                  String serviceModelInvariantUuid = utils.getNodeText(serviceModelInfo, "modelInvariantUuid")  !=null ?
722                                                                                     utils.getNodeText(serviceModelInfo, "modelInvariantUuid")  : ""
723                  String serviceModelUuid = utils.getNodeText(serviceModelInfo, "modelUuid") !=null ?
724                                                                utils.getNodeText(serviceModelInfo, "modelUuid") : ""
725                  String serviceModelVersion = utils.getNodeText(serviceModelInfo, "modelVersion") !=null ?
726                                                                   utils.getNodeText(serviceModelInfo, "modelVersion") : ""
727                  String serviceModelName = utils.getNodeText(serviceModelInfo, "modelName") !=null ?
728                                                            utils.getNodeText(serviceModelInfo, "modelName") : ""
729
730
731                   String content =
732                   """<aetgt:SDNCAdapterWorkflowRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
733                                                                     xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1"
734                                                     xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1">
735                                            <sdncadapter:RequestHeader>
736                                                   <sdncadapter:RequestId>${MsoUtils.xmlEscape(hdrRequestId)}</sdncadapter:RequestId>
737                                                   <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
738                                                   <sdncadapter:SvcAction>${MsoUtils.xmlEscape(action)}</sdncadapter:SvcAction>
739                                                   <sdncadapter:SvcOperation>network-topology-operation</sdncadapter:SvcOperation>
740                                                   <sdncadapter:CallbackUrl>sdncCallback</sdncadapter:CallbackUrl>
741                           <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
742                                            </sdncadapter:RequestHeader>
743                                            <sdncadapterworkflow:SDNCRequestData>
744                                                    <request-information>
745                                                       <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
746                                                       <request-action>${MsoUtils.xmlEscape(requestAction)}</request-action>
747                                                       <source>${MsoUtils.xmlEscape(source)}</source>
748                                                       <notification-url></notification-url>
749                                                       <order-number></order-number>
750                                                       <order-version></order-version>
751                                                    </request-information>
752                                                    <service-information>
753                                                       <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
754                                                       <subscription-service-type>${MsoUtils.xmlEscape(subscriptionServiceType)}</subscription-service-type>
755                                                           <onap-model-information>
756                                                                    <model-invariant-uuid>${MsoUtils.xmlEscape(serviceModelInvariantUuid)}</model-invariant-uuid>
757                                                                    <model-uuid>${MsoUtils.xmlEscape(serviceModelUuid)}</model-uuid>
758                                                                    <model-version>${MsoUtils.xmlEscape(serviceModelVersion)}</model-version>
759                                                                    <model-name>${MsoUtils.xmlEscape(serviceModelName)}</model-name>
760                               </onap-model-information>
761                                                       <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
762                                                       <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id>
763                                                       <subscriber-name>${MsoUtils.xmlEscape(subscriberName)}</subscriber-name>
764                                                    </service-information>
765                                                    <network-information>
766                                                       <network-id>${MsoUtils.xmlEscape(networkId)}</network-id>
767                                                       <network-type>${MsoUtils.xmlEscape(networkType)}</network-type>
768                                                           <onap-model-information>
769                                                                    <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
770                                                                    <model-customization-uuid>${MsoUtils.xmlEscape(modelCustomizationUuid)}</model-customization-uuid>
771                                                                    <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
772                                                                    <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
773                                                                    <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
774                                                           </onap-model-information>
775                                                    </network-information>
776                                                    <network-request-input>
777                                                      <network-name>${MsoUtils.xmlEscape(networkName)}</network-name>
778                                                  <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
779                                                      <aic-cloud-region>${MsoUtils.xmlEscape(aicCloudRegion)}</aic-cloud-region>
780                                                      <aic-clli></aic-clli>
781                                                      <network-input-parameters/>
782                                                    </network-request-input>
783                                       </sdncadapterworkflow:SDNCRequestData>
784                    </aetgt:SDNCAdapterWorkflowRequest>""".trim()
785
786                          return content
787           }
788
789                         /**
790                          * Validates a workflow response.
791                          * @param execution the execution
792                          * @param responseVar the execution variable in which the response is stored
793                          * @param workflowException the WorkflowException Object returned from sdnc call
794                          */
795         public void validateSDNCResponse(DelegateExecution execution, String response, WorkflowException workflowException, boolean successIndicator){
796                 logger.debug("SDNC Response is: " + response)
797                 logger.debug("SuccessIndicator is: " + successIndicator)
798
799                 try {
800                         def prefix = execution.getVariable('prefix')
801                         execution.setVariable(prefix+'sdncResponseSuccess', false)
802                         logger.debug("Response" + ' = ' + (response == null ? "" : System.lineSeparator()) + response)
803
804                         if (successIndicator){
805                                 if (response == null || response.trim().equals("")) {
806                                         logger.debug(response + ' is empty');
807                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "SDNCAdapter Workflow Response is Empty")
808                                 }else{
809
810                                         // we need to peer into the request data for error
811                                         def String sdncAdapterWorkflowResponse = taskProcessor.utils.getNodeXml(response, 'response-data', false)
812                                         def String decodedXml = sdncAdapterWorkflowResponse.replace('<?xml version="1.0" encoding="UTF-8"?>', "")
813                                         decodedXml = taskProcessor.utils.getNodeXml(response, 'RequestData')
814                                         logger.debug("decodedXml:\n" + decodedXml)
815
816                                         int requestDataResponseCode = 200
817                                         def String requestDataResponseMessage = ''
818
819                                         try{
820                                                 if (taskProcessor.utils.nodeExists(decodedXml, "response-message")) {
821                                                         requestDataResponseMessage = taskProcessor.utils.getNodeText(decodedXml, "response-message")
822                                                 } else if (taskProcessor.utils.nodeExists(sdncAdapterWorkflowResponse, "ResponseMessage")) {
823                                                         requestDataResponseMessage = taskProcessor.utils.getNodeText(sdncAdapterWorkflowResponse, "ResponseMessage")
824                                                 }
825                                         }catch(Exception e){
826                                                 logger.debug('Error caught while decoding resposne ' + e.getMessage())
827                                         }
828
829                                         if(taskProcessor.utils.nodeExists(decodedXml, "response-code")) {
830                                                 logger.debug("response-code node Exist ")
831                                                 String code = taskProcessor.utils.getNodeText(decodedXml, "response-code")
832                                                 if(code.isEmpty() || code.equals("")){
833                                                         // if response-code is blank then Success
834                                                         logger.debug("response-code node is empty")
835                                                         requestDataResponseCode = 0
836                                                 }else{
837                                                         requestDataResponseCode  = code.toInteger()
838                                                         logger.debug("response-code is: " + requestDataResponseCode)
839                                                 }
840                                         }else if(taskProcessor.utils.nodeExists(sdncAdapterWorkflowResponse, "ResponseCode")){
841                                                 logger.debug("ResponseCode node Exist ")
842                                                 String code = taskProcessor.utils.getNodeText(sdncAdapterWorkflowResponse, "ResponseCode")
843                                                 if(code.isEmpty() || code.equals("")){
844                                                         // if ResponseCode blank then Success
845                                                         logger.debug("ResponseCode node is empty")
846                                                         requestDataResponseCode = 0
847                                                 }else{
848                                                         requestDataResponseCode  = code.toInteger()
849                                                         logger.debug("ResponseCode is: " + requestDataResponseCode)
850                                                 }
851                                         }else{
852                                                 logger.debug("A Response Code DOES NOT Exist.")
853                                                 // if a response code does not exist then Success
854                                                 requestDataResponseCode = 0
855                                         }
856                                         try{
857
858                                                 execution.setVariable(prefix+'sdncRequestDataResponseCode', requestDataResponseCode.toString())
859                                                 // if a response code is 0 or 2XX then Success
860                                                 if ((requestDataResponseCode >= 200 && requestDataResponseCode <= 299) || requestDataResponseCode == 0) {
861                                                         execution.setVariable(prefix+'sdncResponseSuccess', true)
862                                                         logger.debug("Setting sdncResponseSuccess to True ")
863                                                         logger.debug("Exited ValidateSDNCResponse Method")
864                                                 }else{
865                                                         ExceptionUtil exceptionUtil = new ExceptionUtil()
866                                                         String convertedCode = exceptionUtil.MapSDNCResponseCodeToErrorCode(requestDataResponseCode.toString())
867                                                         int convertedCodeInt = Integer.parseInt(convertedCode)
868                                                         exceptionUtil.buildAndThrowWorkflowException(execution, convertedCodeInt, "Received error from SDN-C: " + requestDataResponseMessage)
869                                                 }
870
871                                         }catch(Exception e){
872                                                 //TODO proper handling of new, non numerical response codes in 1607 and new error handling for common API
873                                                 requestDataResponseCode = 500
874                                         }
875
876                                         logger.debug("SDNC callback response-code: " + requestDataResponseCode)
877                                         logger.debug("SDNC callback response-message: " + requestDataResponseMessage)
878                                 }
879
880                         }else {
881                                 logger.debug('SDNCAdapter Subflow did NOT complete Successfully.  SuccessIndicator is False. ')
882                                 if(workflowException != null){
883                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
884                                 }else{
885                                         //TODO : what error code and error message use here
886                                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Internal Error - SDNCAdapter Subflow did NOT complete successfully.")
887                                 }
888                         }
889
890                 } catch (BpmnError e) {
891                         throw e;
892                 } catch (Exception e) {
893                         logger.debug('END of Validate SDNC Response')
894                         exceptionUtil.buildAndThrowWorkflowException(execution, 500, 'Internal Error- Unable to validate SDNC Response ');
895                 }
896         }
897
898         /**
899                          * Validates a workflow response.
900                          * @param execution the execution
901                          * @param responseVar the execution variable in which the response is stored
902                          * @param responseCodeVar the execution variable in which the response code is stored
903                          * @param errorResponseVar the execution variable in which the error response is stored
904                          */
905                         public void validateL3BondingSDNCResp(DelegateExecution execution, String response, WorkflowException workflowException, boolean success) {
906                                 def method = getClass().getSimpleName() + '.validateL3BondingSDNCResp(' +
907                                         'execution=' + execution.getId() +
908                                         ', response=' + response +
909                                         ')'
910                                 logger.trace('Entered ' + method)
911                                 def prefix = execution.getVariable('prefix')
912                                 TrinityExceptionUtil trinityExceptionUtil = new TrinityExceptionUtil()
913
914                                 try {
915                                         execution.setVariable(prefix+'sdncResponseSuccess', false)
916
917                                         logger.debug("sdncAdapter Success Indicator is: " + success)
918                                         if (success) {
919
920                                                 // we need to look inside the request data for error
921                                                 def String callbackRequestData = taskProcessor.utils.getNodeXml(response, 'RequestData', false)
922                                                 def String decodedXml = callbackRequestData
923                                                 logger.debug("decodedXml:\n" + decodedXml)
924
925                                                 def requestDataResponseCode = '200'
926                                                 def requestDataResponseMessage = ''
927                                                 int intDataResponseCode = 200
928
929                                                 if (taskProcessor.utils.nodeExists(decodedXml, "response-code")) {
930
931                                                         requestDataResponseCode  = ((String) taskProcessor.utils.getNodeText(decodedXml, "response-code"))
932                                                         if (taskProcessor.utils.nodeExists(decodedXml, "response-message")) {
933                                                                 requestDataResponseMessage  = taskProcessor.utils.getNodeText(decodedXml, "response-message")
934                                                         }
935                                                 }else if(taskProcessor.utils.nodeExists(decodedXml, "ResponseCode")){
936                                                         requestDataResponseCode  = ((String) taskProcessor.utils.getNodeText(decodedXml, "ResponseCode")).toInteger()
937                                                 }else if(taskProcessor.utils.nodeExists(response, "ResponseCode")){
938                                                         requestDataResponseCode  = ((String) taskProcessor.utils.getNodeText(response, "ResponseCode")).toInteger()
939                                                         requestDataResponseMessage  = taskProcessor.utils.getNodeText(response, "ResponseMessage")
940                                                 }
941
942                                                 logger.debug("SDNC callback response-code: " + requestDataResponseCode)
943                                                 logger.debug("SDNC callback response-message: " + requestDataResponseMessage)
944
945                                                 // Get the AAI Status to determine if rollback is needed on ASSIGN
946                                                 def aai_status = ''
947                                                 if (taskProcessor.utils.nodeExists(decodedXml, "aai-status")) {
948                                                         aai_status = ((String) taskProcessor.utils.getNodeText(decodedXml, "aai-status"))
949                                                         logger.debug("SDNC sent AAI STATUS code: " + aai_status)
950                                                 }
951                                                 if (aai_status != null && !aai_status.equals("")) {
952                                                         execution.setVariable(prefix+"AaiStatus",aai_status)
953                                                         logger.debug("Set variable " + prefix + "AaiStatus: " + execution.getVariable(prefix+"AaiStatus"))
954                                                 }
955
956                                                 // Get the result string to determine if rollback is needed on ASSIGN in Add Bonding flow only
957                                                 def sdncResult = ''
958                                                 if (taskProcessor.utils.nodeExists(decodedXml, "result")) {
959                                                         sdncResult = ((String) taskProcessor.utils.getNodeText(decodedXml, "result"))
960                                                         logger.debug("SDNC sent result: " + sdncResult)
961                                                 }
962                                                 if (sdncResult != null && !sdncResult.equals("")) {
963                                                         execution.setVariable(prefix+"SdncResult",sdncResult)
964                                                         logger.debug("Set variable " + prefix + "SdncResult: " + execution.getVariable(prefix+"SdncResult"))
965                                                 }
966
967                                                 try{
968                                                         intDataResponseCode = Integer.parseInt(String.valueOf(requestDataResponseCode))
969                                                 }catch(Exception e){
970                                                         intDataResponseCode = 400
971                                                 }
972
973                                                 logger.debug("intDataResponseCode " + intDataResponseCode )
974
975                                                 // if response-code is not Success (200, 201, etc) we need to throw an exception
976                                                 if ((intDataResponseCode < 200 || intDataResponseCode > 299) && intDataResponseCode != 0) {
977                                                         execution.setVariable(prefix+'ResponseCode', intDataResponseCode)
978                                                         execution.setVariable("L3HLAB_rollback", true)
979                                                         def msg = trinityExceptionUtil.mapSDNCAdapterExceptionToErrorResponse(response, execution)
980                                                         exceptionUtil.buildAndThrowWorkflowException(execution, intDataResponseCode, "Received error from SDN-C: " + msg)
981
982                                                 }
983                                         }else {
984                                                 logger.warn("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_WARNING,
985                                                                 'sdncAdapter did not complete successfully, sdncAdapter Success Indicator was false ',
986                                                                 "BPMN", MsoLogger.ErrorCode.UnknownError,
987                                                                 'sdncAdapter did not complete successfully, sdncAdapter Success Indicator was false ')
988                                                 execution.setVariable("L3HLAB_rollback", true)
989                                                 def msg = trinityExceptionUtil.intDataResponseCode(response, execution)
990                                                 exceptionUtil.buildAndThrowWorkflowException(execution, intDataResponseCode, msg)
991                                         }
992
993                                         if (response == null || response.trim().equals("")) {
994                                                 logger.warn("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_WARNING,
995                                                                 'sdncAdapter workflow response is empty', "BPMN",
996                                                                 MsoLogger.ErrorCode.UnknownError, 'sdncAdapter workflow response is empty')
997                                                 execution.setVariable("L3HLAB_rollback", true)
998                                                 def msg = trinityExceptionUtil.buildException("Exception occurred while validating SDNC response " , execution)
999                                                 exceptionUtil.buildAndThrowWorkflowException(execution, intResponseCode, msg)
1000                                         }
1001
1002                                         execution.setVariable(prefix+'sdncResponseSuccess', true)
1003                                         logger.trace('Exited ' + method)
1004                                 } catch (BpmnError e) {
1005                                         throw e;
1006                                 } catch (Exception e) {
1007                                         logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), 'Caught ' +
1008                                                         'exception in ' + method, "BPMN", MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
1009                                         execution.setVariable(prefix+"ResponseCode",400)
1010                                         execution.setVariable("L3HLAB_rollback", true)
1011                                         def msg = trinityExceptionUtil.buildException("Exception occurred while validating SDNC response: " + e.getMessage(), execution)
1012                                         exceptionUtil.buildAndThrowWorkflowException(execution, 400, msg)
1013                                 }
1014                         }
1015
1016         public String modelInfoToEcompModelInformation(String jsonModelInfo) {
1017                 String modelInvariantUuid = jsonUtil.getJsonValue(jsonModelInfo, "modelInvariantUuid")
1018                 String modelUuid = jsonUtil.getJsonValue(jsonModelInfo, "modelUuid")
1019                 if (modelUuid == null) {
1020                         modelUuid = ""
1021                 }
1022                 String modelCustomizationUuid = jsonUtil.getJsonValue(jsonModelInfo, "modelCustomizationUuid")
1023                 String modelCustomizationString = ""
1024                 if (modelCustomizationUuid != null) {
1025                         modelCustomizationString = "<model-customization-uuid>${MsoUtils.xmlEscape(modelCustomizationUuid)}</model-customization-uuid>"
1026                 }
1027                 String modelVersion = jsonUtil.getJsonValue(jsonModelInfo, "modelVersion")
1028                 if (modelVersion == null) {
1029                         modelVersion = ""
1030                 }
1031                 String modelName = jsonUtil.getJsonValue(jsonModelInfo, "modelName")
1032                 String ecompModelInformation =
1033                                 """<onap-model-information>
1034                                                 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
1035                                                 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
1036                                                 ${modelCustomizationString}
1037                                                 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
1038                                                 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
1039                                 </onap-model-information>"""
1040
1041                 return ecompModelInformation
1042         }
1043 }