X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=otf-camunda%2Fsrc%2Fmain%2Fjava%2Forg%2Foran%2Fotf%2Fservice%2Fimpl%2FProcessInstanceCompletionServiceImpl.java;fp=otf-camunda%2Fsrc%2Fmain%2Fjava%2Forg%2Foran%2Fotf%2Fservice%2Fimpl%2FProcessInstanceCompletionServiceImpl.java;h=66e262bae84bd19e58faa3391531d9f1b8c3d1cf;hb=14f6f95c84a4a1fa8774190db4a03fd0214ec55f;hp=0000000000000000000000000000000000000000;hpb=f49bd1efeaaddd4891c1f329b18d8cfb28b3e75b;p=it%2Fotf.git diff --git a/otf-camunda/src/main/java/org/oran/otf/service/impl/ProcessInstanceCompletionServiceImpl.java b/otf-camunda/src/main/java/org/oran/otf/service/impl/ProcessInstanceCompletionServiceImpl.java new file mode 100644 index 0000000..66e262b --- /dev/null +++ b/otf-camunda/src/main/java/org/oran/otf/service/impl/ProcessInstanceCompletionServiceImpl.java @@ -0,0 +1,119 @@ +/* Copyright (c) 2019 AT&T Intellectual Property. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +##############################################################################*/ + + +package org.oran.otf.service.impl; + +import org.oran.otf.camunda.configuration.OtfCamundaConfiguration; +import org.oran.otf.common.model.local.OTFProcessInstanceCompletionResponse; +import org.oran.otf.common.utility.http.ResponseUtility; +import org.oran.otf.service.ProcessInstanceCompletionService; +import java.util.List; +import javax.ws.rs.core.Response; + +import org.camunda.bpm.BpmPlatform; +import org.camunda.bpm.engine.HistoryService; +import org.camunda.bpm.engine.ManagementService; +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.history.*; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Service; + +@Service +public class ProcessInstanceCompletionServiceImpl implements ProcessInstanceCompletionService { + + RuntimeService runtimeService; + + ManagementService managementService; + + HistoryService historyService; + + + + private ProcessInstanceCompletionServiceImpl() { + // prohibit instantiation + } + + @EventListener(ApplicationReadyEvent.class) + private void initialize(){ + if(this.runtimeService == null){ + this.runtimeService = BpmPlatform.getProcessEngineService().getProcessEngine(OtfCamundaConfiguration.processEngineName).getRuntimeService(); + } + if(this.managementService == null){ + this.managementService = BpmPlatform.getProcessEngineService().getProcessEngine(OtfCamundaConfiguration.processEngineName).getManagementService(); + } + if(this.historyService == null){ + this.historyService = BpmPlatform.getProcessEngineService().getProcessEngine(OtfCamundaConfiguration.processEngineName).getHistoryService(); + } + + } + + @Override + public Response isProcessInstanceComplete(String processInstanceId) { + + HistoricProcessInstance historicProcessInstance = historyService + .createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); + + List historicActivityInstance = historyService + .createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).list(); + + List historicIncident = + historyService.createHistoricIncidentQuery().processInstanceId(processInstanceId).list(); + + List historicJobLog = + historyService.createHistoricJobLogQuery().processInstanceId(processInstanceId).list(); + + List historicExternalTaskLog = + historyService.createHistoricExternalTaskLogQuery().processInstanceId(processInstanceId).list(); + + List historicVariableInstance = + historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list(); + + + + OTFProcessInstanceCompletionResponse response = new OTFProcessInstanceCompletionResponse(); + response.setHistoricProcessInstance(historicProcessInstance); + response.setHistoricActivityInstance(historicActivityInstance); + response.setHistoricIncident(historicIncident); + response.setHistoricJobLog(historicJobLog); + response.setHistoricExternalTaskLog(historicExternalTaskLog); + response.setHistoricVariableInstance(historicVariableInstance); + + + return ResponseUtility.Build.okRequestWithObject(response); + + // Boolean done = runtimeService +// .createProcessInstanceQuery() +// .processInstanceId(processInstanceId) +// .singleResult() == null; +// +// if(done) { +// return Response.ok(new ProcessInstanceCompletionResponse("Completed", "Process Instance Completed Execution")).build(); +// } +// +// +// Incident incident = runtimeService.createIncidentQuery().processInstanceId(processInstanceId).singleResult(); +// if(incident != null && incident.getIncidentType().equals("failedJob")) { +// String errorMessage = incident.getIncidentMessage(); +// return Response.ok(new ProcessInstanceCompletionResponse("Failed", errorMessage)).build(); +// } +// +// +// else { +// return Response.ok(new ProcessInstanceCompletionResponse("In Progress", "Process Instance is active")).build(); +// } + } +}