diff options
Diffstat (limited to 'bpmn/MSOGammaBPMN/src/main/groovy/com/att/bpm/scripts/SDNCAdapter.groovy')
-rw-r--r-- | bpmn/MSOGammaBPMN/src/main/groovy/com/att/bpm/scripts/SDNCAdapter.groovy | 368 |
1 files changed, 0 insertions, 368 deletions
diff --git a/bpmn/MSOGammaBPMN/src/main/groovy/com/att/bpm/scripts/SDNCAdapter.groovy b/bpmn/MSOGammaBPMN/src/main/groovy/com/att/bpm/scripts/SDNCAdapter.groovy deleted file mode 100644 index 8bd6983cc4..0000000000 --- a/bpmn/MSOGammaBPMN/src/main/groovy/com/att/bpm/scripts/SDNCAdapter.groovy +++ /dev/null @@ -1,368 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * OPENECOMP - MSO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.att.bpm.scripts; - -import org.openecomp.mso.bpmn.core.WorkflowException -import java.text.SimpleDateFormat - -import org.camunda.bpm.engine.delegate.BpmnError -import org.camunda.bpm.engine.runtime.Execution -import org.apache.commons.codec.binary.Base64; - - -// SDNC Adapter Request/Response processing - -public class SDNCAdapter extends AbstractServiceTaskProcessor { - - def Prefix="SDNCA_" - ExceptionUtil exceptionUtil = new ExceptionUtil() - - // Script Task: Process SDNC Workflow Request - // Params: Workflow Execution - // Assume: Received SDNCAdapterWorkflowRequest is in variable 'sdncAdapterWorkflowRequest' - // Put created SDNCAdapterRequest in variable 'sdncAdapterRequest' - public void preProcessRequest (Execution execution) { - def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - try{ - - utils.log("DEBUG", "=========== Begin PreProcess SDNCAdapterRequestScript ===========", isDebugEnabled) - utils.log("DEBUG", "Incoming sdncAdapterWorkflowRequest:\n" + execution.getVariable("sdncAdapterWorkflowRequest"), isDebugEnabled) - - // Initialize some variables used throughout the flow - execution.setVariable("prefix", Prefix) - execution.setVariable("sdncAdapterResponse", "") - execution.setVariable("asynchronousResponseTimeout", false) - execution.setVariable("continueListening", false) - execution.setVariable("SDNCA_SuccessIndicator", false) - - // Authorization Info - String basicAuthValue = execution.getVariable("URN_mso_adapters_po_auth") - utils.log("DEBUG", "Obtained BasicAuth userid password for sdnc adapter:" + basicAuthValue, isDebugEnabled) - try { - def encodedString = utils.getBasicAuth(basicAuthValue, execution.getVariable("URN_mso_msoKey")) - execution.setVariable("BasicAuthHeaderValue",encodedString) - } catch (IOException ex) { - utils.log("ERROR", "Unable to encode username password string") - } - - // TODO Use variables instead of passing xml request - Huh? - - // Get original RequestHeader - def sdncwfreq= execution.getVariable("sdncAdapterWorkflowRequest") - def requestHeader = utils.getNodeXml(sdncwfreq, "RequestHeader") - requestHeader = requestHeader.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", "") - utils.log("DEBUG", "RequestHeader:\n" + requestHeader, isDebugEnabled) - - // Set Callback URL to use from URN Mapping or jBoss Property - def origCallbackUrl = utils.getNodeText(requestHeader, "CallbackUrl") - def callbackUrlToUse = execution.getVariable("URN_mso_workflow_sdncadapter_callback") - MsoUtils msoUtil = new MsoUtils() - def useQualifiedHostName = execution.getVariable("URN_mso_use_qualified_host") - if((useQualifiedHostName!=null) && (useQualifiedHostName.equals("true"))){ - callbackUrlToUse = msoUtil.getQualifiedHostNameForCallback(callbackUrlToUse) - } - utils.log("DEBUG", "Callback URL to use:\n" + callbackUrlToUse, isDebugEnabled) - requestHeader = requestHeader.replace(origCallbackUrl, callbackUrlToUse) - - // Get parameters from request header - def sdnca_svcInstanceId = utils.getNodeText1(requestHeader, "SvcInstanceId") // optional - utils.log("DEBUG", "SvcInstanceId: " + sdnca_svcInstanceId, isDebugEnabled) - def sdnca_msoAction = utils.getNodeText1(requestHeader, "MsoAction") // optional - utils.log("DEBUG", "MsoAction: " + sdnca_msoAction, isDebugEnabled) - def sdnca_svcAction = utils.getNodeText(requestHeader, "SvcAction") - utils.log("DEBUG", "SvcAction: " + sdnca_svcAction, isDebugEnabled) - def sdnca_svcOperation = utils.getNodeText(requestHeader, "SvcOperation") - utils.log("DEBUG", "SvcOperation: " + sdnca_svcOperation, isDebugEnabled) - def sdncRequestData = utils.getChildNodes(sdncwfreq, "SDNCRequestData") - sdncRequestData = sdncRequestData.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", "") - sdncRequestData = sdncRequestData.replaceAll('tag0:', '').replaceAll(':tag0', '') - utils.log("DEBUG", "SDNCRequestData:\n" + sdncRequestData, isDebugEnabled) - def sdnca_serviceType = "" - if (utils.nodeExists(sdncwfreq, "service-type")) { - sdnca_serviceType = utils.getNodeText(sdncwfreq, "service-type") - } - utils.log("DEBUG", "service-type: " + sdnca_serviceType, isDebugEnabled) - def serviceConfigActivate = false - def source = '' - - execution.setVariable("serviceConfigActivate", serviceConfigActivate) - utils.log("DEBUG", "serviceConfigActivate: " + serviceConfigActivate, isDebugEnabled) - execution.setVariable("source", source) - utils.log("DEBUG", "source: " + source, isDebugEnabled) - - //calling process should pass a generated uuid if sending multiple sdnc requests - def requestId = utils.getNodeText(requestHeader, "RequestId") - execution.setVariable(Prefix + "requestId", requestId) - - // Prepare SDNC Request to the SDNC Adapter - String sdncAdapterRequest = """ - <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> - <SOAP-ENV:Body> - <aetgt:SDNCAdapterRequest xmlns:aetgt="http://domain2.att.com/workflow/sdnc/adapter/schema/v1" xmlns:sdncadaptersc="http://domain2.att.com/workflow/sdnc/adapter/schema/v1"> - <sdncadapter:RequestHeader xmlns:sdncadapter="http://domain2.att.com/workflow/sdnc/adapter/schema/v1"> - <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>""" - - if (sdnca_svcInstanceId != null) { - sdncAdapterRequest += """ - <sdncadapter:SvcInstanceId>${sdnca_svcInstanceId}</sdncadapter:SvcInstanceId>""" - } - - sdncAdapterRequest += """ - <sdncadapter:SvcAction>${sdnca_svcAction}</sdncadapter:SvcAction> - <sdncadapter:SvcOperation>${sdnca_svcOperation}</sdncadapter:SvcOperation> - <sdncadapter:CallbackUrl>${callbackUrlToUse}</sdncadapter:CallbackUrl>""" - - if (sdnca_msoAction != null) { - sdncAdapterRequest += """ - <sdncadapter:MsoAction>${sdnca_msoAction}</sdncadapter:MsoAction>""" - } - - sdncAdapterRequest += """ - </sdncadapter:RequestHeader> - <sdncadaptersc:RequestData>${sdncRequestData}</sdncadaptersc:RequestData></aetgt:SDNCAdapterRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>""" - - utils.logAudit("Outgoing SDNCAdapterRequest:\n" + sdncAdapterRequest) - execution.setVariable("sdncAdapterRequest", sdncAdapterRequest) - - utils.log("DEBUG", execution.getVariable("sdncAdapterRequest"), isDebugEnabled) - utils.log("DEBUG", execution.getVariable("URN_mso_adapters_sdnc_endpoint"), isDebugEnabled) - }catch(Exception e){ - utils.log("DEBUG", 'Internal Error occured during PreProcess Method: ' + e, isDebugEnabled) - exceptionUtil.buildAndThrowWorkflowException(execution, 9999, 'Internal Error occured during PreProcess Method') // TODO: what message and error code? - } - utils.log("DEBUG","=========== End pre Process SDNCRequestScript ===========", isDebugEnabled) - } - - public void postProcessResponse (Execution execution) { - - def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - try{ - utils.log("DEBUG","=========== Begin POSTProcess SDNCAdapter ===========", isDebugEnabled) - utils.log("DEBUG","Incoming sdncAdapterCallbackRequest:\n" + execution.getVariable("sdncAdapterCallbackRequest"), isDebugEnabled) - - // Check the sdnccallback request and get the responsecode - def sdnccallbackreq = execution.getVariable("sdncAdapterCallbackRequest") - def callbackRequestData = "" - def callbackHeader = "" - - if(sdnccallbackreq != null){ - callbackHeader = utils.getNodeXml(sdnccallbackreq, "CallbackHeader") - callbackRequestData = utils.getNodeXml(sdnccallbackreq, "RequestData") - - callbackHeader = callbackHeader.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", "") - utils.log("DEBUG","SDNCCallbackHeader is:\n" + callbackHeader, isDebugEnabled) - - callbackRequestData = callbackRequestData.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", "") - utils.log("DEBUG","DECODED SDNCCallback RequestData is:\n" + callbackRequestData, isDebugEnabled) - - String sdncAdapterWorkflowResponse =""" - <sdncadapterworkflow:SDNCAdapterWorkflowResponse xmlns:sdncadapterworkflow="http://ecomp.att.com/mso/workflow/schema/v1"> - <sdncadapterworkflow:response-data> - ${callbackHeader} - ${callbackRequestData} - </sdncadapterworkflow:response-data> - </sdncadapterworkflow:SDNCAdapterWorkflowResponse>""" - - - utils.log("DEBUG","Outgoing sdncAdapterWorkflowResponse:\n" + sdncAdapterWorkflowResponse, isDebugEnabled) - sdncAdapterWorkflowResponse = utils.formatXml(sdncAdapterWorkflowResponse) - execution.setVariable("sdncAdapterResponse", sdncAdapterWorkflowResponse) - // TODO: Should deprecate use of processKey+Response variable for the response. Will use "WorkflowResponse" instead - execution.setVariable("WorkflowResponse", sdncAdapterWorkflowResponse) - - // Check final indicator to determine if we are to continue listening or not - def String enhancedCallbackRequestData = callbackRequestData.replaceAll("&", "&") - enhancedCallbackRequestData = enhancedCallbackRequestData.replaceAll("<", "<") - enhancedCallbackRequestData = enhancedCallbackRequestData.replaceAll(">", ">") - // replace the data with '&' (ex: subscriber-name= 'FOUR SEASONS HEATING & COOLING' - enhancedCallbackRequestData = enhancedCallbackRequestData.replace("&", "&") - utils.log("DEBUG","EnhancedCallbackRequestData:\n" + enhancedCallbackRequestData, isDebugEnabled) - execution.setVariable("enhancedCallbackRequestData", enhancedCallbackRequestData) - def continueListening = false - if (utils.nodeExists(enhancedCallbackRequestData, "ack-final-indicator")) { - if (utils.getNodeText(enhancedCallbackRequestData, "ack-final-indicator") == 'N') { - continueListening = true - } - } - execution.setVariable("continueListening", continueListening) - utils.log("DEBUG", "Continue Listening: " + continueListening, isDebugEnabled) - }else{ - // Timed out waiting for asynchronous message, build error response - exceptionUtil.buildWorkflowException(execution, 500, "SDNC Callback Timeout Error") - execution.setVariable("asynchronousResponseTimeout", true) - utils.log("DEBUG", "Timed out waiting for asynchronous message", isDebugEnabled) - } - }catch(Exception e){ - utils.log("DEBUG", 'Internal Error occured during PostProcess Method: ' + e, isDebugEnabled) - exceptionUtil.buildAndThrowWorkflowException(execution, 9999, 'Internal Error occured during PostProcess Method') // TODO: what message and error code? - } - utils.log("DEBUG","=========== End POSTProcess SDNCAdapter ===========", isDebugEnabled) - } - - public void callbackResponsecheck(Execution execution){ - - def sdnccallbackreq=execution.getVariable("sdncAdapterCallbackRequest") - if (sdnccallbackreq==null){ - execution.setVariable("callbackResponseReceived",false); - }else{ - execution.setVariable("callbackResponseReceived",true); - } - } - - public void resetCallbackRequest(Execution execution) { - - def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - - utils.log("DEBUG","=========== Begin Reset Callback Info SDNCAdapter ===========", isDebugEnabled) - - // Clear sdncAdapterCallbackRequest variable - execution.removeVariable("sdncAdapterCallbackRequest") - - // Determine and set SDNC Timeout Value - def enhancedCallbackRequestData = execution.getVariable("enhancedCallbackRequestData") - def interim = false - if (enhancedCallbackRequestData != null) { - if (utils.nodeExists(enhancedCallbackRequestData, "ack-final-indicator")) { - if (utils.getNodeText(enhancedCallbackRequestData, "ack-final-indicator") == 'N') { - interim = true - } - } - } - def timeoutValue = execution.getVariable("URN_mso_sdnc_timeout") - def sdncAdapterWorkflowRequest = execution.getVariable("sdncAdapterWorkflowRequest") - if (interim && utils.nodeExists(sdncAdapterWorkflowRequest, "InterimSDNCTimeOutValueInHours")) { - timeoutValue = "PT" + utils.getNodeText(sdncAdapterWorkflowRequest, "InterimSDNCTimeOutValueInHours") + "H" - } else if (utils.nodeExists(sdncAdapterWorkflowRequest, "SDNCTimeOutValueInMinutes")) { - timeoutValue = "PT" + utils.getNodeText(sdncAdapterWorkflowRequest, "SDNCTimeOutValueInMinutes") + "M" - } - execution.setVariable("sdncTimeoutValue", timeoutValue) - utils.log("DEBUG", "Setting SDNC Timeout Value to " + timeoutValue, isDebugEnabled) - - utils.log("DEBUG","=========== End Reset Callback Info SDNCAdapter ===========", isDebugEnabled) - } - - public void prepareCSIMessage(Execution execution) { - - } - - public void prepareDBMessage(Execution execution) { - - def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - - utils.log("DEBUG","=========== Begin Prepare DB Message SDNCAdapter ===========", isDebugEnabled) - - // Create DB Message - def dbRequestId = execution.getVariable("att-mso-request-id") - String dbUpdateInterimStageCompletion = """ - <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> - <SOAP-ENV:Body> - <DBAdapter:updateInterimStageCompletion xmlns:DBAdapter="http://com.att.mso/requestsdb"> - <requestId>${dbRequestId}</requestId> - <interimStageCompletion>1</interimStageCompletion> - <lastModifiedBy>BPEL</lastModifiedBy> - </DBAdapter:updateInterimStageCompletion> - </SOAP-ENV:Body> - </SOAP-ENV:Envelope> - """ - - execution.setVariable("dbUpdateInterimStageCompletion", dbUpdateInterimStageCompletion) - utils.log("DEBUG","DB UpdateInterimStageCompletion:\n" + dbUpdateInterimStageCompletion, isDebugEnabled) - - utils.log("DEBUG","=========== End Prepare DB Message SDNCAdapter ===========", isDebugEnabled) - } - - public void prepareCCDMessage(Execution execution) { - - def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - - utils.log("DEBUG","=========== Begin Prepare CCD Message SDNCAdapter ===========", isDebugEnabled) - - try { - def sdncwfreq= execution.getVariable("sdncAdapterWorkflowRequest") - def sdncRequestData = utils.getNodeXml(sdncwfreq, "SDNCRequestData", false) - - def ccdNotificationUrl = utils.getNodeText(sdncRequestData, 'notification-url') - execution.setVariable('ccd-notification-url', ccdNotificationUrl) - utils.log("DEBUG", 'ccd-notification-url: ' + ccdNotificationUrl, isDebugEnabled) - - def requestId = utils.getNodeText(sdncRequestData, 'request-id') - def requestAction = utils.getNodeText(sdncRequestData, 'request-action') - String payload =""" - <ns:status-notification - xmlns:ns="http://ecomp.att.com/mso/statusnotification/schema/v1" - xmlns:msoservtypes="http://ecomp.att.com/mso/request/types/v1" - xmlns:structuredtypes="http://ecomp.att.com/mso/structured/types/v1"> - <msoservtypes:request-id>${requestId}</msoservtypes:request-id> - <msoservtypes:request-action>${requestAction}</msoservtypes:request-action> - <msoservtypes:source>CCD</msoservtypes:source> - <msoservtypes:ack-final-indicator>N</msoservtypes:ack-final-indicator> - <structuredtypes:parameter-list> - <structuredtypes:parameter> - <structuredtypes:name>request-stage</structuredtypes:name> - <structuredtypes:value>DataStagingComplete</structuredtypes:value> - </structuredtypes:parameter> - </structuredtypes:parameter-list> - </ns:status-notification> - """ - - payload = utils.formatXml(payload) - execution.setVariable('ccd-notification-payload', payload) - utils.log("DEBUG", 'ccd-notification-payload:\n' + payload, isDebugEnabled) - - } catch (BpmnError e) { - throw e; - } catch (Exception e) { - logError('Caught exception in prepareCCDMessage', e) - exceptionUtil.buildAndThrowWorkflowException(execution, 9999, 'Internal Error') // TODO: what message and error code? - } - - utils.log("DEBUG","=========== End Prepare CCD Message SDNCAdapter ===========", isDebugEnabled) - } - - public String generateCurrentTimeInUtc(){ - final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - sdf.setTimeZone(TimeZone.getTimeZone("UTC")); - final String utcTime = sdf.format(new Date()); - return utcTime; - } - - public void toggleSuccessIndicator(Execution execution){ - def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - execution.setVariable("SDNCA_SuccessIndicator", true) - utils.log("DEBUG","Setting SDNCA Success Indicator to True", isDebugEnabled) - } - - public void assignError(Execution execution){ - def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - utils.log("DEBUG","=========== Started Assign Error ===========", isDebugEnabled) - WorkflowException wf = execution.getVariable("WorkflowException") - if(wf == null){ - exceptionUtil.buildWorkflowException(execution, 5000, "SDNCAdapter Encountered an Internal Error") // TODO: Not sure what message and error code we want here..... - }else{ - execution.setVariable("WorkflowException", wf) - } - - utils.log("DEBUG","Outgoing WorkflowException is: " + execution.getVariable("WorkflowException"), isDebugEnabled) - utils.log("DEBUG","=========== End Assign Error ===========", isDebugEnabled) - } - -} - |