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.camunda.exception.TestExecutionException;
\r
20 import org.oran.otf.camunda.model.ExecutionConstants;
\r
21 import org.oran.otf.camunda.workflow.utility.WorkflowUtility;
\r
22 import org.oran.otf.common.model.TestExecution;
\r
23 import org.oran.otf.common.repository.TestExecutionRepository;
\r
24 import org.oran.otf.common.utility.Utility;
\r
25 import com.google.gson.JsonObject;
\r
26 import com.mongodb.client.result.UpdateResult;
\r
27 import org.camunda.bpm.engine.delegate.DelegateExecution;
\r
28 import org.camunda.bpm.engine.delegate.ExecutionListener;
\r
29 import org.camunda.bpm.extension.reactor.bus.CamundaSelector;
\r
30 import org.camunda.bpm.extension.reactor.spring.listener.ReactorExecutionListener;
\r
31 import org.camunda.bpm.model.bpmn.instance.StartEvent;
\r
32 import org.slf4j.Logger;
\r
33 import org.slf4j.LoggerFactory;
\r
34 import org.springframework.beans.factory.annotation.Autowired;
\r
35 import org.springframework.data.mongodb.core.MongoTemplate;
\r
36 import org.springframework.data.mongodb.core.query.Criteria;
\r
37 import org.springframework.data.mongodb.core.query.Query;
\r
38 import org.springframework.data.mongodb.core.query.Update;
\r
39 import org.springframework.stereotype.Component;
\r
42 @CamundaSelector(event = ExecutionListener.EVENTNAME_END)
\r
43 public class StartEventListener extends ReactorExecutionListener {
\r
46 WorkflowUtility utility;
\r
49 MongoTemplate mongoOperation;
\r
51 private static Logger LOGGER = LoggerFactory.getLogger(StartEventListener.class);
\r
54 public void notify(DelegateExecution execution) {
\r
55 if (execution.getBpmnModelElementInstance() instanceof StartEvent) {
\r
56 LOGGER.info(execution.getProcessInstanceId() + " has started.");
\r
57 //setTestResult(execution, ExecutionConstants.TestResult.STARTED);
\r
61 private void onStartEvent(DelegateExecution execution) {
\r
64 private void onVthStart(DelegateExecution execution) {
\r
65 // Useful for reporting back the exact parameters being sent to the VTH as they can be modified
\r
69 private void setTestResult(DelegateExecution execution, String result){
\r
70 // Get the current test execution object.
\r
71 final String logPrefix = Utility.getLoggerPrefix();
\r
73 TestExecution testExecution =
\r
74 utility.getExecutionVariable(
\r
75 execution.getVariables(), ExecutionConstants.ExecutionVariable.TEST_EXECUTION, TestExecution.class);
\r
76 // Perform a null-check to ensure it is available. It's critical to throw an exception if it
\r
77 // is not available since the object is essential for results.
\r
78 if (testExecution == null) {
\r
79 LOGGER.error(logPrefix + "Test execution is null.");
\r
80 throw new TestExecutionException("The test execution was not found.");
\r
82 execution.setVariable(ExecutionConstants.ExecutionVariable.TEST_RESULT, result);
\r
84 testExecution.setTestResult(result);
\r
85 testExecution.setProcessInstanceId(execution.getProcessInstanceId());
\r
87 Query query = new Query();
\r
88 //TODO: Update needs new query for Azure
\r
89 query.addCriteria((Criteria.where("groupId").is(testExecution.getGroupId())));
\r
90 query.addCriteria(Criteria.where("businessKey").is(execution.getProcessBusinessKey()));
\r
91 Update update = new Update();
\r
92 update.set("testResult", testExecution.getTestResult());
\r
93 update.set("processInstanceId", execution.getProcessInstanceId());
\r
94 UpdateResult updateResult = mongoOperation.updateFirst(query, update, TestExecution.class);
\r