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;
27 import org.apache.commons.lang3.*
28 import org.camunda.bpm.engine.delegate.BpmnError
29 import org.camunda.bpm.engine.delegate.DelegateExecution
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.so.logger.MessageEnum
33 import org.onap.so.logger.MsoLogger
34 import org.slf4j.Logger
35 import org.slf4j.LoggerFactory
40 class ReceiveWorkflowMessage extends AbstractServiceTaskProcessor {
41 private static final Logger logger = LoggerFactory.getLogger( ReceiveWorkflowMessage.class);
44 ExceptionUtil exceptionUtil = new ExceptionUtil()
47 * Process the incoming variables.
49 * @param execution The flow's execution instance.
51 public void preProcessRequest (DelegateExecution execution) {
52 def method = getClass().getSimpleName() + '.preProcessRequest(' +
53 'execution=' + execution.getId() +
55 logger.trace('Entered ' + method)
57 def prefix="RCVWFMSG_"
58 execution.setVariable("prefix", prefix)
59 setSuccessIndicator(execution, false)
63 // Confirm that timeout value has been provided in 'RCVWFMSG_timeout'.
64 def timeout = execution.getVariable('RCVWFMSG_timeout')
65 logger.debug('Timeout value is \'' + timeout + '\'')
66 if ((timeout == null) || (timeout.isEmpty())) {
67 String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_timeout\''
69 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
70 MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue());
71 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
74 // Confirm that message type has been provided in 'RCVWFMSG_messageType'
75 def messageType = execution.getVariable('RCVWFMSG_messageType')
76 logger.debug('Message type is \'' + messageType + '\'')
77 if ((messageType == null) || (messageType.isEmpty())) {
78 String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_messageType\''
80 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
81 MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue());
82 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
85 // Confirm that correlator value has been provided in 'RCVWFMSG_correlator'
86 def correlator = execution.getVariable('RCVWFMSG_correlator')
87 logger.debug('Correlator value is \'' + correlator + '\'')
88 if ((correlator == null) || (correlator.isEmpty())) {
89 String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_correlator\''
91 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
92 MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue());
93 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
95 execution.setVariable(messageType + '_CORRELATOR', correlator)
97 logger.trace('Exited ' + method)
98 } catch (BpmnError e) {
100 } catch (Exception e) {
101 String msg = 'Caught exception in ' + method + ": " + e
103 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
104 MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue());
105 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
110 * Process a received message.
112 * @param execution The flow's execution instance.
114 public void processReceivedMessage(DelegateExecution execution){
115 def method = getClass().getSimpleName() + '.processReceivedMessage(' +
116 'execution=' + execution.getId() +
118 logger.trace('Entered ' + method)
120 String messageType = null;
121 String receivedMessage = null;
124 messageType = execution.getVariable('RCVWFMSG_messageType')
125 receivedMessage = execution.getVariable(messageType + '_MESSAGE')
126 logger.debug(getProcessKey(execution) + ": received message:\n" + receivedMessage)
128 // The received message is made available to the calling flow in WorkflowResponse
129 execution.setVariable("WorkflowResponse", receivedMessage)
131 setSuccessIndicator(execution, true)
133 logger.trace('Exited ' + method)
134 } catch (Exception e) {
135 receivedMessage = receivedMessage == null || String.valueOf(receivedMessage).isEmpty() ? "NONE" : receivedMessage
136 String msg = "Error processing received workflow message: " + receivedMessage
137 logger.debug(getProcessKey(execution) + ': ' + msg)
138 exceptionUtil.buildWorkflowException(execution, 7020, msg)