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.core.plugins;
25 import java.util.ArrayList;
26 import java.util.List;
27 import org.camunda.bpm.engine.RepositoryService;
28 import org.camunda.bpm.engine.delegate.DelegateExecution;
29 import org.camunda.bpm.engine.delegate.ExecutionListener;
30 import org.camunda.bpm.engine.impl.bpmn.parser.AbstractBpmnParseListener;
31 import org.camunda.bpm.engine.impl.bpmn.parser.BpmnParseListener;
32 import org.camunda.bpm.engine.impl.cfg.AbstractProcessEnginePlugin;
33 import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
34 import org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity;
35 import org.camunda.bpm.engine.impl.pvm.process.ActivityImpl;
36 import org.camunda.bpm.engine.impl.pvm.process.ScopeImpl;
37 import org.camunda.bpm.engine.impl.pvm.process.TransitionImpl;
38 import org.camunda.bpm.engine.impl.util.xml.Element;
39 import org.camunda.bpm.engine.impl.variable.VariableDeclaration;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.stereotype.Component;
48 * Plugin for MSO logging and URN mapping.
51 public class LoggingAndURNMappingPlugin extends AbstractProcessEnginePlugin {
54 private LoggingParseListener loggingParseListener;
57 public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
58 List<BpmnParseListener> preParseListeners = processEngineConfiguration.getCustomPreBPMNParseListeners();
59 if (preParseListeners == null) {
60 preParseListeners = new ArrayList<>();
61 processEngineConfiguration.setCustomPreBPMNParseListeners(preParseListeners);
63 preParseListeners.add(loggingParseListener);
67 * Called when a process flow is parsed so we can inject listeners.
70 public class LoggingParseListener extends AbstractBpmnParseListener {
73 private void injectLogExecutionListener(ActivityImpl activity) {
74 activity.addListener(ExecutionListener.EVENTNAME_END, new LoggingExecutionListener("END"));
76 activity.addListener(ExecutionListener.EVENTNAME_START, new LoggingExecutionListener("START"));
78 activity.addListener(ExecutionListener.EVENTNAME_TAKE, new LoggingExecutionListener("TAKE"));
82 public void parseProcess(Element processElement, ProcessDefinitionEntity processDefinition) {}
85 public void parseStartEvent(Element startEventElement, ScopeImpl scope, ActivityImpl startEventActivity) {
86 // Inject these listeners only on the main start event for the flow, not on any embedded subflow start
89 injectLogExecutionListener(startEventActivity);
93 public void parseServiceTask(Element serviceTaskElement, ScopeImpl scope, ActivityImpl activity) {
94 injectLogExecutionListener(activity);
98 public void parseExclusiveGateway(Element exclusiveGwElement, ScopeImpl scope, ActivityImpl activity) {
99 injectLogExecutionListener(activity);
103 public void parseInclusiveGateway(Element inclusiveGwElement, ScopeImpl scope, ActivityImpl activity) {
104 injectLogExecutionListener(activity);
108 public void parseParallelGateway(Element parallelGwElement, ScopeImpl scope, ActivityImpl activity) {
109 injectLogExecutionListener(activity);
113 public void parseScriptTask(Element scriptTaskElement, ScopeImpl scope, ActivityImpl activity) {
114 injectLogExecutionListener(activity);
118 public void parseBusinessRuleTask(Element businessRuleTaskElement, ScopeImpl scope, ActivityImpl activity) {
119 injectLogExecutionListener(activity);
123 public void parseTask(Element taskElement, ScopeImpl scope, ActivityImpl activity) {
124 injectLogExecutionListener(activity);
128 public void parseManualTask(Element manualTaskElement, ScopeImpl scope, ActivityImpl activity) {
129 injectLogExecutionListener(activity);
133 public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity) {
134 injectLogExecutionListener(activity);
138 public void parseEndEvent(Element endEventElement, ScopeImpl scope, ActivityImpl activity) {
139 injectLogExecutionListener(activity);
143 public void parseBoundaryTimerEventDefinition(Element timerEventDefinition, boolean interrupting,
144 ActivityImpl timerActivity) {
145 injectLogExecutionListener(timerActivity);
149 public void parseBoundaryErrorEventDefinition(Element errorEventDefinition, boolean interrupting,
150 ActivityImpl activity, ActivityImpl nestedErrorEventActivity) {
151 injectLogExecutionListener(activity);
155 public void parseSubProcess(Element subProcessElement, ScopeImpl scope, ActivityImpl activity) {
156 injectLogExecutionListener(activity);
160 public void parseCallActivity(Element callActivityElement, ScopeImpl scope, ActivityImpl activity) {
161 injectLogExecutionListener(activity);
165 public void parseProperty(Element propertyElement, VariableDeclaration variableDeclaration,
166 ActivityImpl activity) {
167 injectLogExecutionListener(activity);
171 public void parseSequenceFlow(Element sequenceFlowElement, ScopeImpl scopeElement, TransitionImpl transition) {
172 // injectLogExecutionListener(activity);
176 public void parseSendTask(Element sendTaskElement, ScopeImpl scope, ActivityImpl activity) {
177 injectLogExecutionListener(activity);
181 public void parseMultiInstanceLoopCharacteristics(Element activityElement,
182 Element multiInstanceLoopCharacteristicsElement, ActivityImpl activity) {
183 injectLogExecutionListener(activity);
187 public void parseIntermediateTimerEventDefinition(Element timerEventDefinition, ActivityImpl timerActivity) {
188 injectLogExecutionListener(timerActivity);
192 public void parseRootElement(Element rootElement, List<ProcessDefinitionEntity> processDefinitions) {
197 public void parseReceiveTask(Element receiveTaskElement, ScopeImpl scope, ActivityImpl activity) {
198 injectLogExecutionListener(activity);
202 public void parseIntermediateSignalCatchEventDefinition(Element signalEventDefinition,
203 ActivityImpl signalActivity) {
204 injectLogExecutionListener(signalActivity);
208 public void parseBoundarySignalEventDefinition(Element signalEventDefinition, boolean interrupting,
209 ActivityImpl signalActivity) {
210 injectLogExecutionListener(signalActivity);
214 public void parseEventBasedGateway(Element eventBasedGwElement, ScopeImpl scope, ActivityImpl activity) {
215 injectLogExecutionListener(activity);
219 public void parseTransaction(Element transactionElement, ScopeImpl scope, ActivityImpl activity) {
220 injectLogExecutionListener(activity);
224 public void parseCompensateEventDefinition(Element compensateEventDefinition,
225 ActivityImpl compensationActivity) {
226 injectLogExecutionListener(compensationActivity);
230 public void parseIntermediateThrowEvent(Element intermediateEventElement, ScopeImpl scope,
231 ActivityImpl activity) {
232 injectLogExecutionListener(activity);
236 public void parseIntermediateCatchEvent(Element intermediateEventElement, ScopeImpl scope,
237 ActivityImpl activity) {
238 injectLogExecutionListener(activity);
242 public void parseBoundaryEvent(Element boundaryEventElement, ScopeImpl scopeElement,
243 ActivityImpl nestedActivity) {
244 injectLogExecutionListener(nestedActivity);
248 public void parseIntermediateMessageCatchEventDefinition(Element messageEventDefinition,
249 ActivityImpl nestedActivity) {
250 injectLogExecutionListener(nestedActivity);
254 public void parseBoundaryMessageEventDefinition(Element element, boolean interrupting,
255 ActivityImpl messageActivity) {
256 injectLogExecutionListener(messageActivity);
261 * Logs details about the current activity.
263 public class LoggingExecutionListener implements ExecutionListener {
264 private final Logger logger = LoggerFactory.getLogger(LoggingExecutionListener.class);
266 private String event;
268 public LoggingExecutionListener() {
272 public LoggingExecutionListener(String event) {
276 public String getEvent() {
281 public void notify(DelegateExecution execution) throws Exception {
282 // required for legacy groovy processing in camunda
283 execution.setVariable("isDebugLogEnabled", "true");
284 if (!isBlank(execution.getCurrentActivityName())) {
287 String id = execution.getId();
289 RepositoryService repositoryService =
290 execution.getProcessEngineServices().getRepositoryService();
291 String processName = repositoryService.createProcessDefinitionQuery()
292 .processDefinitionId(execution.getProcessDefinitionId()).singleResult().getName();
295 String requestId = (String) execution.getVariable("mso-request-id");
296 String svcid = (String) execution.getVariable("mso-service-instance-id");
298 } catch (Exception e) {
299 logger.error("Exception occurred", e);
304 private boolean isBlank(Object object) {
305 return object == null || "".equals(object.toString().trim());