Java Code Examples for org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity#createProcessInstance()

The following examples show how to use org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity#createProcessInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignalEventHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void handleStartEvent(EventSubscriptionEntity eventSubscription, Map<String, Object> payload, String businessKey, CommandContext commandContext) {
  String processDefinitionId = eventSubscription.getConfiguration();
  ensureNotNull("Configuration of signal start event subscription '" + eventSubscription.getId() + "' contains no process definition id.",
      processDefinitionId);

  DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache();
  ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
  if (processDefinition == null || processDefinition.isSuspended()) {
    // ignore event subscription
    LOG.debugIgnoringEventSubscription(eventSubscription, processDefinitionId);
  } else {
    ActivityImpl signalStartEvent = processDefinition.findActivity(eventSubscription.getActivityId());
    PvmProcessInstance processInstance = processDefinition.createProcessInstance(businessKey, signalStartEvent);
    processInstance.start(payload);
  }
}
 
Example 2
Source File: EvaluateStartConditionCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ProcessInstance instantiateProcess(CommandContext commandContext, ConditionHandlerResult result) {
  ProcessDefinitionEntity processDefinitionEntity = result.getProcessDefinition();

  ActivityImpl startEvent = processDefinitionEntity.findActivity(result.getActivity().getActivityId());
  ExecutionEntity processInstance = processDefinitionEntity.createProcessInstance(builder.getBusinessKey(), startEvent);
  processInstance.start(builder.getVariables());

  return processInstance;
}
 
Example 3
Source File: StartProcessInstanceCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public ProcessInstanceWithVariables execute(CommandContext commandContext) {

    ProcessDefinitionEntity processDefinition = new GetDeployedProcessDefinitionCmd(instantiationBuilder, false).execute(commandContext);

    for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
      checker.checkCreateProcessInstance(processDefinition);
    }

    // Start the process instance
    ExecutionEntity processInstance = processDefinition.createProcessInstance(instantiationBuilder.getBusinessKey(),
        instantiationBuilder.getCaseInstanceId());

    if (instantiationBuilder.getTenantId() != null) {
      processInstance.setTenantId(instantiationBuilder.getTenantId());
    }

    final ExecutionVariableSnapshotObserver variablesListener = new ExecutionVariableSnapshotObserver(processInstance);

    processInstance.start(instantiationBuilder.getVariables());

    commandContext.getOperationLogManager().logProcessInstanceOperation(
        UserOperationLogEntry.OPERATION_TYPE_CREATE,
        processInstance.getId(),
        processInstance.getProcessDefinitionId(),
        processInstance.getProcessDefinition().getKey(),
        Collections.singletonList(PropertyChange.EMPTY_CHANGE));

    return new ProcessInstanceWithVariablesImpl(processInstance, variablesListener.getVariables());
  }
 
Example 4
Source File: SubmitStartFormCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessInstance execute(CommandContext commandContext) {
  ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
  DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache();
  ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
  ensureNotNull("No process definition found for id = '" + processDefinitionId + "'", "processDefinition", processDefinition);

  for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
    checker.checkCreateProcessInstance(processDefinition);
  }

  ExecutionEntity processInstance = null;
  if (businessKey != null) {
    processInstance = processDefinition.createProcessInstance(businessKey);
  } else {
    processInstance = processDefinition.createProcessInstance();
  }

  // if the start event is async, we have to set the variables already here
  // since they are lost after the async continuation otherwise
  // see CAM-2828
  if (processDefinition.getInitial().isAsyncBefore()) {
    // avoid firing history events
    processInstance.setStartContext(new ProcessInstanceStartContext(processInstance.getActivity()));
    FormPropertyHelper.initFormPropertiesOnScope(variables, processInstance);
    processInstance.start();

  } else {
    processInstance.startWithFormProperties(variables);

  }


  return processInstance;
}
 
Example 5
Source File: StartProcessInstanceAtActivitiesCmd.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public ProcessInstanceWithVariables execute(CommandContext commandContext) {

    ProcessDefinitionEntity processDefinition = new GetDeployedProcessDefinitionCmd(instantiationBuilder, false).execute(commandContext);

    for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
      checker.checkCreateProcessInstance(processDefinition);
    }

    ProcessInstanceModificationBuilderImpl modificationBuilder = instantiationBuilder.getModificationBuilder();
    ensureNotEmpty("At least one instantiation instruction required (e.g. by invoking startBefore(..), startAfter(..) or startTransition(..))",
        "instructions", modificationBuilder.getModificationOperations());

    // instantiate the process
    ActivityImpl initialActivity = determineFirstActivity(processDefinition, modificationBuilder);

    ExecutionEntity processInstance = processDefinition
        .createProcessInstance(instantiationBuilder.getBusinessKey(), instantiationBuilder.getCaseInstanceId(), initialActivity);

    if (instantiationBuilder.getTenantId() != null) {
      processInstance.setTenantId(instantiationBuilder.getTenantId());
    }

    processInstance.setSkipCustomListeners(modificationBuilder.isSkipCustomListeners());
    VariableMap variables = modificationBuilder.getProcessVariables();

    final ExecutionVariableSnapshotObserver variablesListener = new ExecutionVariableSnapshotObserver(processInstance);

    processInstance.startWithoutExecuting(variables);

    // prevent ending of the process instance between instructions
    processInstance.setPreserveScope(true);

    // apply modifications
    List<AbstractProcessInstanceModificationCommand> instructions = modificationBuilder.getModificationOperations();

    for (int i = 0; i < instructions.size(); i++) {
      AbstractProcessInstanceModificationCommand instruction = instructions.get(i);
      LOG.debugStartingInstruction(processInstance.getId(), i, instruction.describe());

      instruction.setProcessInstanceId(processInstance.getId());
      instruction.setSkipCustomListeners(modificationBuilder.isSkipCustomListeners());
      instruction.setSkipIoMappings(modificationBuilder.isSkipIoMappings());
      instruction.execute(commandContext);
    }

    if (!processInstance.hasChildren() && processInstance.isEnded()) {
      // process instance has ended regularly but this has not been propagated yet
      // due to preserveScope setting
      processInstance.propagateEnd();
    }

    commandContext.getOperationLogManager().logProcessInstanceOperation(
        UserOperationLogEntry.OPERATION_TYPE_CREATE,
        processInstance.getId(),
        processInstance.getProcessDefinitionId(),
        processInstance.getProcessDefinition().getKey(),
        Collections.singletonList(PropertyChange.EMPTY_CHANGE),
        modificationBuilder.getAnnotation());

    return new ProcessInstanceWithVariablesImpl(processInstance, variablesListener.getVariables());
  }
 
Example 6
Source File: AbstractCorrelateMessageCmd.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected ProcessInstance instantiateProcess(CommandContext commandContext, CorrelationHandlerResult correlationResult) {
  ProcessDefinitionEntity processDefinitionEntity = correlationResult.getProcessDefinitionEntity();

  ActivityImpl messageStartEvent = processDefinitionEntity.findActivity(correlationResult.getStartEventActivityId());
  ExecutionEntity processInstance = processDefinitionEntity.createProcessInstance(builder.getBusinessKey(), messageStartEvent);

  if (variablesEnabled) {
    variablesListener = new ExecutionVariableSnapshotObserver(processInstance, false, deserializeVariableValues);
  }

  VariableMap startVariables = resolveStartVariables();

  processInstance.start(startVariables);

  return processInstance;
}