Merge "avoid null exception"
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / UpdateCustomE2EServiceInstance.groovy
index 44eaa34..adea23a 100644 (file)
@@ -34,7 +34,7 @@ import java.util.List;
 import java.util.UUID;
 
 import org.camunda.bpm.engine.delegate.BpmnError
-import org.camunda.bpm.engine.runtime.Execution
+import org.camunda.bpm.engine.delegate.DelegateExecution
 import org.apache.commons.lang3.*
 import org.apache.commons.codec.binary.Base64;
 import org.springframework.web.util.UriUtils
@@ -50,7 +50,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
        JsonUtils jsonUtil = new JsonUtils()
 
 
-       public void preProcessRequest (Execution execution) {
+       public void preProcessRequest (DelegateExecution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
                execution.setVariable("prefix",Prefix)
                String msg = ""
@@ -109,8 +109,8 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
 
                        utils.log("INFO", "uuiRequest:\n" + uuiRequest,  isDebugEnabled)
 
-                       //requestParameters
-                       String serviceType = jsonUtil.getJsonValue(uuiRequest, "service.parameters.serviceType")
+                       //serviceType for aai
+                       String serviceType = jsonUtil.getJsonValue(uuiRequest, "service.serviceType")
                        if (isBlank(serviceType)) {
                                msg = "Input serviceType is null"
                                utils.log("INFO", msg, isDebugEnabled)
@@ -119,6 +119,29 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                                execution.setVariable("serviceType", serviceType)
                        }
                        
+                       /*
+                        * Extracting User Parameters from incoming Request and converting into a Map
+                        */
+                       def jsonSlurper = new JsonSlurper()
+                       def jsonOutput = new JsonOutput()
+
+                       Map reqMap = jsonSlurper.parseText(siRequest)
+
+                       //InputParams
+                       def userParamsList = reqMap.requestDetails?.requestParameters?.userParams
+
+                       Map<String, String> inputMap = [:]
+                       if (userParamsList) {
+                               for (def i=0; i<userParamsList.size(); i++) {
+                                       def userParams1 = userParamsList.get(i)
+                                       userParams1.each { param -> inputMap.put(param.key, param.value)}
+                               }
+                       }
+                       
+                       utils.log("DEBUG", "User Input Parameters map: " + inputMap.toString(), isDebugEnabled)
+                       execution.setVariable("serviceInputParams", inputMap)
+                       execution.setVariable("uuiRequest", inputMap.get("UUIRequest"))
+                       
                        //operationId
                        String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
                        if (isBlank(operationId)) {
@@ -138,8 +161,63 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                }
                utils.log("INFO"," ***** Exit preProcessRequest *****",  isDebugEnabled)
        }
+       
+       /**
+        * Init the service Operation Status
+        */
+       public void prepareInitServiceOperationStatus(DelegateExecution execution){
+               def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+               utils.log("DEBUG", " ======== STARTED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
+               try{
+                       String serviceId = execution.getVariable("serviceInstanceId")
+                       String operationId = execution.getVariable("operationId")
+                       String operationType = execution.getVariable("operationType")
+                       String userId = ""
+                       String result = "processing"
+                       String progress = "0"
+                       String reason = ""
+                       String operationContent = "Prepare service updating"
+                       utils.log("DEBUG", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)
+                       serviceId = UriUtils.encode(serviceId,"UTF-8")
+                       execution.setVariable("serviceInstanceId", serviceId)
+                       execution.setVariable("operationId", operationId)
+                       execution.setVariable("operationType", operationType)
+
+                       def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
+                       execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
+                       utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
+
+                       String payload =
+                               """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+                        xmlns:ns="http://org.openecomp.mso/requestsdb">
+                        <soapenv:Header/>
+                        <soapenv:Body>
+                            <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
+                            <serviceId>${serviceId}</serviceId>
+                            <operationId>${operationId}</operationId>
+                            <operationType>${operationType}</operationType>
+                            <userId>${userId}</userId>
+                            <result>${result}</result>
+                            <operationContent>${operationContent}</operationContent>
+                            <progress>${progress}</progress>
+                            <reason>${reason}</reason>
+                        </ns:updateServiceOperationStatus>
+                    </soapenv:Body>
+                </soapenv:Envelope>"""
+
+                       payload = utils.formatXml(payload)
+                       execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
+                       utils.log("DEBUG", "Outgoing updateServiceOperStatusRequest: \n" + payload, isDebugEnabled)
+                       utils.logAudit("CreateVfModuleInfra Outgoing updateServiceOperStatusRequest Request: " + payload)
+
+               }catch(Exception e){
+                       utils.log("ERROR", "Exception Occured Processing prepareInitServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)
+                       execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
+               }
+               utils.log("DEBUG", "======== COMPLETED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
+       }
 
-       public void sendSyncResponse (Execution execution) {
+       public void sendSyncResponse (DelegateExecution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
                utils.log("INFO", " *** sendSyncResponse *** ", isDebugEnabled)
 
@@ -147,9 +225,9 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                        String operationId = execution.getVariable("operationId")
                        String serviceInstanceId = execution.getVariable("serviceInstanceId")
                        // RESTResponse for API Handler (APIH) Reply Task
-                       String updateServiceRestRequest = """{"service":{"serviceId":"${serviceInstanceId}","operationId":"${operationId}"}}""".trim()
-                       utils.log("INFO", " sendSyncResponse to APIH:" + "\n" + updateServiceRestRequest, isDebugEnabled)
-                       sendWorkflowResponse(execution, 202, updateServiceRestRequest)
+                       String updateServiceResp = """{"operationId":"${operationId}"}""".trim()
+                       utils.log("INFO", " sendSyncResponse to APIH:" + "\n" + updateServiceResp, isDebugEnabled)
+                       sendWorkflowResponse(execution, 202, updateServiceResp)
                        execution.setVariable("sentSyncResponse", true)
 
                } catch (Exception ex) {
@@ -161,7 +239,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
        }
 
 
-       public void sendSyncError (Execution execution) {
+       public void sendSyncError (DelegateExecution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
                utils.log("INFO", " *** sendSyncError *** ", isDebugEnabled)
 
@@ -189,7 +267,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
 
        }
 
-       public void prepareCompletionRequest (Execution execution) {
+       public void prepareCompletionRequest (DelegateExecution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
                utils.log("INFO", " *** prepareCompletion *** ", isDebugEnabled)
 
@@ -225,7 +303,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                utils.log("INFO", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
        }
 
-       public void prepareFalloutRequest(Execution execution){
+       public void prepareFalloutRequest(DelegateExecution execution){
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
                utils.log("INFO", " *** prepareFalloutRequest *** ", isDebugEnabled)