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