1 package org.openecomp.mso.bpmn.common.scripts
\r 
   5 import org.apache.commons.lang3.*
\r 
   6 import org.camunda.bpm.engine.delegate.BpmnError
\r 
   7 import org.camunda.bpm.engine.runtime.Execution
\r 
   8 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r 
   9 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r 
  12 class ReceiveWorkflowMessage extends AbstractServiceTaskProcessor {
\r 
  14         ExceptionUtil exceptionUtil = new ExceptionUtil()
\r 
  17          * Process the incoming variables.
\r 
  19          * @param execution The flow's execution instance.
\r 
  21 public void preProcessRequest (Execution execution) {
\r 
  22                 def method = getClass().getSimpleName() + '.preProcessRequest(' +
\r 
  23                         'execution=' + execution.getId() +
\r 
  25                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r 
  26                 logDebug('Entered ' + method, isDebugLogEnabled)
\r 
  28                 def prefix="RCVWFMSG_"
\r 
  29                 execution.setVariable("prefix", prefix)
\r 
  30                 setSuccessIndicator(execution, false)
\r 
  34                         // Confirm that timeout value has been provided in 'RCVWFMSG_timeout'.
\r 
  35                         def timeout = execution.getVariable('RCVWFMSG_timeout')
\r 
  36                         logDebug('Timeout value is \'' + timeout + '\'', isDebugLogEnabled)
\r 
  37                         if ((timeout == null) || (timeout.isEmpty())) {
\r 
  38                                 String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_timeout\''
\r 
  39                                 logDebug(msg, isDebugLogEnabled)
\r 
  41                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
\r 
  44                         // Confirm that message type has been provided in 'RCVWFMSG_messageType'
\r 
  45                         def messageType = execution.getVariable('RCVWFMSG_messageType')
\r 
  46                         logDebug('Message type is \'' + messageType + '\'', isDebugLogEnabled)
\r 
  47                         if ((messageType == null) || (messageType.isEmpty())) {
\r 
  48                                 String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_messageType\''
\r 
  49                                 logDebug(msg, isDebugLogEnabled)
\r 
  51                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
\r 
  54                         // Confirm that correlator value has been provided in 'RCVWFMSG_correlator'
\r 
  55                         def correlator = execution.getVariable('RCVWFMSG_correlator')
\r 
  56                         logDebug('Correlator value is \'' + correlator + '\'', isDebugLogEnabled)
\r 
  57                         if ((correlator == null) || (correlator.isEmpty())) {
\r 
  58                                 String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_correlator\''
\r 
  59                                 logDebug(msg, isDebugLogEnabled)
\r 
  61                                 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
\r 
  63                         execution.setVariable(messageType + '_CORRELATOR', correlator)
\r 
  65                         logDebug('Exited ' + method, isDebugLogEnabled)
\r 
  66                 } catch (BpmnError e) {
\r 
  68                 } catch (Exception e) {
\r 
  69                         String msg = 'Caught exception in ' + method + ": " + e
\r 
  70                         logDebug(msg, isDebugLogEnabled)
\r 
  72                         exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
\r 
  77          * Process a received message.
\r 
  79          * @param execution The flow's execution instance.
\r 
  81         public void processReceivedMessage(Execution execution){
\r 
  82                 def method = getClass().getSimpleName() + '.processReceivedMessage(' +
\r 
  83                         'execution=' + execution.getId() +
\r 
  85                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r 
  86                 logDebug('Entered ' + method, isDebugLogEnabled)
\r 
  88                 String messageType = null;
\r 
  89                 String receivedMessage = null;
\r 
  92                         messageType = execution.getVariable('RCVWFMSG_messageType')
\r 
  93                         receivedMessage = execution.getVariable(messageType + '_MESSAGE')
\r 
  94                         logDebug(getProcessKey(execution) + ": received message:\n" + receivedMessage, isDebugLogEnabled)
\r 
  96                         // The received message is made available to the calling flow in WorkflowResponse
\r 
  97                         execution.setVariable("WorkflowResponse", receivedMessage)
\r 
  99                         setSuccessIndicator(execution, true)
\r 
 101                         logDebug('Exited ' + method, isDebugLogEnabled)
\r 
 102                 } catch (Exception e) {
\r 
 103                         receivedMessage = receivedMessage == null || String.valueOf(receivedMessage).isEmpty() ? "NONE" : receivedMessage
\r 
 104                         String msg = "Error processing received workflow message: " + receivedMessage
\r 
 105                         logDebug(getProcessKey(execution) + ': ' + msg, isDebugLogEnabled)
\r 
 106                         exceptionUtil.buildWorkflowException(execution, 7020, msg)
\r