2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.core.plugins;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.HashMap;
27 import java.util.Iterator;
28 import java.util.List;
30 import java.util.Map.Entry;
31 import java.util.Properties;
32 import java.util.concurrent.ConcurrentHashMap;
34 import org.camunda.bpm.engine.RepositoryService;
35 import org.camunda.bpm.engine.delegate.DelegateExecution;
36 import org.camunda.bpm.engine.delegate.ExecutionListener;
37 import org.camunda.bpm.engine.impl.bpmn.parser.AbstractBpmnParseListener;
38 import org.camunda.bpm.engine.impl.bpmn.parser.BpmnParseListener;
39 import org.camunda.bpm.engine.impl.cfg.AbstractProcessEnginePlugin;
40 import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
41 import org.camunda.bpm.engine.impl.context.Context;
42 import org.camunda.bpm.engine.impl.interceptor.Command;
43 import org.camunda.bpm.engine.impl.interceptor.CommandContext;
44 import org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity;
45 import org.camunda.bpm.engine.impl.pvm.process.ActivityImpl;
46 import org.camunda.bpm.engine.impl.pvm.process.ScopeImpl;
47 import org.camunda.bpm.engine.impl.pvm.process.TransitionImpl;
48 import org.camunda.bpm.engine.impl.util.xml.Element;
49 import org.camunda.bpm.engine.impl.variable.VariableDeclaration;
50 import org.camunda.bpm.model.bpmn.impl.instance.FlowNodeImpl;
51 import org.camunda.bpm.model.bpmn.instance.EndEvent;
52 import org.camunda.bpm.model.bpmn.instance.FlowNode;
53 import org.camunda.bpm.model.bpmn.instance.StartEvent;
54 import org.onap.so.bpmn.core.BPMNLogger;
57 import org.onap.so.logger.MessageEnum;
58 import org.onap.so.logger.MsoLogger;
60 import org.springframework.beans.factory.annotation.Autowired;
61 import org.springframework.core.env.AbstractEnvironment;
62 import org.springframework.core.env.Environment;
63 import org.springframework.core.env.MapPropertySource;
64 import org.springframework.core.env.PropertySource;
65 import org.springframework.stereotype.Component;
70 * Plugin for MSO logging and URN mapping.
73 public class LoggingAndURNMappingPlugin extends AbstractProcessEnginePlugin {
76 private LoggingParseListener loggingParseListener;
80 ProcessEngineConfigurationImpl processEngineConfiguration) {
81 List<BpmnParseListener> preParseListeners = processEngineConfiguration
82 .getCustomPreBPMNParseListeners();
83 if (preParseListeners == null) {
84 preParseListeners = new ArrayList<>();
85 processEngineConfiguration.setCustomPreBPMNParseListeners(preParseListeners);
87 preParseListeners.add(loggingParseListener);
91 * Called when a process flow is parsed so we can inject listeners.
94 public class LoggingParseListener extends AbstractBpmnParseListener {
97 private void injectLogExecutionListener(ActivityImpl activity) {
99 ExecutionListener.EVENTNAME_END,
100 new LoggingExecutionListener("END"));
102 activity.addListener(
103 ExecutionListener.EVENTNAME_START,
104 new LoggingExecutionListener("START"));
106 activity.addListener(
107 ExecutionListener.EVENTNAME_TAKE,
108 new LoggingExecutionListener("TAKE"));
112 public void parseProcess(Element processElement, ProcessDefinitionEntity processDefinition) {
116 public void parseStartEvent(Element startEventElement, ScopeImpl scope, ActivityImpl startEventActivity) {
117 // Inject these listeners only on the main start event for the flow, not on any embedded subflow start events
119 injectLogExecutionListener(startEventActivity);
123 public void parseServiceTask(Element serviceTaskElement, ScopeImpl scope, ActivityImpl activity) {
124 injectLogExecutionListener(activity);
128 public void parseExclusiveGateway(Element exclusiveGwElement, ScopeImpl scope, ActivityImpl activity) {
129 injectLogExecutionListener(activity);
133 public void parseInclusiveGateway(Element inclusiveGwElement, ScopeImpl scope, ActivityImpl activity) {
134 injectLogExecutionListener(activity);
138 public void parseParallelGateway(Element parallelGwElement, ScopeImpl scope, ActivityImpl activity) {
139 injectLogExecutionListener(activity);
143 public void parseScriptTask(Element scriptTaskElement, ScopeImpl scope, ActivityImpl activity) {
144 injectLogExecutionListener(activity);
148 public void parseBusinessRuleTask(Element businessRuleTaskElement, ScopeImpl scope, ActivityImpl activity) {
149 injectLogExecutionListener(activity);
153 public void parseTask(Element taskElement, ScopeImpl scope, ActivityImpl activity) {
154 injectLogExecutionListener(activity);
158 public void parseManualTask(Element manualTaskElement, ScopeImpl scope, ActivityImpl activity) {
159 injectLogExecutionListener(activity);
163 public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity) {
164 injectLogExecutionListener(activity);
168 public void parseEndEvent(Element endEventElement, ScopeImpl scope, ActivityImpl activity) {
169 injectLogExecutionListener(activity);
173 public void parseBoundaryTimerEventDefinition(Element timerEventDefinition, boolean interrupting, ActivityImpl timerActivity) {
174 injectLogExecutionListener(timerActivity);
178 public void parseBoundaryErrorEventDefinition(Element errorEventDefinition, boolean interrupting, ActivityImpl activity, ActivityImpl nestedErrorEventActivity) {
179 injectLogExecutionListener(activity);
183 public void parseSubProcess(Element subProcessElement, ScopeImpl scope, ActivityImpl activity) {
184 injectLogExecutionListener(activity);
188 public void parseCallActivity(Element callActivityElement, ScopeImpl scope, ActivityImpl activity) {
189 injectLogExecutionListener(activity);
193 public void parseProperty(Element propertyElement, VariableDeclaration variableDeclaration, ActivityImpl activity) {
194 injectLogExecutionListener(activity);
198 public void parseSequenceFlow(Element sequenceFlowElement, ScopeImpl scopeElement, TransitionImpl transition) {
202 public void parseSendTask(Element sendTaskElement, ScopeImpl scope, ActivityImpl activity) {
203 injectLogExecutionListener(activity);
207 public void parseMultiInstanceLoopCharacteristics(Element activityElement, Element multiInstanceLoopCharacteristicsElement, ActivityImpl activity) {
208 injectLogExecutionListener(activity);
212 public void parseIntermediateTimerEventDefinition(Element timerEventDefinition, ActivityImpl timerActivity) {
213 injectLogExecutionListener(timerActivity);
217 public void parseRootElement(Element rootElement, List<ProcessDefinitionEntity> processDefinitions) {
222 public void parseReceiveTask(Element receiveTaskElement, ScopeImpl scope, ActivityImpl activity) {
223 injectLogExecutionListener(activity);
227 public void parseIntermediateSignalCatchEventDefinition(Element signalEventDefinition, ActivityImpl signalActivity) {
228 injectLogExecutionListener(signalActivity);
232 public void parseBoundarySignalEventDefinition(Element signalEventDefinition, boolean interrupting, ActivityImpl signalActivity) {
233 injectLogExecutionListener(signalActivity);
237 public void parseEventBasedGateway(Element eventBasedGwElement, ScopeImpl scope, ActivityImpl activity) {
238 injectLogExecutionListener(activity);
242 public void parseTransaction(Element transactionElement, ScopeImpl scope, ActivityImpl activity) {
243 injectLogExecutionListener(activity);
247 public void parseCompensateEventDefinition(Element compensateEventDefinition, ActivityImpl compensationActivity) {
248 injectLogExecutionListener(compensationActivity);
252 public void parseIntermediateThrowEvent(Element intermediateEventElement, ScopeImpl scope, ActivityImpl activity) {
253 injectLogExecutionListener(activity);
257 public void parseIntermediateCatchEvent(Element intermediateEventElement, ScopeImpl scope, ActivityImpl activity) {
258 injectLogExecutionListener(activity);
262 public void parseBoundaryEvent(Element boundaryEventElement, ScopeImpl scopeElement, ActivityImpl nestedActivity) {
263 injectLogExecutionListener(nestedActivity);
267 public void parseIntermediateMessageCatchEventDefinition(Element messageEventDefinition, ActivityImpl nestedActivity) {
268 injectLogExecutionListener(nestedActivity);
272 public void parseBoundaryMessageEventDefinition(Element element, boolean interrupting, ActivityImpl messageActivity) {
273 injectLogExecutionListener(messageActivity);
278 * Logs details about the current activity.
280 public class LoggingExecutionListener implements ExecutionListener {
281 private final MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,LoggingExecutionListener.class);
283 private String event;
285 public LoggingExecutionListener() {
289 public LoggingExecutionListener(String event) {
293 public String getEvent() {
298 public void notify(DelegateExecution execution) throws Exception {
299 //required for legacy groovy processing in camunda
300 execution.setVariable("isDebugLogEnabled", "true");
301 if (!isBlank(execution.getCurrentActivityName())) {
304 String id = execution.getId();
306 RepositoryService repositoryService = execution.getProcessEngineServices().getRepositoryService();
307 String processName = repositoryService.createProcessDefinitionQuery()
308 .processDefinitionId(execution.getProcessDefinitionId())
312 MsoLogger.setServiceName(processName);
313 String requestId = (String) execution.getVariable("mso-request-id");
314 String svcid = (String) execution.getVariable("mso-service-instance-id");
315 MsoLogger.setLogContext(requestId, svcid);
317 } catch(Exception e) {
323 private boolean isBlank(Object object) {
324 return object == null || "".equals(object.toString().trim());