1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 package org.oran.otf.camunda.listener;
\r
19 import org.oran.otf.event.TestInstanceCompletionEvent;
\r
20 import com.google.gson.JsonObject;
\r
21 import org.camunda.bpm.engine.delegate.DelegateExecution;
\r
22 import org.camunda.bpm.engine.delegate.ExecutionListener;
\r
23 import org.camunda.bpm.extension.reactor.bus.CamundaSelector;
\r
24 import org.camunda.bpm.extension.reactor.spring.listener.ReactorExecutionListener;
\r
25 import org.camunda.bpm.model.bpmn.instance.EndEvent;
\r
26 import org.slf4j.Logger;
\r
27 import org.slf4j.LoggerFactory;
\r
28 import org.springframework.beans.factory.annotation.Autowired;
\r
29 import org.springframework.context.ApplicationEventPublisher;
\r
30 import org.springframework.stereotype.Component;
\r
33 @CamundaSelector(event = ExecutionListener.EVENTNAME_END)
\r
34 public class EndEventListener extends ReactorExecutionListener {
\r
36 private static Logger LOGGER = LoggerFactory.getLogger(EndEventListener.class);
\r
39 private ApplicationEventPublisher publisher;
\r
42 public void notify(DelegateExecution execution) {
\r
43 JsonObject jmsg = new JsonObject();
\r
44 jmsg.addProperty("executionId", execution.getProcessInstanceId());
\r
45 jmsg.addProperty("origin", "otf-camunda");
\r
46 if (execution.getBpmnModelElementInstance() instanceof EndEvent) {
\r
47 LOGGER.info(execution.getProcessInstanceId() + " is finished.");
\r
48 jmsg.addProperty("status", "completed");
\r
49 publisher.publishEvent(new TestInstanceCompletionEvent(this, jmsg, execution));
\r
53 private void onEndEvent(DelegateExecution execution) {
\r
57 private void onVthEnd(DelegateExecution execution) {
\r
58 // Useful for reporting back the result of a VTH
\r