Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.bndly.common.bpm.impl;
/*-
* #%L
* BPM Impl
* %%
* Copyright (C) 2013 - 2020 Cybercon GmbH
* %%
* 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.
* #L%
*/
import org.bndly.common.bpm.annotation.ReturnVariable;
import org.bndly.common.bpm.api.BusinessProcess;
import org.bndly.common.bpm.api.ProcessDeploymentService;
import org.bndly.common.bpm.api.ProcessInstance;
import org.bndly.common.bpm.api.ProcessInstanceService;
import org.bndly.common.bpm.api.ProcessInvocationListener;
import org.bndly.common.bpm.api.ProcessVariable;
import org.bndly.common.bpm.api.ProcessVariableAdapter;
import org.bndly.common.bpm.api.ReturnValueHandler;
import org.bndly.common.bpm.api.TypedProcessVariable;
import org.bndly.common.bpm.exception.ProcessDeploymentException;
import org.bndly.common.bpm.impl.privateapi.UltimateEventHandler;
import org.bndly.common.bpm.exception.ProcessErrorException;
import org.bndly.common.bpm.exception.ProcessInvocationException;
import static org.bndly.common.bpm.impl.ProcessInvoker.PROCESS_INSTANCE_PROCESS_NAME_VAR;
import static org.bndly.common.bpm.impl.ProcessInvoker.UNIQUE_PROCESS_INSTANCE_ID_VAR;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.locks.ReadWriteLock;
import org.activiti.engine.ActivitiObjectNotFoundException;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.BpmnError;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricVariableInstance;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.runtime.Execution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProcessInstanceServiceImpl implements ProcessInstanceService, ProcessVariableAdapter {
private static final Logger LOG = LoggerFactory.getLogger(ProcessInstanceServiceImpl.class);
private HistoryService historyService;
private RuntimeService runtimeService;
private EventHandlerRegistry eventHandlerRegistry;
private ProcessDeploymentService processDeploymentService;
private final List processVariableAdapters = new ArrayList<>();
private final List listeners;
private final ReadWriteLock lock;
private static final ThreadLocal currentEventHandlerRegistry = new ThreadLocal<>();
public ProcessInstanceServiceImpl(List listeners, ReadWriteLock lock) {
this.listeners = listeners;
this.lock = lock;
}
/**
* returns the current event handler registry based on the current thread.
*
* @return the current event handler registry or null, when called from another thread than the one that called startProcess or resumeProcess.
*/
public static EventHandlerRegistry getCurrentEventHandlerRegistry() {
return currentEventHandlerRegistry.get();
}
@Override
public void registerVariableAdapter(ProcessVariableAdapter processVariableAdapter) {
if (processVariableAdapter != null) {
processVariableAdapters.add(processVariableAdapter);
}
}
@Override
public void unregisterVariableAdapter(ProcessVariableAdapter processVariableAdapter) {
Iterator iterator = processVariableAdapters.iterator();
while (iterator.hasNext()) {
ProcessVariableAdapter next = iterator.next();
if (next == processVariableAdapter) {
iterator.remove();
}
}
}
@Override
public List listProcessInstances(int offset, int size) {
List result = new ArrayList<>();
List historicInstances = historyService.createHistoricProcessInstanceQuery().orderByProcessInstanceStartTime().desc().listPage(offset, size);
if (historicInstances != null) {
for (HistoricProcessInstance historicProcessInstance : historicInstances) {
result.add(mapActivitiProcessInstance(historicProcessInstance));
}
}
return result;
}
@Override
public ProcessInstanceImpl startProcess(String processName, Collection processVariables, ReturnValueHandler returnValueHandler) {
try {
currentEventHandlerRegistry.set(eventHandlerRegistry);
Map params = convertProcessVariablesToMap(processVariables);
BusinessProcess deployedProcess = processDeploymentService.getDeployedProcessByProcessName(processName);
boolean isDeployedProcess = deployedProcess != null;
String id;
if (!isDeployedProcess) {
LOG.info("auto deploying process {}, because it is not deployed already", processName);
try {
deployedProcess = processDeploymentService.autoDeploy(processName);
if (deployedProcess == null) {
throw new ProcessInvocationException("could not auto deploy process '" + processName + "'");
}
} catch (ProcessDeploymentException e) {
throw new ProcessInvocationException("could not auto deploy process '" + processName + "'", e);
}
}
id = deployedProcess.getId();
String uniqueProcessInstanceId = UUID.randomUUID().toString();
params.put(UNIQUE_PROCESS_INSTANCE_ID_VAR, uniqueProcessInstanceId);
params.put(PROCESS_INSTANCE_PROCESS_NAME_VAR, processName);
final ObjectReferenceHolder errorEndHolder = new ObjectReferenceHolder<>();
final ObjectReferenceHolder processInstanceIdHolder = new ObjectReferenceHolder<>();
final ObjectReferenceHolder