added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / main / java / org / oran / otf / camunda / listener / EndEventListener.java
diff --git a/otf-camunda/src/main/java/org/oran/otf/camunda/listener/EndEventListener.java b/otf-camunda/src/main/java/org/oran/otf/camunda/listener/EndEventListener.java
new file mode 100644 (file)
index 0000000..f886000
--- /dev/null
@@ -0,0 +1,60 @@
+/*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
+#                                                                              #\r
+#   Licensed under the Apache License, Version 2.0 (the "License");            #\r
+#   you may not use this file except in compliance with the License.           #\r
+#   You may obtain a copy of the License at                                    #\r
+#                                                                              #\r
+#       http://www.apache.org/licenses/LICENSE-2.0                             #\r
+#                                                                              #\r
+#   Unless required by applicable law or agreed to in writing, software        #\r
+#   distributed under the License is distributed on an "AS IS" BASIS,          #\r
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
+#   See the License for the specific language governing permissions and        #\r
+#   limitations under the License.                                             #\r
+##############################################################################*/\r
+\r
+\r
+package org.oran.otf.camunda.listener;\r
+\r
+import org.oran.otf.event.TestInstanceCompletionEvent;\r
+import com.google.gson.JsonObject;\r
+import org.camunda.bpm.engine.delegate.DelegateExecution;\r
+import org.camunda.bpm.engine.delegate.ExecutionListener;\r
+import org.camunda.bpm.extension.reactor.bus.CamundaSelector;\r
+import org.camunda.bpm.extension.reactor.spring.listener.ReactorExecutionListener;\r
+import org.camunda.bpm.model.bpmn.instance.EndEvent;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.context.ApplicationEventPublisher;\r
+import org.springframework.stereotype.Component;\r
+\r
+@Component\r
+@CamundaSelector(event = ExecutionListener.EVENTNAME_END)\r
+public class EndEventListener extends ReactorExecutionListener {\r
+\r
+  private static Logger LOGGER = LoggerFactory.getLogger(EndEventListener.class);\r
+\r
+  @Autowired\r
+  private ApplicationEventPublisher publisher;\r
+\r
+  @Override\r
+  public void notify(DelegateExecution execution) {\r
+    JsonObject jmsg = new JsonObject();\r
+    jmsg.addProperty("executionId", execution.getProcessInstanceId());\r
+    jmsg.addProperty("origin", "otf-camunda");\r
+    if (execution.getBpmnModelElementInstance() instanceof EndEvent) {\r
+      LOGGER.info(execution.getProcessInstanceId() + " is finished.");\r
+      jmsg.addProperty("status", "completed");\r
+      publisher.publishEvent(new TestInstanceCompletionEvent(this, jmsg, execution));\r
+    }\r
+  }\r
+\r
+  private void onEndEvent(DelegateExecution execution) {\r
+\r
+  }\r
+\r
+  private void onVthEnd(DelegateExecution execution) {\r
+    // Useful for reporting back the result of a VTH\r
+  }\r
+}\r