Merge "Reorder modifiers"
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / openecomp / mso / bpmn / common / scripts / SDNCAdapterUtils.groovy
index 437d592..7aa7b20 100644 (file)
@@ -22,9 +22,10 @@ package org.openecomp.mso.bpmn.common.scripts;
 \r
 import org.apache.commons.lang3.*\r
 import org.camunda.bpm.engine.delegate.BpmnError\r
-import org.camunda.bpm.engine.runtime.Execution\r
+import org.camunda.bpm.engine.delegate.DelegateExecution\r
+\r
 import org.openecomp.mso.bpmn.core.WorkflowException\r
-import org.openecomp.mso.bpmn.core.json.JsonUtils\r
+import org.openecomp.mso.bpmn.core.json.JsonUtils;\r
 import org.springframework.web.util.UriUtils\r
 \r
 \r
@@ -43,7 +44,8 @@ class SDNCAdapterUtils {
                this.taskProcessor = taskProcessor\r
        }\r
 \r
-       String SDNCAdapterFeatureRequest(Execution execution, String requestName, String action, String callbackURL, String serviceOperation, String timeoutValueInMinutes) {\r
+       String SDNCAdapterFeatureRequest(DelegateExecution execution, String requestName, String action, String callbackURL, String serviceOperation, String timeoutValueInMinutes) {\r
+\r
                def utils=new MsoUtils()\r
 \r
                def prefix = execution.getVariable('prefix')\r
@@ -88,7 +90,8 @@ class SDNCAdapterUtils {
                return sdncAdapterFeatureRequest\r
        }\r
 \r
-       String SDNCAdapterActivateVnfRequest(Execution execution, String action, String callbackURL, String serviceOperation, String msoAction, String timeoutValueInMinutes) {\r
+       String SDNCAdapterActivateVnfRequest(DelegateExecution execution, String action, String callbackURL, String serviceOperation, String msoAction, String timeoutValueInMinutes) {\r
+\r
                def utils=new MsoUtils()\r
 \r
                def prefix = execution.getVariable('prefix')\r
@@ -131,7 +134,8 @@ class SDNCAdapterUtils {
                return sdncAdapterActivateVnfRequest\r
        }\r
 \r
-       String SDNCAdapterL3ToHigherLayerRequest(Execution execution, String action, String callbackURL, String serviceOperation, String timeoutValueInMinutes) {\r
+       String SDNCAdapterL3ToHigherLayerRequest(DelegateExecution execution, String action, String callbackURL, String serviceOperation, String timeoutValueInMinutes) {\r
+\r
                def utils=new MsoUtils()\r
 \r
                def prefix = execution.getVariable('prefix')\r
@@ -230,7 +234,8 @@ class SDNCAdapterUtils {
 \r
 \r
 \r
-       private void SDNCAdapterActivateRequest(Execution execution, String resultVar, String svcAction,\r
+       private void SDNCAdapterActivateRequest(DelegateExecution execution, String resultVar, String svcAction,\r
+\r
                        String svcOperation, String additionalData) {\r
                        def utils=new MsoUtils()\r
 \r
@@ -273,6 +278,15 @@ class SDNCAdapterUtils {
                                additionalData = ""\r
                        }\r
 \r
+                       boolean isAic3 = execution.getVariable("isAic3")\r
+                       \r
+                       if(isAic3) {\r
+                               nnsl2HomingInformation = updateHomingInfo(nnsl2HomingInformation, "AIC3.0")\r
+                       }\r
+                       else {\r
+                               nnsl2HomingInformation = updateHomingInfo(nnsl2HomingInformation, "AIC2.X")\r
+                       }\r
+                                                                       \r
                        String content = """\r
                                <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1"\r
                                                xmlns:sdncadapter="http://domain2.openecomp.com/workflow/sdnc/adapter/schema/v1">\r
@@ -301,14 +315,28 @@ class SDNCAdapterUtils {
                        execution.setVariable(resultVar, content)\r
        }\r
 \r
+       /**\r
+        * Builds an SDNC "reserve" request and stores it in the specified execution\r
+        * variable. \r
+        * @param execution the execution\r
+        * @param action the type of action: reserve, turnup, etc\r
+        * @param resultVar the execution variable in which the result will be stored\r
+        */\r
+       public void sdncReservePrep(DelegateExecution execution, String action, String resultVar) {\r
+               sdncReservePrep(execution, action, resultVar, false)\r
+       }\r
+\r
        /**\r
         * Builds an SDNC "reserve" request and stores it in the specified execution\r
         * variable.\r
         * @param execution the execution\r
+        * @param action the type of action: reserve, turnup, etc\r
         * @param resultVar the execution variable in which the result will be stored\r
+        * @param isAic3 boolean to indicate whether request is for AIC3.0\r
         */\r
-       public void sdncReservePrep(Execution execution, String action, String resultVar) {\r
-               sdncPrep(execution, resultVar, action , 'service-configuration-operation', null, this.taskProcessor)\r
+       public void sdncReservePrep(DelegateExecution execution, String action, String resultVar, boolean isAic3) {\r
+\r
+               sdncPrep(execution, resultVar, action , 'service-configuration-operation', null, isAic3, this.taskProcessor)\r
        }\r
 \r
        /**\r
@@ -320,8 +348,23 @@ class SDNCAdapterUtils {
         * @param additionalData additional XML content to be inserted into the\r
         *        RequestData element (may be null)\r
         */\r
-       public void sdncPrep(Execution execution, String resultVar, String svcAction,\r
-                       String svcOperation, String additionalData, AbstractServiceTaskProcessor taskProcessor) {\r
+       public void sdncPrep(DelegateExecution execution, String resultVar, String svcAction,\r
+               String svcOperation, String additionalData, AbstractServiceTaskProcessor taskProcessor) {\r
+               sdncPrep(execution, resultVar, svcAction, svcOperation, additionalData, false, taskProcessor)\r
+       }\r
+\r
+       /**\r
+        * Builds a basic SDNC request and stores it in the specified execution variable.\r
+        * @param execution the execution\r
+        * @param resultVar the execution variable in which the result will be stored\r
+        * @param svcAction the svcAction element value\r
+        * @param svcOperation the svcOperation element value\r
+        * @param additionalData additional XML content to be inserted into the RequestData element (may be null)\r
+        * @param isAic3 boolean to indicate whether request is for AIC3.0\r
+        */\r
+       public void sdncPrep(DelegateExecution execution, String resultVar, String svcAction,\r
+\r
+                       String svcOperation, String additionalData, boolean isAic3, AbstractServiceTaskProcessor taskProcessor) {\r
                def method = getClass().getSimpleName() + '.sdncPrep(' +\r
                        'execution=' + execution.getId() +\r
                        ', resultVar=' + resultVar +\r
@@ -382,6 +425,14 @@ class SDNCAdapterUtils {
                        if (additionalData == null) {\r
                                additionalData = ""\r
                        }\r
+                       \r
+                       if(isAic3) {\r
+                               nnsl2HomingInformation = updateHomingInfo(nnsl2HomingInformation, "AIC3.0")\r
+                       }\r
+                       else {\r
+                               nnsl2HomingInformation = updateHomingInfo(nnsl2HomingInformation, "AIC2.X")\r
+                       }\r
+\r
 \r
                        String content = """\r
                                <sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:sdncadapterworkflow="http://openecomp.com/mso/workflow/schema/v1"\r
@@ -420,7 +471,17 @@ class SDNCAdapterUtils {
                        exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error")\r
                }\r
        }\r
-\r
+       \r
+       public String updateHomingInfo(String homingInfo, String aicVersion) {\r
+               String newHomingInfo\r
+               if(homingInfo == null || homingInfo.trim().length() == 0) {\r
+                       newHomingInfo = "<l2-homing-information><aic-version>" + aicVersion + "</aic-version></l2-homing-information>"\r
+               }\r
+               else {\r
+                       newHomingInfo = homingInfo.substring(0, homingInfo.indexOf("</l2-homing-information>")) + "<aic-version>" + aicVersion + "</aic-version></l2-homing-information>"\r
+               }\r
+       }\r
+       \r
        /**\r
         * Builds a topology SDNC request and return String request.\r
         * As V2 will use 1607-style request, region instead of aic clli code\r
@@ -435,7 +496,8 @@ class SDNCAdapterUtils {
         * @param additionalData additional XML content to be inserted into the\r
         *   RequestData element (may be null)\r
         */\r
-        public String sdncTopologyRequestV2 (Execution execution, String requestXML, String serviceInstanceId, String callbackUrl, String action, String requestAction, String cloudRegionId, networkId, String queryAAIResponse, String additionalData) {\r
+        public String sdncTopologyRequestV2 (DelegateExecution execution, String requestXML, String serviceInstanceId, String callbackUrl, String action, String requestAction, String cloudRegionId, networkId, String queryAAIResponse, String additionalData) {\r
+\r
                 def utils=new MsoUtils()\r
 \r
                 // SNDC is expecting request Id for header as unique each call.\r
@@ -553,7 +615,8 @@ class SDNCAdapterUtils {
          * @param additionalData additional XML content to be inserted into the\r
          *   RequestData element (may be null)\r
          */\r
-         public String sdncTopologyRequestRsrc (Execution execution, String requestXML, String serviceInstanceId, String callbackUrl, String action, String requestAction, String cloudRegionId, networkId, String additionalData) {\r
+         public String sdncTopologyRequestRsrc (DelegateExecution execution, String requestXML, String serviceInstanceId, String callbackUrl, String action, String requestAction, String cloudRegionId, networkId, String additionalData) {\r
+\r
                  def utils=new MsoUtils()\r
 \r
                  // SNDC is expecting request Id for header as unique each call.\r
@@ -715,7 +778,8 @@ class SDNCAdapterUtils {
                         * @param responseVar the execution variable in which the response is stored\r
                         * @param workflowException the WorkflowException Object returned from sdnc call\r
                         */\r
-       public void validateSDNCResponse(Execution execution, String response, WorkflowException workflowException, boolean successIndicator){\r
+       public void validateSDNCResponse(DelegateExecution execution, String response, WorkflowException workflowException, boolean successIndicator){\r
+\r
                def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
                taskProcessor.utils.log("DEBUG", "SDNC Response is: " + response, isDebugLogEnabled)\r
                taskProcessor.utils.log("DEBUG", "SuccessIndicator is: " + successIndicator, isDebugLogEnabled)\r
@@ -725,13 +789,18 @@ class SDNCAdapterUtils {
                        execution.setVariable(prefix+'sdncResponseSuccess', false)\r
                        taskProcessor.utils.log("DEBUG", "Response" + ' = ' + (response == null ? "" : System.lineSeparator()) + response, isDebugLogEnabled)\r
 \r
-                       if (successIndicator == true){\r
+                       if (successIndicator){\r
                                if (response == null || response.trim().equals("")) {\r
                                        taskProcessor.utils.log("DEBUG", response + ' is empty');\r
                                        exceptionUtil.buildAndThrowWorkflowException(execution, 500, "SDNCAdapter Workflow Response is Empty")\r
                                }else{\r
+\r
                                        // we need to peer into the request data for error\r
-                                       def String decodedXml = taskProcessor.utils.getNodeText1(response, "RequestData")\r
+                                       def String sdncAdapterWorkflowResponse = taskProcessor.utils.getNodeXml(response, 'response-data', false)\r
+                                       def String decodedXml = decodeXML(sdncAdapterWorkflowResponse).replace('<?xml version="1.0" encoding="UTF-8"?>', "")\r
+\r
+                                       // change '&' to "&amp; (if present as data, ex: subscriber-name = 'FOUR SEASONS HEATING & COOLING_8310006378683'\r
+                                       decodedXml = decodedXml.replace("&", "&amp;")\r
 \r
                                        taskProcessor.utils.log("DEBUG","decodedXml:\n" + decodedXml, isDebugLogEnabled)\r
 \r
@@ -740,14 +809,12 @@ class SDNCAdapterUtils {
 \r
                                        try{\r
                                                if (taskProcessor.utils.nodeExists(decodedXml, "response-message")) {\r
-                                                       requestDataResponseMessage = taskProcessor.utils.getNodeText1(decodedXml, "response-message")\r
-                                                       \r
-                                                       // note: ResponseMessage appears within "response", not "decodedXml"\r
-                                               } else if (taskProcessor.utils.nodeExists(response, "ResponseMessage")) {\r
-                                                       requestDataResponseMessage = taskProcessor.utils.getNodeText1(response, "ResponseMessage")\r
+                                                       requestDataResponseMessage = taskProcessor.utils.getNodeText(decodedXml, "response-message")\r
+                                               } else if (taskProcessor.utils.nodeExists(decodedXml, "ResponseMessage")) {\r
+                                                       requestDataResponseMessage = taskProcessor.utils.getNodeText(decodedXml, "ResponseMessage")\r
                                                }\r
                                        }catch(Exception e){\r
-                                               taskProcessor.utils.log("DEBUG", 'Error caught while decoding response ' + e.getMessage(), isDebugLogEnabled)\r
+                                               taskProcessor.utils.log("DEBUG", 'Error caught while decoding resposne ' + e.getMessage(), isDebugLogEnabled)\r
                                        }\r
 \r
                                        if(taskProcessor.utils.nodeExists(decodedXml, "response-code")) {\r
@@ -758,20 +825,18 @@ class SDNCAdapterUtils {
                                                        taskProcessor.utils.log("DEBUG","response-code node is empty", isDebugLogEnabled)\r
                                                        requestDataResponseCode = 0\r
                                                }else{\r
-                                                       requestDataResponseCode  = code as Integer\r
+                                                       requestDataResponseCode  = code.toInteger()\r
                                                        taskProcessor.utils.log("DEBUG","response-code is: " + requestDataResponseCode, isDebugLogEnabled)\r
                                                }\r
-                                               \r
-                                               // note: ResponseCode appears within "response", not "decodedXml"\r
-                                       }else if(taskProcessor.utils.nodeExists(response, "ResponseCode")){\r
+                                       }else if(taskProcessor.utils.nodeExists(decodedXml, "ResponseCode")){\r
                                                taskProcessor.utils.log("DEBUG","ResponseCode node Exist ", isDebugLogEnabled)\r
-                                               String code = taskProcessor.utils.getNodeText1(response, "ResponseCode")\r
+                                               String code = taskProcessor.utils.getNodeText1(decodedXml, "ResponseCode")\r
                                                if(code.isEmpty() || code.equals("")){\r
                                                        // if ResponseCode blank then Success\r
                                                        taskProcessor.utils.log("DEBUG","ResponseCode node is empty", isDebugLogEnabled)\r
                                                        requestDataResponseCode = 0\r
                                                }else{\r
-                                                       requestDataResponseCode  = code as Integer\r
+                                                       requestDataResponseCode  = code.toInteger()\r
                                                        taskProcessor.utils.log("DEBUG","ResponseCode is: " + requestDataResponseCode, isDebugLogEnabled)\r
                                                }\r
                                        }else{\r
@@ -828,7 +893,8 @@ class SDNCAdapterUtils {
                         * @param responseCodeVar the execution variable in which the response code is stored\r
                         * @param errorResponseVar the execution variable in which the error response is stored\r
                         */\r
-                       public void validateL3BondingSDNCResp(Execution execution, String response, WorkflowException workflowException, boolean success) {\r
+                       public void validateL3BondingSDNCResp(DelegateExecution execution, String response, WorkflowException workflowException, boolean success) {\r
+\r
                                def method = getClass().getSimpleName() + '.validateL3BondingSDNCResp(' +\r
                                        'execution=' + execution.getId() +\r
                                        ', response=' + response +\r
@@ -842,7 +908,7 @@ class SDNCAdapterUtils {
                                        execution.setVariable(prefix+'sdncResponseSuccess', false)\r
 \r
                                        taskProcessor.utils.log("sdncAdapter Success Indicator is: " + success, isDebugLogEnabled)\r
-                                       if (success == true) {\r
+                                       if (success) {\r
 \r
                                                // we need to look inside the request data for error\r
                                                def String callbackRequestData = taskProcessor.utils.getNodeXml(response, 'RequestData', false)\r
@@ -974,4 +1040,4 @@ class SDNCAdapterUtils {
        \r
        \r
 \r
-}
+}\r