[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / openecomp / mso / bpmn / common / scripts / CreateAAIVfModule.groovy
  * ============LICENSE_END=========================================================
  */
 
-package com.att.bpm.scripts
-import java.io.Serializable;
-
+package org.openecomp.mso.bpmn.common.scripts
 import org.camunda.bpm.engine.runtime.Execution
-import org.springframework.web.util.UriUtils
-
-import org.openecomp.mso.rest.APIResponse
-import org.openecomp.mso.rest.RESTClient
-import org.openecomp.mso.rest.RESTConfig
 import org.openecomp.mso.bpmn.core.RollbackData
 import org.openecomp.mso.bpmn.core.WorkflowException
+import org.openecomp.mso.rest.APIResponse
+import org.springframework.web.util.UriUtils
 
 
 public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
@@ -43,6 +38,7 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
                execution.setVariable("CAAIVfMod_serviceId",null)
                execution.setVariable("CAAIVfMod_personaId",null)
                execution.setVariable("CAAIVfMod_personaVer",null)
+               execution.setVariable("CAAIVfMod_modelCustomizationId",null)
                execution.setVariable("CAAIVfMod_vnfPersonaId",null)
                execution.setVariable("CAAIVfMod_vnfPersonaVer",null)
                execution.setVariable("CAAIVfMod_isBaseVfModule", false)
@@ -80,64 +76,75 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
        // and VF Module data in the flow Execution
        public void preProcessRequest(Execution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               def xml = execution.getVariable("CreateAAIVfModuleRequest")
-               utils.log("DEBUG", "input request xml:" + xml, isDebugEnabled)
                initProcessVariables(execution)
 
-               def vnfId = ""
-               if (utils.nodeExists(xml, "vnf-id")) {
-                       vnfId = utils.getNodeText(xml,"vnf-id")
-               }
-               if (vnfId.isEmpty()) {
+               def vnfId = execution.getVariable("vnfId")              
+               if (vnfId == null || vnfId.isEmpty()) {
                        execution.setVariable("CAAIVfMod_newGenericVnf", true)
+                       execution.setVariable("CAAIVfMod_vnfId","")
                }
-               execution.setVariable("CAAIVfMod_vnfId",vnfId)
-
-               def vnfName = ""
-               if (utils.nodeExists(xml, "vnf-name")) {
-                       vnfName = utils.getNodeText(xml,"vnf-name")
+               else {
+                       execution.setVariable("CAAIVfMod_vnfId",vnfId)
                }
+
+               def vnfName = execution.getVariable("vnfName")          
                execution.setVariable("CAAIVfMod_vnfName", vnfName)
 
-               if (utils.nodeExists(xml, "vnf-type")) {
-                       execution.setVariable("CAAIVfMod_vnfType",utils.getNodeText(xml,"vnf-type"))
+               String vnfType = execution.getVariable("vnfType")
+               if (vnfType != null && !vnfType.isEmpty()) {
+                       execution.setVariable("CAAIVfMod_vnfType", vnfType)
                } else {
                        execution.setVariable("CAAIVfMod_vnfType","")
                }
 
-               execution.setVariable("CAAIVfMod_serviceId",utils.getNodeText(xml,"service-id"))
+               execution.setVariable("CAAIVfMod_serviceId", execution.getVariable("serviceId"))
+               
+               String personaModelId = execution.getVariable("personaModelId")
 
-               if (utils.nodeExists(xml, "persona-model-id")) {
-                       execution.setVariable("CAAIVfMod_personaId",utils.getNodeText(xml,"persona-model-id"))
+               if (personaModelId != null && !personaModelId.isEmpty()) {
+                       execution.setVariable("CAAIVfMod_personaId",personaModelId)
                } else {
                        execution.setVariable("CAAIVfMod_personaId","")
                }
+               
+               String personaModelVersion = execution.getVariable("personaModelVersion")
 
-               if (utils.nodeExists(xml, "persona-model-version")) {
-                       execution.setVariable("CAAIVfMod_personaVer",utils.getNodeText(xml,"persona-model-version"))
+               if (personaModelVersion != null && !personaModelVersion.isEmpty()) {
+                       execution.setVariable("CAAIVfMod_personaVer", personaModelVersion)
                } else {
                        execution.setVariable("CAAIVfMod_personaVer","")
                }
                
-               if (utils.nodeExists(xml, "vnf-persona-model-id")) {
-                       execution.setVariable("CAAIVfMod_vnfPersonaId",utils.getNodeText(xml,"vnf-persona-model-id"))
+               
+               String modelCustomizationId = execution.getVariable("modelCustomizationId")
+
+               if (modelCustomizationId != null && !modelCustomizationId.isEmpty()) {
+                       execution.setVariable("CAAIVfMod_modelCustomizationId",modelCustomizationId)
+               } else {
+                       execution.setVariable("CAAIVfMod_modelCustomizationId","")
+               }
+               
+               String vnfPersonaModelId = execution.getVariable("vnfPersonaModelId")
+               
+               if (vnfPersonaModelId != null && !vnfPersonaModelId.isEmpty()) {
+                       execution.setVariable("CAAIVfMod_vnfPersonaId",vnfPersonaModelId)
                } else {
                        execution.setVariable("CAAIVfMod_vnfPersonaId","")
                }
+               
+               String vnfPersonaModelVersion = execution.getVariable("vnfPersonaModelVersion")
 
-               if (utils.nodeExists(xml, "vnf-persona-model-version")) {
-                       execution.setVariable("CAAIVfMod_vnfPersonaVer",utils.getNodeText(xml,"vnf-persona-model-version"))
+               if (vnfPersonaModelVersion != null && !vnfPersonaModelVersion.isEmpty()) {
+                       execution.setVariable("CAAIVfMod_vnfPersonaVer",vnfPersonaModelVersion)
                } else {
                        execution.setVariable("CAAIVfMod_vnfPersonaVer","")
                }
                
                //isBaseVfModule
                Boolean isBaseVfModule = false
-               if (utils.nodeExists(xml, "is-base-vf-module")) {
-                       String isBaseVfModuleString = utils.getNodeText(xml, "is-base-vf-module")
-                       if (isBaseVfModuleString.equals("true")) {
-                               isBaseVfModule = true
-                       }
+               String isBaseVfModuleString = execution.getVariable("isBaseVfModule")
+               if (isBaseVfModuleString != null && isBaseVfModuleString.equals("true")) {
+                               isBaseVfModule = true                   
                }
                execution.setVariable("CAAIVfMod_isBaseVfModule", isBaseVfModule)
                
@@ -146,8 +153,8 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
                        logDebug("VID Request received", isDebugEnabled)                
                }
 
-               execution.setVariable("CAAIVfMod_moduleName",utils.getNodeText(xml,"vf-module-name"))
-               execution.setVariable("CAAIVfMod_moduleModelName",utils.getNodeText(xml,"vf-module-model-name"))
+               execution.setVariable("CAAIVfMod_moduleName",execution.getVariable("vfModuleName"))
+               execution.setVariable("CAAIVfMod_moduleModelName",execution.getVariable("vfModuleModelName"))
 
                AaiUtil aaiUriUtil = new AaiUtil(this)
                def aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
@@ -155,20 +162,19 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
                String aaiNamespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
                logDebug('AAI namespace is: ' + aaiNamespace, isDebugEnabled)
                
-               execution.setVariable("CAAIVfMod_aaiNamespace","${aaiNamespace}")
-               
+               execution.setVariable("CAAIVfMod_aaiNamespace","${aaiNamespace}")               
        
-               if (vnfId.isEmpty()) {
+               if (vnfId == null || vnfId.isEmpty()) {
                        // TBD - assert that the vnfName is not empty
                        execution.setVariable("CAAIVfMod_genericVnfGetEndpoint",
                                "${aai_uri}/?vnf-name=" +
-                                       UriUtils.encode(vnfName,"UTF-8"))
+                                       UriUtils.encode(vnfName,"UTF-8") + "&depth=1")
                } else {
                        execution.setVariable("CAAIVfMod_genericVnfGetEndpoint",
-                               "${aai_uri}/" + UriUtils.encode(vnfId,"UTF-8"))
+                               "${aai_uri}/" + UriUtils.encode(vnfId,"UTF-8") + "?depth=1")
                }
 
-               
+               utils.logAudit("CreateAAIVfModule VNF PUT Endpoint:   ${aai_uri}/")
                execution.setVariable("CAAIVfMod_genericVnfPutEndpoint","${aai_uri}/")
        }
        
@@ -177,27 +183,22 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
        public void queryAAIForGenericVnf(Execution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
                def endPoint = execution.getVariable("URN_aai_endpoint") + execution.getVariable("CAAIVfMod_genericVnfGetEndpoint")
-               def aaiRequestId = UUID.randomUUID().toString()
-
-               RESTConfig config = new RESTConfig(endPoint);
-               utils.log("DEBUG","queryAAIForGenericVnf() endpoint-" + endPoint, isDebugEnabled)
-               def responseData = ""
-
-               String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
 
                try {
-                       RESTClient client = new RESTClient(config).addHeader("X-TransactionId", aaiRequestId).addHeader("X-FromAppId", "MSO").addHeader("Content-Type", "application/xml").
-                               addHeader("Accept","application/xml");
-                       if (basicAuthCred != null && !"".equals(basicAuthCred)) {
-                               client.addAuthorizationHeader(basicAuthCred)
-                       }
+                       utils.log("DEBUG","queryAAIForGenericVnf() endpoint-" + endPoint, isDebugEnabled)
                        utils.log("DEBUG", "invoking GET call to AAI endpoint :"+System.lineSeparator()+endPoint,isDebugEnabled)
-                       APIResponse response = client.httpGet()
-                               
-                       responseData = response.getResponseBodyAsString()
-                       execution.setVariable("CAAIVfMod_queryGenericVnfResponseCode", response.getStatusCode())
+                       utils.logAudit("CreateAAIVfModule sending GET call to AAI Endpoint: " + endPoint)
+
+                       AaiUtil aaiUtil = new AaiUtil(this)
+                       APIResponse response = aaiUtil.executeAAIGetCall(execution, endPoint)
+                       def responseData = response.getResponseBodyAsString()
+                       def statusCode = response.getStatusCode()
+                       execution.setVariable("CAAIVfMod_queryGenericVnfResponseCode", statusCode)
                        execution.setVariable("CAAIVfMod_queryGenericVnfResponse", responseData)
-                       utils.log("DEBUG", "Response code:" + response.getStatusCode(), isDebugEnabled)
+
+                       utils.logAudit("CreateAAIVfModule Response Code: " + statusCode)
+                       utils.logAudit("CreateAAIVfModule Response data: " + responseData)
+                       utils.log("DEBUG", "Response code:" + statusCode, isDebugEnabled)
                        utils.log("DEBUG", "Response:" + System.lineSeparator()+responseData,isDebugEnabled)
                } catch (Exception ex) {
                        ex.printStackTrace()
@@ -238,16 +239,13 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
        // note: to get here, the vnf-id in the original CREATE_VF_MODULE request was absent or ""
        public void createGenericVnf(Execution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               def aaiRequestId = UUID.randomUUID().toString()
                // TBD - is this how we want to generate the Id for the new Generic VNF?
                def newVnfId = UUID.randomUUID().toString()
                def endPoint = execution.getVariable("URN_aai_endpoint") +
                        execution.getVariable("CAAIVfMod_genericVnfPutEndpoint") + newVnfId
                // update the flow execution with the new Vnf Id
                execution.setVariable("CAAIVfMod_vnfId",newVnfId)
-
-               String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
-
+               
        //      AaiUriUtil aaiUriUtil = new AaiUriUtil(this)
        //      def aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
        //      logDebug('AAI URI is: ' + aai_uri, isDebugEnabled)
@@ -266,22 +264,21 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
                                                        </generic-vnf>""" as String
                execution.setVariable("CAAIVfMod_createGenericVnfPayload", payload)
 
-               RESTConfig config = new RESTConfig(endPoint);
-               utils.log("DEBUG","createGenericVnf() endpoint-" + endPoint, isDebugEnabled)
-               def responseData = ""
                try {
-                       RESTClient client = new RESTClient(config).addHeader("X-TransactionId", aaiRequestId).addHeader("X-FromAppId", "MSO").addHeader("Content-Type", "application/xml").
-                               addHeader("Accept","application/xml");
-                       if (basicAuthCred != null && !"".equals(basicAuthCred)) {
-                               client.addAuthorizationHeader(basicAuthCred)
-                       }
+                       utils.log("DEBUG","createGenericVnf() endpoint-" + endPoint, isDebugEnabled)
                        utils.log("DEBUG", "invoking PUT call to AAI with payload:"+System.lineSeparator()+payload,isDebugEnabled)
-                       APIResponse response = client.httpPut(payload)
-                               
-                       responseData = response.getResponseBodyAsString()
-                       execution.setVariable("CAAIVfMod_createGenericVnfResponseCode", response.getStatusCode())
+                       utils.logAudit("Sending PUT call to AAI with Endpoint /n" + endPoint + " with payload /n" + payload)
+
+                       AaiUtil aaiUtil = new AaiUtil(this);
+                       APIResponse response = aaiUtil.executeAAIPutCall(execution, endPoint, payload);
+                       def     responseData = response.getResponseBodyAsString()
+                       def responseStatusCode = response.getStatusCode()
+                       execution.setVariable("CAAIVfMod_createGenericVnfResponseCode", responseStatusCode)
                        execution.setVariable("CAAIVfMod_createGenericVnfResponse", responseData)
-                       utils.log("DEBUG", "Response code:" + response.getStatusCode(), isDebugEnabled)
+                       
+                       utils.logAudit("Response Code: " + responseStatusCode)
+                       utils.logAudit("Response Data: " + responseData)
+                       utils.log("DEBUG", "Response code:" + responseStatusCode, isDebugEnabled)
                        utils.log("DEBUG", "Response:" + System.lineSeparator()+responseData,isDebugEnabled)
                } catch (Exception ex) {
                        ex.printStackTrace()
@@ -305,9 +302,6 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
                // need to append the existing Vnf Id or the one generated in createGenericVnf() to the url
                endPoint = endPoint + UriUtils.encode(execution.getVariable("CAAIVfMod_vnfId"), "UTF-8") +
                        "/vf-modules/vf-module/" + newModuleId;
-               def aaiRequestId = UUID.randomUUID().toString()
-
-               String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
 
                // if we get to this point, we may be about to create the Vf Module,
                // add rollback information about the Generic VNF for this base/add-on module
@@ -325,32 +319,31 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
                                                                <vf-module-name>${execution.getVariable("CAAIVfMod_moduleName")}</vf-module-name>
                                                                <persona-model-id>${execution.getVariable("CAAIVfMod_personaId")}</persona-model-id>
                                                                <persona-model-version>${execution.getVariable("CAAIVfMod_personaVer")}</persona-model-version>
+                                                               <persona-model-customization-id>${execution.getVariable("CAAIVfMod_modelCustomizationId")}</persona-model-customization-id>
                                                                <is-base-vf-module>${isBaseModule}</is-base-vf-module>
                                                                <orchestration-status>pending-create</orchestration-status>
                                                                </vf-module>""" as String
                execution.setVariable("CAAIVfMod_createVfModulePayload", payload)
 
-               RESTConfig config = new RESTConfig(endPoint);
-               utils.log("DEBUG","createVfModule() endpoint-" + endPoint, isDebugEnabled)
-               def responseData = ""
                try {
-                       RESTClient client = new RESTClient(config).addHeader("X-TransactionId", aaiRequestId).addHeader("X-FromAppId", "MSO").addHeader("Content-Type", "application/xml").
-                               addHeader("Accept","application/xml");
-                       if (basicAuthCred != null && !"".equals(basicAuthCred)) {
-                               client.addAuthorizationHeader(basicAuthCred)
-                       }
+                       utils.log("DEBUG","createVfModule() endpoint-" + endPoint, isDebugEnabled)
                        utils.log("DEBUG", "invoking PUT call to AAI with payload:"+System.lineSeparator()+payload,isDebugEnabled)
-                       APIResponse response = client.httpPut(payload)
-                               
-                       responseData = response.getResponseBodyAsString()
-                       execution.setVariable("CAAIVfMod_createVfModuleResponseCode", response.getStatusCode())
+                       utils.logAudit("CreateAAIVfModule sending PUT call to AAI with endpoint /n" + endPoint + " with payload /n " + payload)
+
+                       AaiUtil aaiUtil = new AaiUtil(this)
+                       APIResponse response = aaiUtil.executeAAIPutCall(execution, endPoint, payload)  
+                       def responseData = response.getResponseBodyAsString()
+                       def statusCode = response.getStatusCode()
+                       execution.setVariable("CAAIVfMod_createVfModuleResponseCode", statusCode)
                        execution.setVariable("CAAIVfMod_createVfModuleResponse", responseData)
-                       utils.log("DEBUG", "Response code:" + response.getStatusCode(), isDebugEnabled)
+                       
+                       utils.log("DEBUG", "Response code:" + statusCode, isDebugEnabled)
                        utils.log("DEBUG", "Response:" + System.lineSeparator()+responseData,isDebugEnabled)
-
+                       utils.logAudit("Response Code: " + statusCode)
+                       utils.logAudit("Response data: " + responseData)
                        // the base or add-on VF Module was successfully created,
                        // add the module name to the rollback data and the response
-                       if (isOneOf(response.getStatusCode(), 200, 201)) {
+                       if (isOneOf(statusCode, 200, 201)) {
                                rollbackData.put("VFMODULE", "vfModuleId", newModuleId)
                                rollbackData.put("VFMODULE", "vfModuleName", execution.getVariable("CAAIVfMod_moduleName"))
                                execution.setVariable("RollbackData", rollbackData)
@@ -377,6 +370,7 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
                                
                                execution.setVariable("CreateAAIVfModuleResponse", responseOut)
                                utils.log("DEBUG", "CreateAAIVfModuleResponse:" + System.lineSeparator()+responseOut,isDebugEnabled)
+                               utils.logAudit("CreateAAIVfModule Response /n " + responseOut)
                        }
                } catch (Exception ex) {
                        ex.printStackTrace()
@@ -544,6 +538,7 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
                String processKey = getProcessKey(execution);
                WorkflowException exception = new WorkflowException(processKey, errorCode, errorResponse)
                execution.setVariable("WorkflowException", exception)
+               utils.logAudit("Workflow exception occurred in CreateAAIVfModule: " + errorResponse)
        }
 
        /**
@@ -566,6 +561,7 @@ public class CreateAAIVfModule extends AbstractServiceTaskProcessor{
                        AaiUtil aaiUriUtil = new AaiUtil(this)
                        def aai_uri = aaiUriUtil.getNetworkGenericVnfUri(execution)
                        logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
+                       utils.logAudit("CreateAAIVfModule rollback AAI URI: " + aai_uri)
                        
                        if (rollbackData != null) {
                                if (rollbackData.hasType("VFMODULE")) {