[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / openecomp / mso / bpmn / common / scripts / UpdateAAIVfModule.groovy
  * ============LICENSE_END=========================================================
  */
 
-package com.att.bpm.scripts
-
-import groovy.util.Node
-import groovy.util.XmlParser;
-import groovy.xml.QName
-
-import java.io.Serializable;
+package org.openecomp.mso.bpmn.common.scripts
 
 import org.camunda.bpm.engine.delegate.BpmnError
 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 UpdateAAIVfModule extends AbstractServiceTaskProcessor {
@@ -74,6 +64,7 @@ public class UpdateAAIVfModule extends AbstractServiceTaskProcessor {
                try {
                        def xml = execution.getVariable('UpdateAAIVfModuleRequest')
                        logDebug('Received request xml:\n' + xml, isDebugLogEnabled)
+                       utils.logAudit("UpdateAAIVfModule Request XML: " + xml)
                        initProcessVariables(execution)
 
                        def vnfId = getRequiredNodeText(execution, xml,'vnf-id')
@@ -114,29 +105,17 @@ public class UpdateAAIVfModule extends AbstractServiceTaskProcessor {
                        logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
                        String endPoint = execution.getVariable('URN_aai_endpoint') + aai_uri + '/' + UriUtils.encode(vnfId, "UTF-8") + '/vf-modules/vf-module/' + UriUtils.encode(vfModuleId, "UTF-8")
 
-                       String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
-
                        try {
-                               RESTConfig config = new RESTConfig(endPoint);
-                               def responseData = ''
-                               def aaiRequestId = UUID.randomUUID().toString()
-                               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)
-                               }
-
                                logDebug('sending GET to AAI endpoint \'' + endPoint + '\'', isDebugLogEnabled)
-                               APIResponse response = client.httpGet()
+                               utils.logAudit("UpdateAAIVfModule sending GET to AAI endpoint: " + endPoint)
 
-                               responseData = response.getResponseBodyAsString()
+                               APIResponse response = aaiUriUtil.executeAAIGetCall(execution, endPoint)
+                               def responseData = response.getResponseBodyAsString()
                                execution.setVariable('UAAIVfMod_getVfModuleResponseCode', response.getStatusCode())
                                execution.setVariable('UAAIVfMod_getVfModuleResponse', responseData)
                                logDebug('Response code:' + response.getStatusCode(), isDebugLogEnabled)
                                logDebug('Response:' + System.lineSeparator() + responseData, isDebugLogEnabled)
+                               utils.logAudit("UpdateAAIVfModule response data: " + responseData)
                        } catch (Exception ex) {
                                ex.printStackTrace()
                                logDebug('Exception occurred while executing AAI GET:' + ex.getMessage(),isDebugLogEnabled)
@@ -171,6 +150,7 @@ public class UpdateAAIVfModule extends AbstractServiceTaskProcessor {
                        def origRequest = execution.getVariable('UpdateAAIVfModuleRequest')
                        def Node vfModuleNode = xmlParser.parseText(vfModule)
                        
+                       utils.logAudit("UpdateAAIVfModule request: " + origRequest)
                        // Confirm resource-version is in retrieved VF Module
                        if (utils.getChildNode(vfModuleNode, 'resource-version') == null) {
                                def msg = 'Can\'t update VF Module ' + vfModuleId + ' since \'resource-version\' is missing'
@@ -221,27 +201,15 @@ public class UpdateAAIVfModule extends AbstractServiceTaskProcessor {
                        logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
                        String endPoint = execution.getVariable('URN_aai_endpoint') + aai_uri + '/' + UriUtils.encode(vnfId, "UTF-8") + '/vf-modules/vf-module/' + UriUtils.encode(vfModuleId, "UTF-8")
 
-                       String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
-
                        try {
-                               RESTConfig config = new RESTConfig(endPoint);
-                               def responseData = ''
-                               def aaiRequestId = UUID.randomUUID().toString()
-                               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)
-                               }
-
                                logDebug('sending PUT to AAI endpoint \'' + endPoint + '\'' + 'with payload \n' + payload, isDebugLogEnabled)
-                               APIResponse response = client.httpPut(payload)
-
-                               responseData = response.getResponseBodyAsString()
+                               utils.logAudit("Sending PUT to AAI endpoint: " + endPoint)
+                               
+                               APIResponse response = aaiUriUtil.executeAAIPutCall(execution, endPoint, payload)
+                               def responseData = response.getResponseBodyAsString()
                                execution.setVariable('UAAIVfMod_updateVfModuleResponseCode', response.getStatusCode())
                                execution.setVariable('UAAIVfMod_updateVfModuleResponse', responseData)
+                               utils.logAudit("UpdateAAIVfModule Response data: " + responseData)
                                logDebug('Response code:' + response.getStatusCode(), isDebugLogEnabled)
                                logDebug('Response:' + System.lineSeparator() + responseData, isDebugLogEnabled)
                        } catch (Exception ex) {
@@ -387,7 +355,7 @@ public class UpdateAAIVfModule extends AbstractServiceTaskProcessor {
                WorkflowException exception = new WorkflowException(processKey, 5000,
                        execution.getVariable('UAAIVfMod_getVfModuleResponse'))
                execution.setVariable('WorkflowException', exception)
-
+               utils.logAudit("UpdateAAIVfModule query failure: " + exception.getErrorMessage())
                logDebug('Exited ' + method, isDebugLogEnabled)
        }
 
@@ -411,6 +379,7 @@ public class UpdateAAIVfModule extends AbstractServiceTaskProcessor {
                        execution.getVariable('UAAIVfMod_updateVfModuleResponse'))
                execution.setVariable('WorkflowException', exception)
 
+               utils.logAudit("UpdateAAIVfModule failure: " + exception.getErrorMessage())
                logDebug('Exited ' + method, isDebugLogEnabled)
        }
 }