[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / openecomp / mso / bpmn / common / scripts / VidUtils.groovy
  * ============LICENSE_END=========================================================
  */
 
-package com.att.bpm.scripts
-
-import org.json.JSONObject;
-import org.json.XML;
-
-import org.openecomp.mso.bpmn.core.xml.XmlTool;
+package org.openecomp.mso.bpmn.common.scripts
 
 import groovy.json.JsonBuilder
 import groovy.json.JsonSlurper
-import groovy.util.slurpersupport.GPathResult
-import groovy.xml.QName
+
+import org.json.JSONObject
+import org.json.XML
+import org.openecomp.mso.bpmn.core.xml.XmlTool
 
 class VidUtils {
        
@@ -83,9 +80,14 @@ class VidUtils {
                def asdcServiceModelVersion = ''
                
                def suppressRollback = requestMap.requestDetails.requestInfo.suppressRollback
-               def rollbackEnabled = true
-               if(suppressRollback != null && suppressRollback == true) {
-                       rollbackEnabled = false
+               
+               def backoutOnFailure = ""
+               if(suppressRollback != null){
+                       if ( suppressRollback == true) {
+                               backoutOnFailure = "false"
+                       } else if ( suppressRollback == false) {
+                               backoutOnFailure = "true"
+                       }
                }
                
                def volGrpName = requestMap.requestDetails.requestInfo?.instanceName ?: ''
@@ -108,6 +110,8 @@ class VidUtils {
                if(userParams != null) {
                        userParamsNode = buildUserParams(userParams)
                }
+               def modelCustomizationId = requestMap.requestDetails?.modelInfo?.modelCustomizationId ?: ''
+               
                def xmlReq = """
                <volume-request xmlns="http://www.w3.org/2001/XMLSchema">
                        <request-info>
@@ -124,7 +128,8 @@ class VidUtils {
                                <aic-cloud-region>${requestMap.requestDetails.cloudConfiguration.lcpCloudRegionId}</aic-cloud-region>
                                <tenant-id>${requestMap.requestDetails.cloudConfiguration.tenantId}</tenant-id>
                                <service-id>${serviceId}</service-id>
-                               <backout-on-failure>${rollbackEnabled}</backout-on-failure>
+                               <backout-on-failure>${backoutOnFailure}</backout-on-failure>
+                               <model-customization-id>${modelCustomizationId}</model-customization-id>
                        </volume-inputs>
                        <volume-params>
                                $userParamsNode
@@ -198,6 +203,7 @@ class VidUtils {
         * @param execution 
         * @param xmlRequestDetails - requestDetails in xml 
         * @return
+        * Note: See latest version: createXmlNetworkRequestInstance()
         */
        public String createXmlNetworkRequestInfra(execution, def networkJsonIncoming) {
        
@@ -214,7 +220,15 @@ class VidUtils {
                        def lcpCloudRegionId = reqMap.requestDetails.cloudConfiguration.lcpCloudRegionId
                        def tenantId = reqMap.requestDetails.cloudConfiguration.tenantId
                        def serviceId = reqMap.requestDetails.requestInfo.productFamilyId 
-                       def backoutOnFailure = reqMap.requestDetails.requestInfo.suppressRollback
+                       def suppressRollback = reqMap.requestDetails.requestInfo.suppressRollback.toString()
+                       def backoutOnFailure = ""
+                       if(suppressRollback != null){
+                               if (suppressRollback == true || suppressRollback == "true") {
+                                       backoutOnFailure = "false"
+                               } else if (suppressRollback == false || suppressRollback == "false") {
+                                       backoutOnFailure = "true"
+                               }
+                       }
                
                        //def userParams = reqMap.requestDetails.requestParameters.userParams
                        //def userParamsNode = buildUserParams(userParams)
@@ -223,7 +237,10 @@ class VidUtils {
                        if(userParams != null) {
                                userParamsNode = buildUserParams(userParams)
                        }
-               
+                       
+                       //'sdncVersion' = current, '1610' (non-RPC SDNC) or '1702' (RPC SDNC)
+                       def sdncVersion =  execution.getVariable("sdncVersion")
+                       
                        def xmlReq = """
                        <network-request xmlns="http://www.w3.org/2001/XMLSchema"> 
                         <request-info> 
@@ -240,6 +257,7 @@ class VidUtils {
                                <tenant-id>${tenantId}</tenant-id>
                                <service-id>${serviceId}</service-id> 
                                <backout-on-failure>${backoutOnFailure}</backout-on-failure>
+                <sdncVersion>${sdncVersion}</sdncVersion>
                         </network-inputs> 
                         <network-params>
                                ${userParamsNode}
@@ -254,6 +272,169 @@ class VidUtils {
                }
        }
        
+       /**
+        * Create a network-request XML using a map, 
+        * @param execution 
+        * @return
+        */
+       public String createXmlNetworkRequestInstance(execution) {
+
+               def networkModelVersionId = ""
+               def networkModelName = ""
+               def networkModelType = ""
+               def networkModelVersion = ""
+               def networkModelCustomizationId = ""
+               def networkModelInvariantId = ""
+               
+               // verify the DB Catalog response JSON structure
+               def networkModelInfo = execution.getVariable("networkModelInfo")
+               def jsonSlurper = new JsonSlurper()
+               if (networkModelInfo != null) {
+                       try {
+                               Map modelMap = jsonSlurper.parseText(networkModelInfo)
+                               if (modelMap != null) {
+                                       if (networkModelInfo.contains("modelVersionId")) {
+                                               networkModelVersionId = modelMap.modelVersionId !=null ? modelMap.modelVersionId : ""
+                                       }
+                                       if (networkModelInfo.contains("modelName")) {
+                                               networkModelName = modelMap.modelName !=null ? modelMap.modelName : ""
+                                       }
+                                       if (networkModelInfo.contains("modelType")) {
+                                               networkModelType = modelMap.modelType !=null ? modelMap.modelType : ""
+                                       }
+                                       if (networkModelInfo.contains("modelVersion")) {
+                                               networkModelVersion = modelMap.modelVersion !=null ? modelMap.modelVersion : ""
+                                       }
+                                       if (networkModelInfo.contains("modelCustomizationId")) {
+                                           networkModelCustomizationId = modelMap.modelCustomizationId !=null ? modelMap.modelCustomizationId : ""
+                                       }
+                                       if (networkModelInfo.contains("modelInvariantId")) {
+                                               networkModelInvariantId = modelMap.modelInvariantId !=null ? modelMap.modelInvariantId : ""
+                                       }
+                               }
+                       } catch (Exception ex) {
+                       throw ex
+                       }
+               }               
+               
+               def serviceModelVersionId = ""
+               def serviceModelName = ""
+               def serviceModelType = ""
+               def serviceModelVersion = ""
+               def serviceModelCustomizationId = ""
+               def serviceModelInvariantId = ""
+               
+               // verify the DB Catalog response JSON structure
+               def serviceModelInfo = execution.getVariable("serviceModelInfo")
+               def jsonServiceSlurper = new JsonSlurper()
+               if (serviceModelInfo != null) {
+                       try {
+                               Map modelMap = jsonServiceSlurper.parseText(serviceModelInfo)
+                               if (modelMap != null) {
+                                       if (serviceModelInfo.contains("modelVersionId")) {
+                                               serviceModelVersionId = modelMap.modelVersionId !=null ? modelMap.modelVersionId : ""
+                                       }
+                                       if (serviceModelInfo.contains("modelName")) {
+                                               serviceModelName = modelMap.modelName !=null ? modelMap.modelName : ""
+                                       }
+                                       if (serviceModelInfo.contains("modelType")) {
+                                               serviceModelType = modelMap.modelType !=null ? modelMap.modelType : ""
+                                       }
+                                       if (serviceModelInfo.contains("modelVersion")) {
+                                               serviceModelVersion = modelMap.modelVersion !=null ? modelMap.modelVersion : ""
+                                       }
+                                       if (serviceModelInfo.contains("modelCustomizationId")) {
+                                               serviceModelCustomizationId = modelMap.modelCustomizationId !=null ? modelMap.modelCustomizationId : ""
+                                       }
+                                       if (serviceModelInfo.contains("modelInvariantId")) {
+                                               serviceModelInvariantId = modelMap.modelInvariantId !=null ? modelMap.modelInvariantId : ""
+                                       }
+                               }
+                       } catch (Exception ex) {
+                               throw ex
+                       }
+               }
+               
+               
+               def subscriptionServiceType = execution.getVariable("subscriptionServiceType") != null ? execution.getVariable("subscriptionServiceType") : ""
+               def globalSubscriberId = execution.getVariable("globalSubscriberId") != null ? execution.getVariable("globalSubscriberId") : ""
+               def requestId = execution.getVariable("msoRequestId")
+               def serviceInstanceId = execution.getVariable("serviceInstanceId") != null ? execution.getVariable("serviceInstanceId") : ""
+               def networkId = (execution.getVariable("networkId")) != null ? execution.getVariable("networkId") : "" // optional
+               def networkName =  execution.getVariable("networkName") != null ? execution.getVariable("networkName") : "" // optional
+               def aicCloudReqion = execution.getVariable("lcpCloudRegionId") != null ? execution.getVariable("lcpCloudRegionId") : ""
+               def tenantId = execution.getVariable("tenantId") != null ? execution.getVariable("tenantId") : ""
+               def serviceId = execution.getVariable("productFamilyId") != null ? execution.getVariable("productFamilyId") : ""
+               def failIfExist = execution.getVariable("failIfExists") != null ? execution.getVariable("failIfExists") : ""
+               def suppressRollback = execution.getVariable("disableRollback")   
+               def backoutOnFailure = ""
+               if(suppressRollback != null){
+                       if (suppressRollback == true || suppressRollback == "true") {
+                               backoutOnFailure = "false"
+                       } else if (suppressRollback == false || suppressRollback == "'false") {
+                               backoutOnFailure = "true"
+                       }
+               }
+               
+               //'sdncVersion' = current, '1610' (non-RPC SDNC) or '1702' (RPC SDNC)
+               def sdncVersion =  execution.getVariable("sdncVersion")
+               
+               def source = "VID"
+               def action = execution.getVariable("action")
+                               
+               def userParamsNode = ""
+               def userParams = execution.getVariable("networkInputParams")
+               if(userParams != null) {
+                  userParamsNode = buildUserParams(userParams)
+               }
+               
+               def xmlReq = """
+               <network-request xmlns="http://www.w3.org/2001/XMLSchema"> 
+                <request-info> 
+            <request-id>${requestId}</request-id>
+                       <action>${action}</action> 
+                       <source>${source}</source> 
+                       <service-instance-id>${serviceInstanceId}</service-instance-id>
+                </request-info> 
+                <network-inputs> 
+                       <network-id>${networkId}</network-id> 
+                       <network-name>${networkName}</network-name> 
+                       <network-type>${networkModelType}</network-type>
+                       <subscription-service-type>${subscriptionServiceType}</subscription-service-type>
+            <global-customer-id>${globalSubscriberId}</global-customer-id>
+                       <aic-cloud-region>${aicCloudReqion}</aic-cloud-region> 
+                       <tenant-id>${tenantId}</tenant-id>
+                       <service-id>${serviceId}</service-id> 
+                       <backout-on-failure>${backoutOnFailure}</backout-on-failure>
+                       <failIfExist>${failIfExist}</failIfExist>
+            <networkModelInfo>
+              <modelName>${networkModelName}</modelName>
+              <modelUuid>${networkModelVersionId}</modelUuid>
+              <modelInvariantUuid>${networkModelInvariantId}</modelInvariantUuid>            
+              <modelVersion>${networkModelVersion}</modelVersion>
+              <modelCustomizationUuid>${networkModelCustomizationId}</modelCustomizationUuid>
+              <modelType>${networkModelType}</modelType>              
+                   </networkModelInfo>
+            <serviceModelInfo>
+              <modelName>${serviceModelName}</modelName>
+              <modelUuid>${serviceModelVersionId}</modelUuid>
+              <modelInvariantUuid>${serviceModelInvariantId}</modelInvariantUuid>            
+              <modelVersion>${serviceModelVersion}</modelVersion>
+              <modelCustomizationUuid>${serviceModelCustomizationId}</modelCustomizationUuid>
+              <modelType>${serviceModelType}</modelType>              
+                   </serviceModelInfo>                                                                                                 
+            <sdncVersion>${sdncVersion}</sdncVersion>                    
+                </network-inputs>
+                <network-params>
+                       ${userParamsNode}
+                </network-params> 
+               </network-request>
+               """
+               // return a pretty-print of the volume-request xml without the preamble
+               return groovy.xml.XmlUtil.serialize(xmlReq.normalize().replaceAll("\t", "").replaceAll("\n", "")).replaceAll("(<\\?[^<]*\\?>\\s*[\\r\\n]*)?", "")
+                       
+       }
+       
        /**
         * Create a vnf-request XML using a map
         * @param requestMap - map created from VID JSON 
@@ -306,13 +487,18 @@ class VidUtils {
                        isBaseVfModule = "true"         
                }
                
-               def requestId = execution.getVariable("att-mso-request-id")             
+               def requestId = execution.getVariable("mso-request-id")         
                def vfModuleName = requestMap.requestDetails?.requestInfo?.instanceName ?: ''
                def vfModuleModelName = requestMap.requestDetails?.modelInfo?.modelName ?: ''
                def suppressRollback = requestMap.requestDetails?.requestInfo?.suppressRollback
-               def backoutOnFailure = "true"
-               if(suppressRollback != null && suppressRollback == true) {
-                       backoutOnFailure = "false"
+               
+               def backoutOnFailure = ""
+               if(suppressRollback != null){
+                       if ( suppressRollback == true) {
+                               backoutOnFailure = "false"
+                       } else if ( suppressRollback == false) {
+                               backoutOnFailure = "true"
+                       }
                }
                
                def serviceId = requestMap.requestDetails?.requestParameters?.serviceId ?: ''
@@ -320,6 +506,7 @@ class VidUtils {
                def tenantId = requestMap.requestDetails?.cloudConfiguration?.tenantId ?: ''
                def personaModelId = requestMap.requestDetails?.modelInfo?.modelInvariantId ?: ''
                def personaModelVersion = requestMap.requestDetails?.modelInfo?.modelVersion ?: ''
+               def modelCustomizationId = requestMap.requestDetails?.modelInfo?.modelCustomizationId ?: ''
                
                def xmlReq = """
                <vnf-request>
@@ -339,6 +526,7 @@ class VidUtils {
                                <vf-module-id>${vfModuleId}</vf-module-id>
                                <vf-module-name>${vfModuleName}</vf-module-name>                                
                                <vf-module-model-name>${vfModuleModelName}</vf-module-model-name>
+                               <model-customization-id>${modelCustomizationId}</model-customization-id>
                                <is-base-vf-module>${isBaseVfModule}</is-base-vf-module>
                                <asdc-service-model-version>${asdcServiceModelInfo}</asdc-service-model-version>
                                <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>