added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / main / java / org / oran / otf / camunda / listener / EndEventListener.java
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\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
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\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
15 \r
16 \r
17 package org.oran.otf.camunda.listener;\r
18 \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
31 \r
32 @Component\r
33 @CamundaSelector(event = ExecutionListener.EVENTNAME_END)\r
34 public class EndEventListener extends ReactorExecutionListener {\r
35 \r
36   private static Logger LOGGER = LoggerFactory.getLogger(EndEventListener.class);\r
37 \r
38   @Autowired\r
39   private ApplicationEventPublisher publisher;\r
40 \r
41   @Override\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
50     }\r
51   }\r
52 \r
53   private void onEndEvent(DelegateExecution execution) {\r
54 \r
55   }\r
56 \r
57   private void onVthEnd(DelegateExecution execution) {\r
58     // Useful for reporting back the result of a VTH\r
59   }\r
60 }\r