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