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.io.IOException;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.HashMap;
29 import java.util.Iterator;
30 import java.util.List;
32 import java.util.Map.Entry;
33 import java.util.Properties;
34 import java.util.concurrent.ConcurrentHashMap;
36 import org.camunda.bpm.engine.RepositoryService;
37 import org.camunda.bpm.engine.delegate.DelegateExecution;
38 import org.camunda.bpm.engine.delegate.ExecutionListener;
39 import org.camunda.bpm.engine.impl.bpmn.parser.AbstractBpmnParseListener;
40 import org.camunda.bpm.engine.impl.bpmn.parser.BpmnParseListener;
41 import org.camunda.bpm.engine.impl.cfg.AbstractProcessEnginePlugin;
42 import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
43 import org.camunda.bpm.engine.impl.context.Context;
44 import org.camunda.bpm.engine.impl.interceptor.Command;
45 import org.camunda.bpm.engine.impl.interceptor.CommandContext;
46 import org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity;
47 import org.camunda.bpm.engine.impl.pvm.process.ActivityImpl;
48 import org.camunda.bpm.engine.impl.pvm.process.ScopeImpl;
49 import org.camunda.bpm.engine.impl.pvm.process.TransitionImpl;
50 import org.camunda.bpm.engine.impl.util.xml.Element;
51 import org.camunda.bpm.engine.impl.variable.VariableDeclaration;
52 import org.camunda.bpm.model.bpmn.impl.instance.FlowNodeImpl;
53 import org.camunda.bpm.model.bpmn.instance.EndEvent;
54 import org.camunda.bpm.model.bpmn.instance.FlowNode;
55 import org.camunda.bpm.model.bpmn.instance.StartEvent;
56 import org.onap.so.bpmn.core.BPMNLogger;
59 import org.slf4j.Logger;
60 import org.slf4j.LoggerFactory;
61 import org.springframework.beans.factory.annotation.Autowired;
62 import org.springframework.core.env.AbstractEnvironment;
63 import org.springframework.core.env.Environment;
64 import org.springframework.core.env.MapPropertySource;
65 import org.springframework.core.env.PropertySource;
66 import org.springframework.stereotype.Component;
71 * Plugin for MSO logging and URN mapping.
74 public class LoggingAndURNMappingPlugin extends AbstractProcessEnginePlugin {
77 private LoggingParseListener loggingParseListener;
81 ProcessEngineConfigurationImpl processEngineConfiguration) {
82 List<BpmnParseListener> preParseListeners = processEngineConfiguration
83 .getCustomPreBPMNParseListeners();
84 if (preParseListeners == null) {
85 preParseListeners = new ArrayList<>();
86 processEngineConfiguration.setCustomPreBPMNParseListeners(preParseListeners);
88 preParseListeners.add(loggingParseListener);
92 * Called when a process flow is parsed so we can inject listeners.
95 public class LoggingParseListener extends AbstractBpmnParseListener {
98 private void injectLogExecutionListener(ActivityImpl activity) {
100 ExecutionListener.EVENTNAME_END,
101 new LoggingExecutionListener("END"));
103 activity.addListener(
104 ExecutionListener.EVENTNAME_START,
105 new LoggingExecutionListener("START"));
107 activity.addListener(
108 ExecutionListener.EVENTNAME_TAKE,
109 new LoggingExecutionListener("TAKE"));
113 public void parseProcess(Element processElement, ProcessDefinitionEntity processDefinition) {
117 public void parseStartEvent(Element startEventElement, ScopeImpl scope, ActivityImpl startEventActivity) {
118 // Inject these listeners only on the main start event for the flow, not on any embedded subflow start events
120 injectLogExecutionListener(startEventActivity);
124 public void parseServiceTask(Element serviceTaskElement, ScopeImpl scope, ActivityImpl activity) {
125 injectLogExecutionListener(activity);
129 public void parseExclusiveGateway(Element exclusiveGwElement, ScopeImpl scope, ActivityImpl activity) {
130 injectLogExecutionListener(activity);
134 public void parseInclusiveGateway(Element inclusiveGwElement, ScopeImpl scope, ActivityImpl activity) {
135 injectLogExecutionListener(activity);
139 public void parseParallelGateway(Element parallelGwElement, ScopeImpl scope, ActivityImpl activity) {
140 injectLogExecutionListener(activity);
144 public void parseScriptTask(Element scriptTaskElement, ScopeImpl scope, ActivityImpl activity) {
145 injectLogExecutionListener(activity);
149 public void parseBusinessRuleTask(Element businessRuleTaskElement, ScopeImpl scope, ActivityImpl activity) {
150 injectLogExecutionListener(activity);
154 public void parseTask(Element taskElement, ScopeImpl scope, ActivityImpl activity) {
155 injectLogExecutionListener(activity);
159 public void parseManualTask(Element manualTaskElement, ScopeImpl scope, ActivityImpl activity) {
160 injectLogExecutionListener(activity);
164 public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity) {
165 injectLogExecutionListener(activity);
169 public void parseEndEvent(Element endEventElement, ScopeImpl scope, ActivityImpl activity) {
170 injectLogExecutionListener(activity);
174 public void parseBoundaryTimerEventDefinition(Element timerEventDefinition, boolean interrupting, ActivityImpl timerActivity) {
175 injectLogExecutionListener(timerActivity);
179 public void parseBoundaryErrorEventDefinition(Element errorEventDefinition, boolean interrupting, ActivityImpl activity, ActivityImpl nestedErrorEventActivity) {
180 injectLogExecutionListener(activity);
184 public void parseSubProcess(Element subProcessElement, ScopeImpl scope, ActivityImpl activity) {
185 injectLogExecutionListener(activity);
189 public void parseCallActivity(Element callActivityElement, ScopeImpl scope, ActivityImpl activity) {
190 injectLogExecutionListener(activity);
194 public void parseProperty(Element propertyElement, VariableDeclaration variableDeclaration, ActivityImpl activity) {
195 injectLogExecutionListener(activity);
199 public void parseSequenceFlow(Element sequenceFlowElement, ScopeImpl scopeElement, TransitionImpl transition) {
200 //injectLogExecutionListener(activity);
204 public void parseSendTask(Element sendTaskElement, ScopeImpl scope, ActivityImpl activity) {
205 injectLogExecutionListener(activity);
209 public void parseMultiInstanceLoopCharacteristics(Element activityElement, Element multiInstanceLoopCharacteristicsElement, ActivityImpl activity) {
210 injectLogExecutionListener(activity);
214 public void parseIntermediateTimerEventDefinition(Element timerEventDefinition, ActivityImpl timerActivity) {
215 injectLogExecutionListener(timerActivity);
219 public void parseRootElement(Element rootElement, List<ProcessDefinitionEntity> processDefinitions) {
224 public void parseReceiveTask(Element receiveTaskElement, ScopeImpl scope, ActivityImpl activity) {
225 injectLogExecutionListener(activity);
229 public void parseIntermediateSignalCatchEventDefinition(Element signalEventDefinition, ActivityImpl signalActivity) {
230 injectLogExecutionListener(signalActivity);
234 public void parseBoundarySignalEventDefinition(Element signalEventDefinition, boolean interrupting, ActivityImpl signalActivity) {
235 injectLogExecutionListener(signalActivity);
239 public void parseEventBasedGateway(Element eventBasedGwElement, ScopeImpl scope, ActivityImpl activity) {
240 injectLogExecutionListener(activity);
244 public void parseTransaction(Element transactionElement, ScopeImpl scope, ActivityImpl activity) {
245 injectLogExecutionListener(activity);
249 public void parseCompensateEventDefinition(Element compensateEventDefinition, ActivityImpl compensationActivity) {
250 injectLogExecutionListener(compensationActivity);
254 public void parseIntermediateThrowEvent(Element intermediateEventElement, ScopeImpl scope, ActivityImpl activity) {
255 injectLogExecutionListener(activity);
259 public void parseIntermediateCatchEvent(Element intermediateEventElement, ScopeImpl scope, ActivityImpl activity) {
260 injectLogExecutionListener(activity);
264 public void parseBoundaryEvent(Element boundaryEventElement, ScopeImpl scopeElement, ActivityImpl nestedActivity) {
265 injectLogExecutionListener(nestedActivity);
269 public void parseIntermediateMessageCatchEventDefinition(Element messageEventDefinition, ActivityImpl nestedActivity) {
270 injectLogExecutionListener(nestedActivity);
274 public void parseBoundaryMessageEventDefinition(Element element, boolean interrupting, ActivityImpl messageActivity) {
275 injectLogExecutionListener(messageActivity);
280 * Logs details about the current activity.
282 public class LoggingExecutionListener implements ExecutionListener {
283 private final Logger logger = LoggerFactory.getLogger(LoggingExecutionListener.class);
285 private String event;
287 public LoggingExecutionListener() {
291 public LoggingExecutionListener(String event) {
295 public String getEvent() {
300 public void notify(DelegateExecution execution) throws Exception {
301 //required for legacy groovy processing in camunda
302 execution.setVariable("isDebugLogEnabled", "true");
303 if (!isBlank(execution.getCurrentActivityName())) {
306 String id = execution.getId();
308 RepositoryService repositoryService = execution.getProcessEngineServices().getRepositoryService();
309 String processName = repositoryService.createProcessDefinitionQuery()
310 .processDefinitionId(execution.getProcessDefinitionId())
315 String requestId = (String) execution.getVariable("mso-request-id");
316 String svcid = (String) execution.getVariable("mso-service-instance-id");
318 } catch(Exception e) {
319 logger.error("Exception occurred", e);
324 private boolean isBlank(Object object) {
325 return object == null || "".equals(object.toString().trim());