[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / openecomp / mso / bpmn / common / scripts / MsoUtils.groovy
  * ============LICENSE_END=========================================================
  */
 
-package com.att.bpm.scripts
+package org.openecomp.mso.bpmn.common.scripts
 
-import groovy.util.Node;
 import groovy.xml.XmlUtil
 
 import java.text.SimpleDateFormat
 
 import org.apache.commons.codec.binary.Base64
-
-
-
-import org.apache.commons.codec.binary.Base64
-import org.camunda.bpm.engine.runtime.Execution;
-import org.slf4j.MDC;
-import org.w3c.dom.Element
-//import org.w3c.dom.NodeList
-
 import org.openecomp.mso.bpmn.core.BPMNLogger
+import org.openecomp.mso.bpmn.core.xml.XmlTool
 import org.openecomp.mso.logger.MessageEnum
 import org.openecomp.mso.logger.MsoLogger
 import org.openecomp.mso.utils.CryptoUtils
-import org.openecomp.mso.bpmn.core.xml.XmlTool
+import org.w3c.dom.Element
 
 class MsoUtils {
        def initializeEndPoints(execution){
                // use this placeholder to initialize end points, if called independently, this need to be set
-               execution.setVariable("AAIEndPoint","http://localhost:8080/SoapUIMocks")                        
+               execution.setVariable("AAIEndPoint","http://localhost:28080/SoapUIMocks")                       
        }
        def getNodeText(xmlInput,element){
                def rtn=null
@@ -209,7 +200,7 @@ class MsoUtils {
                return ret
        }
        
-       // for Trinity L3 delete bonding
+       // for Trinity L3 add/delete bonding
        def getPBGFList(isDebugLogEnabled, xmlInput){
                xmlInput = xmlInput.replaceAll("&", "&")
                xmlInput = xmlInput.replaceAll("&lt;", "<")
@@ -220,13 +211,34 @@ class MsoUtils {
                def respInfo=getNodeXml(xmlInput,"nbnc-response-information", false)
                if(respInfo!=null){
                        def fxml= new XmlSlurper().parseText(respInfo)
-                       def myNode
                        fxml.'virtual-datacenter-list'.each { vdc ->
-                               //we only want to add one BFG per VDC
-                               log("DEBUG", "vdc " + vdc.text(),isDebugLogEnabled)
-                               myNode = vdc.'**'.find {it.'border-element-tangibility'.text() =~ /PHYSICAL/}
-                               log("DEBUG", "myNode " + myNode.text(),isDebugLogEnabled)
-                               myNodes.add(XmlUtil.serialize(myNode))
+                               //we only want to add two BGF per VDC, BGF1 and BGF2
+                                       def routerList = vdc.'router-list'.first()
+                                       routerList.each{ myList ->
+                                               def physNodes  = myList.'**'.findAll {it.'border-element-tangibility'.text() =~ /PHYSICAL/}
+                                               def nodeToAdd
+                                               physNodes.each{
+                                                       if(nodeToAdd==null){
+                                                               nodeToAdd = it
+                                                       }else{
+                                                               def beid = nodeToAdd.'border-element-id'.text() +
+                                                                        " " + nodeToAdd.'border-element-type'.text() +
+                                                                        " and " +
+                                                                        it.'border-element-id'.text() +
+                                                                        " " + it.'border-element-type'.text()
+                                                               def mytag = nodeToAdd.'border-element-id'
+                                                               mytag[0].replaceBody(beid)
+                                                       }
+                                               }
+                                               def mytag = nodeToAdd.'vlan-id'
+                                               def ind = mytag.text().indexOf('.')
+                                               if(ind >= 0){
+                                                       def vlan = mytag.text().substring(0,ind)
+                                                       mytag[0].replaceBody(vlan)
+                                               }
+                                               myNodes.add(XmlUtil.serialize(nodeToAdd))
+                                       }
+                                       
                        }
                }
                                
@@ -449,6 +461,16 @@ class MsoUtils {
                return xmlBuildUnbounded
         }
        
+       // Build l2-homing-information
+       def buildL2HomingInformation(xmlInput) {
+               def elementsL2HomingList = ["evc-name", "topology", "preferred-aic-clli"]
+               def rebuildL2Home = ''
+               if (xmlInput != null) {
+                       rebuildL2Home = buildElements(xmlInput, elementsL2HomingList, "l2-homing-information")
+               }
+               return rebuildL2Home
+       }
+       
        // Build internet-evc-access-information
        def buildInternetEvcAccessInformation(xmlInput) {
                def elementsInternetEvcAccessInformationList = ["internet-evc-speed-value", "internet-evc-speed-units", "ip-version"]
@@ -459,6 +481,38 @@ class MsoUtils {
                return rebuildInternetEvcAccess
        }
        
+       // Build ucpe-vms-service-information
+       def buildUcpeVmsServiceInformation(xmlInput) {
+               def rebuildUcpeVmsServiceInformation = ''
+               if (xmlInput != null) {
+                       def ucpeVmsServiceInformation = getNodeXml(xmlInput, "ucpe-vms-service-information").drop(38).trim()
+                       rebuildUcpeVmsServiceInformation = "<tns2:ucpe-vms-service-information>"
+                       // transport-service-information
+                       rebuildUcpeVmsServiceInformation += "<tns2:transport-service-information>"
+                       def transportServiceInformation = getNodeXml(ucpeVmsServiceInformation, "transport-service-information").drop(38).trim()
+                       def elementsTransportServiceInformationList = ["transport-service-type"]
+                       rebuildUcpeVmsServiceInformation += buildElements(transportServiceInformation, elementsTransportServiceInformationList, "")
+                       try { // optional
+                               def accessCircuitInfoList = ["access-circuit-id", "dual-mode"]
+                               rebuildUcpeVmsServiceInformation += buildElementsUnbounded(transportServiceInformation, accessCircuitInfoList, "access-circuit-info")
+                       } catch (Exception e) {
+                          log("ERROR", " Optional - Exception ACCESS-CIRCUIT-INFO - 'access-circuit-info' ")
+                       }
+                       rebuildUcpeVmsServiceInformation += "</tns2:transport-service-information>"
+                       // ucpe-information
+                       def elementsUcpeInformationList = ["ucpe-host-name", "ucpe-activation-code", "out-of-band-management-modem" ]
+                       rebuildUcpeVmsServiceInformation += buildElements(ucpeVmsServiceInformation, elementsUcpeInformationList, "ucpe-information")
+                       // vnf-list
+                       rebuildUcpeVmsServiceInformation += "<tns2:vnf-list>"
+                       def vnfListList = ["vnf-instance-id", "vnf-sequence-number", "vnf-type", "vnf-vendor", "vnf-model", "vnf-id", "prov-status", "operational-state", "orchestration-status", "equipment-role" ]
+                       rebuildUcpeVmsServiceInformation += buildElementsUnbounded(ucpeVmsServiceInformation, vnfListList, "vnf-information")
+                       rebuildUcpeVmsServiceInformation += "</tns2:vnf-list>"
+                       rebuildUcpeVmsServiceInformation += "</tns2:ucpe-vms-service-information>"
+               }
+               log("DEBUG", " rebuildUcpeVmsServiceInformation - " + rebuildUcpeVmsServiceInformation)
+               return rebuildUcpeVmsServiceInformation
+       }
+       
     // Build internet-service-change-details
        def buildInternetServiceChangeDetails(xmlInput) {
                def rebuildInternetServiceChangeDetails = ""
@@ -468,8 +522,12 @@ class MsoUtils {
                                rebuildInternetServiceChangeDetails = "<tns:internet-service-change-details>"
                                rebuildInternetServiceChangeDetails += buildElements(internetServiceChangeDetails, ["internet-evc-speed-value"], "")
                                rebuildInternetServiceChangeDetails += buildElements(internetServiceChangeDetails, ["internet-evc-speed-units"], "")
-                               def tProvidedV4LanPublicPrefixesChangesList = ["request-index", "v4-next-hop-address", "v4-lan-public-prefix", "v4-lan-public-prefix-length"]
-                               rebuildInternetServiceChangeDetails += buildElementsUnbounded(internetServiceChangeDetails, tProvidedV4LanPublicPrefixesChangesList, "t-provided-v4-lan-public-prefixes")
+                               try { // optional
+                                  def tProvidedV4LanPublicPrefixesChangesList = ["request-index", "v4-next-hop-address", "v4-lan-public-prefix", "v4-lan-public-prefix-length"]
+                                  rebuildInternetServiceChangeDetails += buildElementsUnbounded(internetServiceChangeDetails, tProvidedV4LanPublicPrefixesChangesList, "t-provided-v4-lan-public-prefixes")
+                               } catch (Exception e) {
+                                  log("ERROR"," Optional - Exception in INTERNET-SERVICE-CHANGE-DETAILS 't-provided-v4-lan-public-prefixes ")
+                           }
                                try { // optional
                                  def tProvidedV6LanPublicPrefixesChangesList = ["request-index", "v6-next-hop-address", "v6-lan-public-prefix", "v6-lan-public-prefix-length"]
                                  rebuildInternetServiceChangeDetails += buildElementsUnbounded(internetServiceChangeDetails, tProvidedV6LanPublicPrefixesChangesList, "t-provided-v6-lan-public-prefixes")
@@ -837,7 +895,7 @@ class MsoUtils {
                        def qualifiedHostName = System.getProperty("jboss.qualified.host.name")
                        if(qualifiedHostName!=null){
                                log("DEBUG", "qualifiedHostName:\n" + qualifiedHostName)
-                               callbackUrlToUse = callbackUrlToUse.replaceAll("(http://)(.*)(:8080*)", {orig, first, torepl, last -> "${first}${qualifiedHostName}${last}"})
+                               callbackUrlToUse = callbackUrlToUse.replaceAll("(http://)(.*)(:28080*)", {orig, first, torepl, last -> "${first}${qualifiedHostName}${last}"})
                        }
                }catch(Exception e){
                                log("DEBUG", "unable to grab qualified host name, using what's in urn properties for callbackurl. Exception was: " + e.printStackTrace())
@@ -860,5 +918,27 @@ class MsoUtils {
                }
                return text
         }
+        
+        /**
+         *
+         * Find the lowest unused module-index value in a given xml
+         */
+        public String getLowestUnusedIndex(String xml) {
+                if (xml == null || xml.isEmpty()) {
+                        return "0"
+                }               
+                def moduleIndexList = getMultNodes(xml, "module-index") 
+                if (moduleIndexList == null || moduleIndexList.size() == 0) {                  
+                        return "0"
+                }
+                def sortedModuleIndexList = moduleIndexList.sort { a, b -> a.compareTo b }
+               
+                for (i in 0..sortedModuleIndexList.size()-1) {
+                        if (Integer.parseInt(sortedModuleIndexList[i]) != i) {
+                                return i.toString()
+                        }
+                }
+                return sortedModuleIndexList.size().toString()
+        }
 
 }