All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.activiti.engine.impl.RuntimeServiceImpl Maven / Gradle / Ivy

There is a newer version: 3.0.Beta
Show newest version
/* 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.activiti.engine.impl;

import org.activiti.bpmn.model.FlowNode;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.delegate.event.ActivitiEventType;
import org.activiti.engine.impl.cmd.*;
import org.activiti.engine.impl.persistence.entity.VariableInstance;
import org.activiti.engine.impl.runtime.ProcessInstanceBuilderImpl;
import org.activiti.engine.runtime.*;
import org.activiti.engine.task.Event;
import org.activiti.engine.task.IdentityLink;
import org.activiti.engine.task.IdentityLinkType;

import java.util.*;


public class RuntimeServiceImpl extends ServiceImpl implements RuntimeService {

  public ProcessInstance startProcessInstanceByKey(String processDefinitionKey) {
    return commandExecutor.execute(new StartProcessInstanceCmd(processDefinitionKey, null, null, null));
  }

  public ProcessInstance startProcessInstanceByKey(String processDefinitionKey, String businessKey) {
    return commandExecutor.execute(new StartProcessInstanceCmd(processDefinitionKey, null, businessKey, null));
  }

  public ProcessInstance startProcessInstanceByKey(String processDefinitionKey, Map variables) {
    return commandExecutor.execute(new StartProcessInstanceCmd(processDefinitionKey, null, null, variables));
  }

  public ProcessInstance startProcessInstanceByKey(String processDefinitionKey, String businessKey, Map variables) {
    return commandExecutor.execute(new StartProcessInstanceCmd(processDefinitionKey, null, businessKey, variables));
  }

  public ProcessInstance startProcessInstanceByKeyAndTenantId(String processDefinitionKey, String tenantId) {
    return commandExecutor.execute(new StartProcessInstanceCmd(processDefinitionKey, null, null, null, tenantId));
  }

  public ProcessInstance startProcessInstanceByKeyAndTenantId(String processDefinitionKey, String businessKey, String tenantId) {
    return commandExecutor.execute(new StartProcessInstanceCmd(processDefinitionKey, null, businessKey, null, tenantId));
  }

  public ProcessInstance startProcessInstanceByKeyAndTenantId(String processDefinitionKey, Map variables, String tenantId) {
    return commandExecutor.execute(new StartProcessInstanceCmd(processDefinitionKey, null, null, variables, tenantId));
  }

  public ProcessInstance startProcessInstanceByKeyAndTenantId(String processDefinitionKey, String businessKey, Map variables, String tenantId) {
    return commandExecutor.execute(new StartProcessInstanceCmd(processDefinitionKey, null, businessKey, variables, tenantId));
  }

  public ProcessInstance startProcessInstanceById(String processDefinitionId) {
    return commandExecutor.execute(new StartProcessInstanceCmd(null, processDefinitionId, null, null));
  }

  public ProcessInstance startProcessInstanceById(String processDefinitionId, String businessKey) {
    return commandExecutor.execute(new StartProcessInstanceCmd(null, processDefinitionId, businessKey, null));
  }

  public ProcessInstance startProcessInstanceById(String processDefinitionId, Map variables) {
    return commandExecutor.execute(new StartProcessInstanceCmd(null, processDefinitionId, null, variables));
  }

  public ProcessInstance startProcessInstanceById(String processDefinitionId, String businessKey, Map variables) {
    return commandExecutor.execute(new StartProcessInstanceCmd(null, processDefinitionId, businessKey, variables));
  }

  public void deleteProcessInstance(String processInstanceId, String deleteReason) {
    commandExecutor.execute(new DeleteProcessInstanceCmd(processInstanceId, deleteReason));
  }

  public ExecutionQuery createExecutionQuery() {
    return new ExecutionQueryImpl(commandExecutor);
  }

  public NativeExecutionQuery createNativeExecutionQuery() {
    return new NativeExecutionQueryImpl(commandExecutor);
  }

  public NativeProcessInstanceQuery createNativeProcessInstanceQuery() {
    return new NativeProcessInstanceQueryImpl(commandExecutor);
  }

  public void updateBusinessKey(String processInstanceId, String businessKey) {
    commandExecutor.execute(new SetProcessInstanceBusinessKeyCmd(processInstanceId, businessKey));
  }

  public Map getVariables(String executionId) {
    return commandExecutor.execute(new GetExecutionVariablesCmd(executionId, null, false));
  }

  public Map getVariableInstances(String executionId) {
    return commandExecutor.execute(new GetExecutionVariableInstancesCmd(executionId, null, false));
  }
  
  public List getVariableInstancesByExecutionIds(Set executionIds) {
    return commandExecutor.execute(new GetExecutionsVariablesCmd(executionIds));
  }

  public Map getVariablesLocal(String executionId) {
    return commandExecutor.execute(new GetExecutionVariablesCmd(executionId, null, true));
  }
  
  public Map getVariableInstancesLocal(String executionId) {
    return commandExecutor.execute(new GetExecutionVariableInstancesCmd(executionId, null, true));
  }

  public Map getVariables(String executionId, Collection variableNames) {
    return commandExecutor.execute(new GetExecutionVariablesCmd(executionId, variableNames, false));
  }
  
  public Map getVariableInstances(String executionId, Collection variableNames) {
    return commandExecutor.execute(new GetExecutionVariableInstancesCmd(executionId, variableNames, false));
  }

  public Map getVariablesLocal(String executionId, Collection variableNames) {
    return commandExecutor.execute(new GetExecutionVariablesCmd(executionId, variableNames, true));
  }
  
  public Map getVariableInstancesLocal(String executionId, Collection variableNames) {
    return commandExecutor.execute(new GetExecutionVariableInstancesCmd(executionId, variableNames, true));
  }

  public Object getVariable(String executionId, String variableName) {
    return commandExecutor.execute(new GetExecutionVariableCmd(executionId, variableName, false));
  }
  
  public VariableInstance getVariableInstance(String executionId, String variableName) {
    return commandExecutor.execute(new GetExecutionVariableInstanceCmd(executionId, variableName, false));
  }

  public  T getVariable(String executionId, String variableName, Class variableClass) {
    return variableClass.cast(getVariable(executionId, variableName));
  }

  public boolean hasVariable(String executionId, String variableName) {
    return commandExecutor.execute(new HasExecutionVariableCmd(executionId, variableName, false));
  }

  public Object getVariableLocal(String executionId, String variableName) {
    return commandExecutor.execute(new GetExecutionVariableCmd(executionId, variableName, true));
  }
  
  public VariableInstance getVariableInstanceLocal(String executionId, String variableName) {
    return commandExecutor.execute(new GetExecutionVariableInstanceCmd(executionId, variableName, true));
  }

  public  T getVariableLocal(String executionId, String variableName, Class variableClass) {
    return variableClass.cast(getVariableLocal(executionId, variableName));
  }

  public boolean hasVariableLocal(String executionId, String variableName) {
    return commandExecutor.execute(new HasExecutionVariableCmd(executionId, variableName, true));
  }

  public void setVariable(String executionId, String variableName, Object value) {
    if (variableName == null) {
      throw new ActivitiIllegalArgumentException("variableName is null");
    }
    Map variables = new HashMap();
    variables.put(variableName, value);
    commandExecutor.execute(new SetExecutionVariablesCmd(executionId, variables, false));
  }

  public void setVariableLocal(String executionId, String variableName, Object value) {
    if (variableName == null) {
      throw new ActivitiIllegalArgumentException("variableName is null");
    }
    Map variables = new HashMap();
    variables.put(variableName, value);
    commandExecutor.execute(new SetExecutionVariablesCmd(executionId, variables, true));
  }

  public void setVariables(String executionId, Map variables) {
    commandExecutor.execute(new SetExecutionVariablesCmd(executionId, variables, false));
  }

  public void setVariablesLocal(String executionId, Map variables) {
    commandExecutor.execute(new SetExecutionVariablesCmd(executionId, variables, true));
  }

  public void removeVariable(String executionId, String variableName) {
    Collection variableNames = new ArrayList(1);
    variableNames.add(variableName);
    commandExecutor.execute(new RemoveExecutionVariablesCmd(executionId, variableNames, false));
  }

  public void removeVariableLocal(String executionId, String variableName) {
    Collection variableNames = new ArrayList();
    variableNames.add(variableName);
    commandExecutor.execute(new RemoveExecutionVariablesCmd(executionId, variableNames, true));
  }

  public void removeVariables(String executionId, Collection variableNames) {
    commandExecutor.execute(new RemoveExecutionVariablesCmd(executionId, variableNames, false));
  }

  public void removeVariablesLocal(String executionId, Collection variableNames) {
    commandExecutor.execute(new RemoveExecutionVariablesCmd(executionId, variableNames, true));
  }
  
  @Override
  public Map getDataObjects(String executionId) {
    return commandExecutor.execute(new GetDataObjectsCmd(executionId, null, false));
  }

  @Override
  public Map getDataObjects(String executionId, String locale, boolean withLocalizationFallback) {
    return commandExecutor.execute(new GetDataObjectsCmd(executionId, null, false, locale, withLocalizationFallback));
  }

  @Override
  public Map getDataObjectsLocal(String executionId) {
    return commandExecutor.execute(new GetDataObjectsCmd(executionId, null, true));
  }

  @Override
  public Map getDataObjectsLocal(String executionId, String locale, boolean withLocalizationFallback) {
    return commandExecutor.execute(new GetDataObjectsCmd(executionId, null, true, locale, withLocalizationFallback));
  }

  @Override
  public Map getDataObjects(String executionId, Collection dataObjectNames) {
    return commandExecutor.execute(new GetDataObjectsCmd(executionId, dataObjectNames, false));
  }

  @Override
  public Map getDataObjects(String executionId, Collection dataObjectNames, String locale, boolean withLocalizationFallback) {
    return commandExecutor.execute(new GetDataObjectsCmd(executionId, dataObjectNames, false, locale, withLocalizationFallback));
  }

  @Override
  public Map getDataObjectsLocal(String executionId, Collection dataObjects) {
    return commandExecutor.execute(new GetDataObjectsCmd(executionId, dataObjects, true));
  }

  @Override
  public Map getDataObjectsLocal(String executionId, Collection dataObjectNames, String locale, boolean withLocalizationFallback) {
    return commandExecutor.execute(new GetDataObjectsCmd(executionId, dataObjectNames, true, locale, withLocalizationFallback));
  }

  @Override
  public DataObject getDataObject(String executionId, String dataObject) {
    return commandExecutor.execute(new GetDataObjectCmd(executionId, dataObject, false));
  }

  @Override
  public DataObject getDataObject(String executionId, String dataObjectName, String locale, boolean withLocalizationFallback) {
    return commandExecutor.execute(new GetDataObjectCmd(executionId, dataObjectName, false, locale, withLocalizationFallback));
  }

  @Override
  public DataObject getDataObjectLocal(String executionId, String dataObjectName) {
    return commandExecutor.execute(new GetDataObjectCmd(executionId, dataObjectName, true));
  }

  @Override
  public DataObject getDataObjectLocal(String executionId, String dataObjectName, String locale, boolean withLocalizationFallback) {
    return commandExecutor.execute(new GetDataObjectCmd(executionId, dataObjectName, true, locale, withLocalizationFallback));
  }

  public void signal(String executionId) {
    commandExecutor.execute(new TriggerCmd(executionId, null));
  }

  @Override
  public void trigger(String executionId) {
    commandExecutor.execute(new TriggerCmd(executionId, null));
  }

  public void signal(String executionId, Map processVariables) {
    commandExecutor.execute(new TriggerCmd(executionId, processVariables));
  }

  public void trigger(String executionId, Map processVariables) {
    commandExecutor.execute(new TriggerCmd(executionId, processVariables));
  }
  
  public void trigger(String executionId, Map processVariables, Map transientVariables) {
    commandExecutor.execute(new TriggerCmd(executionId, processVariables, transientVariables));    
  }

  public void addUserIdentityLink(String processInstanceId, String userId, String identityLinkType) {
    commandExecutor.execute(new AddIdentityLinkForProcessInstanceCmd(processInstanceId, userId, null, identityLinkType));
  }

  public void addGroupIdentityLink(String processInstanceId, String groupId, String identityLinkType) {
    commandExecutor.execute(new AddIdentityLinkForProcessInstanceCmd(processInstanceId, null, groupId, identityLinkType));
  }

  public void addParticipantUser(String processInstanceId, String userId) {
    commandExecutor.execute(new AddIdentityLinkForProcessInstanceCmd(processInstanceId, userId, null, IdentityLinkType.PARTICIPANT));
  }

  public void addParticipantGroup(String processInstanceId, String groupId) {
    commandExecutor.execute(new AddIdentityLinkForProcessInstanceCmd(processInstanceId, null, groupId, IdentityLinkType.PARTICIPANT));
  }

  public void deleteParticipantUser(String processInstanceId, String userId) {
    commandExecutor.execute(new DeleteIdentityLinkForProcessInstanceCmd(processInstanceId, userId, null, IdentityLinkType.PARTICIPANT));
  }

  public void deleteParticipantGroup(String processInstanceId, String groupId) {
    commandExecutor.execute(new DeleteIdentityLinkForProcessInstanceCmd(processInstanceId, null, groupId, IdentityLinkType.PARTICIPANT));
  }

  public void deleteUserIdentityLink(String processInstanceId, String userId, String identityLinkType) {
    commandExecutor.execute(new DeleteIdentityLinkForProcessInstanceCmd(processInstanceId, userId, null, identityLinkType));
  }

  public void deleteGroupIdentityLink(String processInstanceId, String groupId, String identityLinkType) {
    commandExecutor.execute(new DeleteIdentityLinkForProcessInstanceCmd(processInstanceId, null, groupId, identityLinkType));
  }

  public List getIdentityLinksForProcessInstance(String processInstanceId) {
    return commandExecutor.execute(new GetIdentityLinksForProcessInstanceCmd(processInstanceId));
  }

  public ProcessInstanceQuery createProcessInstanceQuery() {
    return new ProcessInstanceQueryImpl(commandExecutor);
  }

  public List getActiveActivityIds(String executionId) {
    return commandExecutor.execute(new FindActiveActivityIdsCmd(executionId));
  }

  public void suspendProcessInstanceById(String processInstanceId) {
    commandExecutor.execute(new SuspendProcessInstanceCmd(processInstanceId));
  }

  public void activateProcessInstanceById(String processInstanceId) {
    commandExecutor.execute(new ActivateProcessInstanceCmd(processInstanceId));
  }

  public ProcessInstance startProcessInstanceByMessage(String messageName) {
    return commandExecutor.execute(new StartProcessInstanceByMessageCmd(messageName, null, null, null));
  }

  public ProcessInstance startProcessInstanceByMessageAndTenantId(String messageName, String tenantId) {
    return commandExecutor.execute(new StartProcessInstanceByMessageCmd(messageName, null, null, tenantId));
  }

  public ProcessInstance startProcessInstanceByMessage(String messageName, String businessKey) {
    return commandExecutor.execute(new StartProcessInstanceByMessageCmd(messageName, businessKey, null, null));
  }

  public ProcessInstance startProcessInstanceByMessageAndTenantId(String messageName, String businessKey, String tenantId) {
    return commandExecutor.execute(new StartProcessInstanceByMessageCmd(messageName, businessKey, null, tenantId));
  }

  public ProcessInstance startProcessInstanceByMessage(String messageName, Map processVariables) {
    return commandExecutor.execute(new StartProcessInstanceByMessageCmd(messageName, null, processVariables, null));
  }

  public ProcessInstance startProcessInstanceByMessageAndTenantId(String messageName, Map processVariables, String tenantId) {
    return commandExecutor.execute(new StartProcessInstanceByMessageCmd(messageName, null, processVariables, tenantId));
  }

  public ProcessInstance startProcessInstanceByMessage(String messageName, String businessKey, Map processVariables) {
    return commandExecutor.execute(new StartProcessInstanceByMessageCmd(messageName, businessKey, processVariables, null));
  }

  @Override
  public ProcessInstance startProcessInstanceByMessageAndTenantId(String messageName, String businessKey, Map processVariables, String tenantId) {
    return commandExecutor.execute(new StartProcessInstanceByMessageCmd(messageName, businessKey, processVariables, tenantId));
  }

  public void signalEventReceived(String signalName) {
    commandExecutor.execute(new SignalEventReceivedCmd(signalName, null, null, null));
  }

  public void signalEventReceivedWithTenantId(String signalName, String tenantId) {
    commandExecutor.execute(new SignalEventReceivedCmd(signalName, null, null, tenantId));
  }

  public void signalEventReceivedAsync(String signalName) {
    commandExecutor.execute(new SignalEventReceivedCmd(signalName, null, true, null));
  }

  public void signalEventReceivedAsyncWithTenantId(String signalName, String tenantId) {
    commandExecutor.execute(new SignalEventReceivedCmd(signalName, null, true, tenantId));
  }

  public void signalEventReceived(String signalName, Map processVariables) {
    commandExecutor.execute(new SignalEventReceivedCmd(signalName, null, processVariables, null));
  }

  public void signalEventReceivedWithTenantId(String signalName, Map processVariables, String tenantId) {
    commandExecutor.execute(new SignalEventReceivedCmd(signalName, null, processVariables, tenantId));
  }

  public void signalEventReceived(String signalName, String executionId) {
    commandExecutor.execute(new SignalEventReceivedCmd(signalName, executionId, null, null));
  }

  public void signalEventReceived(String signalName, String executionId, Map processVariables) {
    commandExecutor.execute(new SignalEventReceivedCmd(signalName, executionId, processVariables, null));
  }

  public void signalEventReceivedAsync(String signalName, String executionId) {
    commandExecutor.execute(new SignalEventReceivedCmd(signalName, executionId, true, null));
  }

  public void messageEventReceived(String messageName, String executionId) {
    commandExecutor.execute(new MessageEventReceivedCmd(messageName, executionId, null));
  }

  public void messageEventReceived(String messageName, String executionId, Map processVariables) {
    commandExecutor.execute(new MessageEventReceivedCmd(messageName, executionId, processVariables));
  }

  public void messageEventReceivedAsync(String messageName, String executionId) {
    commandExecutor.execute(new MessageEventReceivedCmd(messageName, executionId, true));
  }

  @Override
  public void addEventListener(ActivitiEventListener listenerToAdd) {
    commandExecutor.execute(new AddEventListenerCommand(listenerToAdd));
  }

  @Override
  public void addEventListener(ActivitiEventListener listenerToAdd, ActivitiEventType... types) {
    commandExecutor.execute(new AddEventListenerCommand(listenerToAdd, types));
  }

  @Override
  public void removeEventListener(ActivitiEventListener listenerToRemove) {
    commandExecutor.execute(new RemoveEventListenerCommand(listenerToRemove));
  }

  @Override
  public void dispatchEvent(ActivitiEvent event) {
    commandExecutor.execute(new DispatchEventCommand(event));
  }

  @Override
  public void setProcessInstanceName(String processInstanceId, String name) {
    commandExecutor.execute(new SetProcessInstanceNameCmd(processInstanceId, name));
  }

  @Override
  public List getProcessInstanceEvents(String processInstanceId) {
    return commandExecutor.execute(new GetProcessInstanceEventsCmd(processInstanceId));
  }
  
  @Override
  public List getEnabledActivitiesFromAdhocSubProcess(String executionId) {
    return commandExecutor.execute(new GetEnabledActivitiesForAdhocSubProcessCmd(executionId));
  }
  
  @Override
  public Execution executeActivityInAdhocSubProcess(String executionId, String activityId) {
    return commandExecutor.execute(new ExecuteActivityForAdhocSubProcessCmd(executionId, activityId));
  }
  
  @Override
  public void completeAdhocSubProcess(String executionId) {
    commandExecutor.execute(new CompleteAdhocSubProcessCmd(executionId));
  }

  @Override
  public ProcessInstanceBuilder createProcessInstanceBuilder() {
    return new ProcessInstanceBuilderImpl(this);
  }

  public ProcessInstance startProcessInstance(ProcessInstanceBuilderImpl processInstanceBuilder) {
    if (processInstanceBuilder.getProcessDefinitionId() != null || processInstanceBuilder.getProcessDefinitionKey() != null) {
      return commandExecutor.execute(new StartProcessInstanceCmd(processInstanceBuilder));
    } else if (processInstanceBuilder.getMessageName() != null) {
      return commandExecutor.execute(new StartProcessInstanceByMessageCmd(processInstanceBuilder));
    } else {
      throw new ActivitiIllegalArgumentException("No processDefinitionId, processDefinitionKey nor messageName provided");
    }
    
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy