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.service.impl;
\r
19 import org.oran.otf.camunda.configuration.OtfCamundaConfiguration;
\r
20 import org.oran.otf.common.model.local.OTFProcessInstanceCompletionResponse;
\r
21 import org.oran.otf.common.utility.http.ResponseUtility;
\r
22 import org.oran.otf.service.ProcessInstanceCompletionService;
\r
23 import java.util.List;
\r
24 import javax.ws.rs.core.Response;
\r
26 import org.camunda.bpm.BpmPlatform;
\r
27 import org.camunda.bpm.engine.HistoryService;
\r
28 import org.camunda.bpm.engine.ManagementService;
\r
29 import org.camunda.bpm.engine.RuntimeService;
\r
30 import org.camunda.bpm.engine.history.*;
\r
31 import org.springframework.boot.context.event.ApplicationReadyEvent;
\r
32 import org.springframework.context.event.EventListener;
\r
33 import org.springframework.stereotype.Service;
\r
36 public class ProcessInstanceCompletionServiceImpl implements ProcessInstanceCompletionService {
\r
38 RuntimeService runtimeService;
\r
40 ManagementService managementService;
\r
42 HistoryService historyService;
\r
46 private ProcessInstanceCompletionServiceImpl() {
\r
47 // prohibit instantiation
\r
50 @EventListener(ApplicationReadyEvent.class)
\r
51 private void initialize(){
\r
52 if(this.runtimeService == null){
\r
53 this.runtimeService = BpmPlatform.getProcessEngineService().getProcessEngine(OtfCamundaConfiguration.processEngineName).getRuntimeService();
\r
55 if(this.managementService == null){
\r
56 this.managementService = BpmPlatform.getProcessEngineService().getProcessEngine(OtfCamundaConfiguration.processEngineName).getManagementService();
\r
58 if(this.historyService == null){
\r
59 this.historyService = BpmPlatform.getProcessEngineService().getProcessEngine(OtfCamundaConfiguration.processEngineName).getHistoryService();
\r
65 public Response isProcessInstanceComplete(String processInstanceId) {
\r
67 HistoricProcessInstance historicProcessInstance = historyService
\r
68 .createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
\r
70 List<HistoricActivityInstance> historicActivityInstance = historyService
\r
71 .createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).list();
\r
73 List<HistoricIncident> historicIncident =
\r
74 historyService.createHistoricIncidentQuery().processInstanceId(processInstanceId).list();
\r
76 List<HistoricJobLog> historicJobLog =
\r
77 historyService.createHistoricJobLogQuery().processInstanceId(processInstanceId).list();
\r
79 List<HistoricExternalTaskLog> historicExternalTaskLog =
\r
80 historyService.createHistoricExternalTaskLogQuery().processInstanceId(processInstanceId).list();
\r
82 List<HistoricVariableInstance> historicVariableInstance =
\r
83 historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
\r
87 OTFProcessInstanceCompletionResponse response = new OTFProcessInstanceCompletionResponse();
\r
88 response.setHistoricProcessInstance(historicProcessInstance);
\r
89 response.setHistoricActivityInstance(historicActivityInstance);
\r
90 response.setHistoricIncident(historicIncident);
\r
91 response.setHistoricJobLog(historicJobLog);
\r
92 response.setHistoricExternalTaskLog(historicExternalTaskLog);
\r
93 response.setHistoricVariableInstance(historicVariableInstance);
\r
96 return ResponseUtility.Build.okRequestWithObject(response);
\r
98 // Boolean done = runtimeService
\r
99 // .createProcessInstanceQuery()
\r
100 // .processInstanceId(processInstanceId)
\r
101 // .singleResult() == null;
\r
104 // return Response.ok(new ProcessInstanceCompletionResponse("Completed", "Process Instance Completed Execution")).build();
\r
108 // Incident incident = runtimeService.createIncidentQuery().processInstanceId(processInstanceId).singleResult();
\r
109 // if(incident != null && incident.getIncidentType().equals("failedJob")) {
\r
110 // String errorMessage = incident.getIncidentMessage();
\r
111 // return Response.ok(new ProcessInstanceCompletionResponse("Failed", errorMessage)).build();
\r
116 // return Response.ok(new ProcessInstanceCompletionResponse("In Progress", "Process Instance is active")).build();
\r