2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.common.scripts
25 import com.google.common.base.Strings;
28 import org.apache.commons.lang3.*
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.delegate.DelegateExecution
31 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
32 import org.onap.so.bpmn.common.scripts.ExceptionUtil
33 import org.onap.so.logger.ErrorCode
34 import org.onap.so.logger.MessageEnum
35 import org.slf4j.Logger
36 import org.slf4j.LoggerFactory
41 class ReceiveWorkflowMessage extends AbstractServiceTaskProcessor {
42 private static final Logger logger = LoggerFactory.getLogger( ReceiveWorkflowMessage.class);
45 ExceptionUtil exceptionUtil = new ExceptionUtil()
48 * Process the incoming variables.
50 * @param execution The flow's execution instance.
52 public void preProcessRequest (DelegateExecution execution) {
53 def method = getClass().getSimpleName() + '.preProcessRequest(' +
54 'execution=' + execution.getId() +
56 logger.trace('Entered ' + method)
58 def prefix="RCVWFMSG_"
59 execution.setVariable("prefix", prefix)
60 setSuccessIndicator(execution, false)
64 // Confirm that timeout value has been provided in 'RCVWFMSG_timeout'.
65 def timeout = execution.getVariable('RCVWFMSG_timeout')
66 logger.debug('Timeout value is \'' + timeout + '\'')
67 if ((timeout == null) || (timeout.isEmpty())) {
68 String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_timeout\''
70 logger.error(Strings.repeat("{} ", 4), MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
71 ErrorCode.UnknownError.getValue());
72 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
75 // Confirm that message type has been provided in 'RCVWFMSG_messageType'
76 def messageType = execution.getVariable('RCVWFMSG_messageType')
77 logger.debug('Message type is \'' + messageType + '\'')
78 if ((messageType == null) || (messageType.isEmpty())) {
79 String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_messageType\''
81 logger.error(Strings.repeat("{} ", 4), MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
82 ErrorCode.UnknownError.getValue());
83 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
86 // Confirm that correlator value has been provided in 'RCVWFMSG_correlator'
87 def correlator = execution.getVariable('RCVWFMSG_correlator')
88 logger.debug('Correlator value is \'' + correlator + '\'')
89 if ((correlator == null) || (correlator.isEmpty())) {
90 String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_correlator\''
92 logger.error(Strings.repeat("{} ", 4), MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
93 ErrorCode.UnknownError.getValue());
94 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
96 execution.setVariable(messageType + '_CORRELATOR', correlator)
98 logger.trace('Exited ' + method)
99 } catch (BpmnError e) {
101 } catch (Exception e) {
102 String msg = 'Caught exception in ' + method + ": " + e
104 logger.error(Strings.repeat("{} ", 4), MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
105 ErrorCode.UnknownError.getValue());
106 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
111 * Process a received message.
113 * @param execution The flow's execution instance.
115 public void processReceivedMessage(DelegateExecution execution){
116 def method = getClass().getSimpleName() + '.processReceivedMessage(' +
117 'execution=' + execution.getId() +
119 logger.trace('Entered ' + method)
121 String messageType = null;
122 String receivedMessage = null;
125 messageType = execution.getVariable('RCVWFMSG_messageType')
126 receivedMessage = execution.getVariable(messageType + '_MESSAGE')
127 logger.debug(getProcessKey(execution) + ": received message:\n" + receivedMessage)
129 // The received message is made available to the calling flow in WorkflowResponse
130 execution.setVariable("WorkflowResponse", receivedMessage)
132 setSuccessIndicator(execution, true)
134 logger.trace('Exited ' + method)
135 } catch (Exception e) {
136 receivedMessage = receivedMessage == null || String.valueOf(receivedMessage).isEmpty() ? "NONE" : receivedMessage
137 String msg = "Error processing received workflow message: " + receivedMessage
138 logger.debug(getProcessKey(execution) + ': ' + msg)
139 exceptionUtil.buildWorkflowException(execution, 7020, msg)