org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity Java Examples

The following examples show how to use org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity. 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: EventSubscriptionDeclaration.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and inserts a subscription entity depending on the message type of this declaration.
 */
public EventSubscriptionEntity createSubscriptionForExecution(ExecutionEntity execution) {
  EventSubscriptionEntity eventSubscriptionEntity = new EventSubscriptionEntity(execution, eventType);

  String eventName = resolveExpressionOfEventName(execution);
  eventSubscriptionEntity.setEventName(eventName);
  if (activityId != null) {
    ActivityImpl activity = execution.getProcessDefinition().findActivity(activityId);
    eventSubscriptionEntity.setActivity(activity);
  }

  eventSubscriptionEntity.insert();
  LegacyBehavior.removeLegacySubscriptionOnParent(execution, eventSubscriptionEntity);

  return eventSubscriptionEntity;
}
 
Example #2
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public HistoryEvent createActivityInstanceEndEvt(DelegateExecution execution) {
  final ExecutionEntity executionEntity = (ExecutionEntity) execution;

  // create event instance
  HistoricActivityInstanceEventEntity evt = loadActivityInstanceEventEntity(executionEntity);
  evt.setActivityInstanceState(executionEntity.getActivityInstanceState());

  // initialize event
  initActivityInstanceEvent(evt, (ExecutionEntity) execution, HistoryEventTypes.ACTIVITY_INSTANCE_END);

  evt.setEndTime(ClockUtil.getCurrentTime());
  if(evt.getStartTime() != null) {
    evt.setDurationInMillis(evt.getEndTime().getTime()-evt.getStartTime().getTime());
  }

  return evt;
}
 
Example #3
Source File: DefaultHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void initActivityInstanceEvent(HistoricActivityInstanceEventEntity evt, ExecutionEntity execution, HistoryEventType eventType) {
  PvmScope eventSource = execution.getActivity();
  if (eventSource == null) {
    eventSource = (PvmScope) execution.getEventSource();
  }
  String activityInstanceId = execution.getActivityInstanceId();

  String parentActivityInstanceId = null;
  ExecutionEntity parentExecution = execution.getParent();

  if (parentExecution != null && CompensationBehavior.isCompensationThrowing(parentExecution) && execution.getActivity() != null) {
    parentActivityInstanceId = CompensationBehavior.getParentActivityInstanceId(execution);
  } else {
    parentActivityInstanceId = execution.getParentActivityInstanceId();
  }

  initActivityInstanceEvent(evt,
      execution,
      eventSource,
      activityInstanceId,
      parentActivityInstanceId,
      eventType);
}
 
Example #4
Source File: MigratingProcessInstance.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public MigratingActivityInstance addActivityInstance(
    MigrationInstruction migrationInstruction,
    ActivityInstance activityInstance,
    ScopeImpl sourceScope,
    ScopeImpl targetScope,
    ExecutionEntity scopeExecution) {

  MigratingActivityInstance migratingActivityInstance = new MigratingActivityInstance(
      activityInstance,
      migrationInstruction,
      sourceScope,
      targetScope,
      scopeExecution);

  migratingActivityInstances.add(migratingActivityInstance);

  if (processInstanceId.equals(activityInstance.getId())) {
    rootInstance = migratingActivityInstance;
  }

  return migratingActivityInstance;
}
 
Example #5
Source File: AsyncEndEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
    "org/camunda/bpm/engine/test/bpmn/async/AsyncEndEventTest.testCallActivity-super.bpmn20.xml",
    "org/camunda/bpm/engine/test/bpmn/async/AsyncEndEventTest.testCallActivity-sub.bpmn20.xml"
})
public void testCallActivity() {
  runtimeService.startProcessInstanceByKey("super");

  ProcessInstance pi = runtimeService
      .createProcessInstanceQuery()
      .processDefinitionKey("sub")
      .singleResult();

  assertTrue(pi instanceof ExecutionEntity);

  assertEquals("theSubEnd", ((ExecutionEntity)pi).getActivityId());

}
 
Example #6
Source File: InclusiveGatewayTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/** This test the isReachable() check thaty is done to check if
 * upstream tokens can reach the inclusive gateway.
 *
 * In case of loops, special care needs to be taken in the algorithm,
 * or else stackoverflows will happen very quickly.
 */
@Deployment
public void testLoop() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("inclusiveTestLoop",
          CollectionUtil.singletonMap("counter", 1));

  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("task C", task.getName());

  taskService.complete(task.getId());
  assertEquals(0, taskService.createTaskQuery().count());


  for (Execution execution : runtimeService.createExecutionQuery().list()) {
    System.out.println(((ExecutionEntity) execution).getActivityId());
  }

  assertEquals("Found executions: " + runtimeService.createExecutionQuery().list(), 0, runtimeService.createExecutionQuery().count());
  assertProcessEnded(pi.getId());
}
 
Example #7
Source File: DefaultDmnHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected HistoricDecisionInstanceEntity createDecisionEvaluatedEvt(DmnDecisionLogicEvaluationEvent evaluationEvent, ExecutionEntity execution) {
  // create event instance
  HistoricDecisionInstanceEntity event = newDecisionInstanceEventEntity(execution, evaluationEvent);
  setReferenceToProcessInstance(event, execution);

  if (isHistoryRemovalTimeStrategyStart()) {
    provideRemovalTime(event);
  }

  // initialize event
  initDecisionInstanceEvent(event, evaluationEvent, HistoryEventTypes.DMN_DECISION_EVALUATE);

  DecisionDefinition decisionDefinition = (DecisionDefinition) evaluationEvent.getDecision();
  String tenantId = execution.getTenantId();
  if (tenantId == null) {
    tenantId = provideTenantId(decisionDefinition, event);
  }
  event.setTenantId(tenantId);
  return event;
}
 
Example #8
Source File: RecorderExecutionListener.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void notify(DelegateExecution execution) throws Exception {
  ExecutionEntity executionCasted = ((ExecutionEntity)execution);
  String parameterValue = null;
  if (parameter != null) {
    parameterValue = (String)parameter.getValue(execution);
  }

  String activityName = null;
  if (executionCasted.getActivity() != null) {
    activityName = executionCasted.getActivity().getProperties().get(new PropertyKey<String>("name"));
  }

  recordedEvents.add( new RecordedEvent(
                  executionCasted.getActivityId(),
                  activityName,
                  execution.getEventName(),
                  parameterValue,
                  execution.getActivityInstanceId(),
                  execution.getCurrentTransitionId(),
                  execution.isCanceled(),
                  execution.getId()));
}
 
Example #9
Source File: TenantIdProviderTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void providerCalledWithExecution_BusinessRuleTasks() {

  ContextLoggingTenantIdProvider tenantIdProvider = new ContextLoggingTenantIdProvider();
  TestTenantIdProvider.delegate = tenantIdProvider;

  BpmnModelInstance process = Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY)
      .startEvent()
      .businessRuleTask()
        .camundaDecisionRef(DECISION_DEFINITION_KEY)
      .camundaAsyncAfter()
      .endEvent()
      .done();

  testRule.deploy(process, DMN_FILE);

  // if a process instance is started
  engineRule.getRuntimeService().startProcessInstanceByKey(PROCESS_DEFINITION_KEY, createVariables());
  Execution execution = engineRule.getRuntimeService().createExecutionQuery().processDefinitionKey(PROCESS_DEFINITION_KEY).singleResult();

  // then the tenant id provider is invoked
  assertThat(tenantIdProvider.dmnParameters.size(), is(1));
  ExecutionEntity passedExecution = (ExecutionEntity) tenantIdProvider.dmnParameters.get(0).getExecution();
  assertThat(passedExecution, is(notNullValue()));
  assertThat(passedExecution.getParent().getId(), is(execution.getId()));
}
 
Example #10
Source File: CompensationInstanceHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(MigratingInstanceParseContext parseContext, EventSubscriptionEntity element) {

  MigratingProcessElementInstance migratingInstance;
  if (element.getConfiguration() != null) {
    migratingInstance = createMigratingEventScopeInstance(parseContext, element);
  }
  else {
    migratingInstance = createMigratingEventSubscriptionInstance(parseContext, element);
  }


  ExecutionEntity owningExecution = element.getExecution();
  MigratingScopeInstance parentInstance = null;
  if (owningExecution.isEventScope()) {
    parentInstance = parseContext.getMigratingCompensationInstanceByExecutionId(owningExecution.getId());
  }
  else {
    parentInstance = parseContext.getMigratingActivityInstanceById(owningExecution.getParentActivityInstanceId());
  }
  migratingInstance.setParent(parentInstance);
}
 
Example #11
Source File: GetExecutionVariableTypedCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public T execute(CommandContext commandContext) {
  ensureNotNull("executionId", executionId);
  ensureNotNull("variableName", variableName);

  ExecutionEntity execution = commandContext
    .getExecutionManager()
    .findExecutionById(executionId);

  ensureNotNull("execution " + executionId + " doesn't exist", "execution", execution);

  checkGetExecutionVariableTyped(execution, commandContext);

  T value;

  if (isLocal) {
    value = execution.getVariableLocalTyped(variableName, deserializeValue);
  } else {
    value = execution.getVariableTyped(variableName, deserializeValue);
  }

  return value;
}
 
Example #12
Source File: DeleteProcessInstancesJobHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(BatchJobConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) {
  ByteArrayEntity configurationEntity = commandContext
      .getDbEntityManager()
      .selectById(ByteArrayEntity.class, configuration.getConfigurationByteArrayId());

  DeleteProcessInstanceBatchConfiguration batchConfiguration = readConfiguration(configurationEntity.getBytes());

  boolean initialLegacyRestrictions = commandContext.isRestrictUserOperationLogToAuthenticatedUsers();
  commandContext.disableUserOperationLog();
  commandContext.setRestrictUserOperationLogToAuthenticatedUsers(true);
  try {
    RuntimeService runtimeService = commandContext.getProcessEngineConfiguration().getRuntimeService();
    if(batchConfiguration.isFailIfNotExists()) {
      runtimeService.deleteProcessInstances(batchConfiguration.getIds(), batchConfiguration.deleteReason, batchConfiguration.isSkipCustomListeners(), true, batchConfiguration.isSkipSubprocesses());
    } else {
      runtimeService.deleteProcessInstancesIfExists(batchConfiguration.getIds(), batchConfiguration.deleteReason, batchConfiguration.isSkipCustomListeners(), true, batchConfiguration.isSkipSubprocesses());
    }
  } finally {
    commandContext.enableUserOperationLog();
    commandContext.setRestrictUserOperationLogToAuthenticatedUsers(initialLegacyRestrictions);
  }

  commandContext.getByteArrayManager().delete(configurationEntity);
}
 
Example #13
Source File: RecalculateJobDuedateCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected TimerDeclarationImpl findTimerDeclarationForActivity(CommandContext commandContext, JobEntity job) {
  ExecutionEntity execution = commandContext.getExecutionManager().findExecutionById(job.getExecutionId());
  if (execution == null) {
    throw new ProcessEngineException("No execution found with id '" + job.getExecutionId() + "' for job id '" + jobId + "'.");
  }
  ActivityImpl activity = execution.getProcessDefinition().findActivity(job.getActivityId());
  if (activity != null) {
    if (TimerTaskListenerJobHandler.TYPE.equals(job.getJobHandlerType())) {
      return findTimeoutListenerDeclaration(job, activity);
    }
    Map<String, TimerDeclarationImpl> timerDeclarations = TimerDeclarationImpl.getDeclarationsForScope(activity.getEventScope());
    if (!timerDeclarations.isEmpty() && timerDeclarations.containsKey(job.getActivityId())) {
      return  timerDeclarations.get(job.getActivityId());
    }
  }
  return null;
}
 
Example #14
Source File: ProcessScope.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public java.lang.Object get(java.lang.Object o) {

	Assert.isInstanceOf(String.class, o, "the 'key' must be a String");

	String varName = (String) o;

	ProcessInstance processInstance = Context.getExecutionContext().getProcessInstance();
	ExecutionEntity executionEntity = (ExecutionEntity) processInstance;
	if (executionEntity.getVariableNames().contains(varName)) {
		return executionEntity.getVariable(varName);
	}
	throw new RuntimeException("no processVariable by the name of '" + varName + "' is available!");
}
 
Example #15
Source File: ModificationUtil.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static void handleChildRemovalInScope(ExecutionEntity removedExecution) {
  ActivityImpl activity = removedExecution.getActivity();
  if (activity == null) {
    if (removedExecution.getSuperExecution() != null) {
      removedExecution = removedExecution.getSuperExecution();
      activity = removedExecution.getActivity();
      if (activity == null) {
        return;
      }
    } else {
      return;
    }
  }
  ScopeImpl flowScope = activity.getFlowScope();

  PvmExecutionImpl scopeExecution = removedExecution.getParentScopeExecution(false);
  PvmExecutionImpl executionInParentScope = removedExecution.isConcurrent() ? removedExecution : removedExecution.getParent();

  if (flowScope.getActivityBehavior() != null && flowScope.getActivityBehavior() instanceof ModificationObserverBehavior) {
    // let child removal be handled by the scope itself
    ModificationObserverBehavior behavior = (ModificationObserverBehavior) flowScope.getActivityBehavior();
    behavior.destroyInnerInstance(executionInParentScope);
  }
  else {
    if (executionInParentScope.isConcurrent()) {
      executionInParentScope.remove();
      scopeExecution.tryPruneLastConcurrentChild();
      scopeExecution.forceUpdate();
    }
  }
}
 
Example #16
Source File: VariableInstanceHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(MigratingInstanceParseContext parseContext, MigratingProcessElementInstance owningInstance, List<VariableInstanceEntity> variables) {

  ExecutionEntity representativeExecution = owningInstance.resolveRepresentativeExecution();

  for (VariableInstanceEntity variable : variables) {
    parseContext.consume(variable);
    boolean isConcurrentLocalInParentScope =
         (variable.getExecution() == representativeExecution.getParent() && variable.isConcurrentLocal())
      || representativeExecution.isConcurrent();
    owningInstance.addMigratingDependentInstance(new MigratingVariableInstance(variable, isConcurrentLocalInParentScope));
  }
}
 
Example #17
Source File: AddCommentCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ExecutionEntity getProcessInstance(CommandContext commandContext) {
  if (processInstanceId != null) {
    return commandContext.getExecutionManager().findExecutionById(processInstanceId);
  } else {
    return null;
  }
}
 
Example #18
Source File: MigratingExternalTaskInstance.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void attachState(MigratingScopeInstance owningInstance) {
  ExecutionEntity representativeExecution = owningInstance.resolveRepresentativeExecution();
  representativeExecution.addExternalTask(externalTask);

  externalTask.setExecution(representativeExecution);
}
 
Example #19
Source File: TestOrderingUtil.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static NullTolerantComparator<Execution> executionByProcessDefinitionId() {
  return propertyComparator(new PropertyAccessor<Execution, String>() {
    @Override
    public String getProperty(Execution obj) {
      return ((ExecutionEntity) obj).getProcessDefinitionId();
    }
  });
}
 
Example #20
Source File: ActivityInstanceUpdateListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected HistoryEvent createHistoryEvent(DelegateTask task, ExecutionEntity execution) {
  ensureHistoryLevelInitialized();
  if(historyLevel.isHistoryEventProduced(HistoryEventTypes.ACTIVITY_INSTANCE_UPDATE, execution)) {
    return eventProducer.createActivityInstanceUpdateEvt(execution, task);
  } else {
    return null;
  }
}
 
Example #21
Source File: MigratingEventScopeInstance.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an emerged scope
 */
public MigratingEventScopeInstance(
    EventSubscriptionEntity eventSubscription,
    ExecutionEntity eventScopeExecution,
    ScopeImpl targetScope
    ) {
  this.migratingEventSubscription =
      new MigratingCompensationEventSubscriptionInstance(null, null, targetScope, eventSubscription);
  this.eventScopeExecution = eventScopeExecution;

  // compensation handlers (not boundary events)
  // or parent flow scopes
  this.targetScope = targetScope;
  this.currentScope = targetScope;
}
 
Example #22
Source File: ExecutionEntityTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestoreProcessInstance() {
  //given parent execution
  List<ExecutionEntity> entities = new ArrayList<ExecutionEntity>();
  ExecutionEntity parent = new ExecutionEntity();
  parent.setId("parent");
  entities.add(parent);
  //when restore process instance is called
  parent.restoreProcessInstance(entities, null, null, null, null, null, null);
  //then no problem should occure

  //when child is added and restore is called again
  ExecutionEntity entity = new ExecutionEntity();
  entity.setId("child");
  entity.setParentId(parent.getId());
  entities.add(entity);

  parent.restoreProcessInstance(entities, null, null, null, null, null, null);
  //then again no problem should occure

  //when parent is deleted from the list
  entities.remove(parent);

  //then exception is thrown because child reference to parent which does not exist anymore
  thrown.expect(ProcessEngineException.class);
  thrown.expectMessage("Cannot resolve parent with id 'parent' of execution 'child', perhaps it was deleted in the meantime");
  parent.restoreProcessInstance(entities, null, null, null, null, null, null);
}
 
Example #23
Source File: ExecutionCachedEntityStateTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testExecutionExternalTask() {
  runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");

  ExecutionEntity execution = (ExecutionEntity) runtimeService
      .createExecutionQuery()
      .activityId("externalTask")
      .singleResult();

  assertEquals(BitMaskUtil.getMaskForBit(ExecutionEntity.EXTERNAL_TASKS_BIT), execution.getCachedEntityStateRaw());

}
 
Example #24
Source File: DefaultContextAssociationManager.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Execution getExecution() {
  ExecutionEntity execution = getExecutionFromContext();
  if(execution != null) {
    return execution;
  } else {
    return getScopedAssociation().getExecution();
  }
}
 
Example #25
Source File: TimerStartEventSubprocessJobHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void execute(TimerJobConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, String tenantId) {
  String activityId = configuration.getTimerElementKey();
  ActivityImpl eventSubprocessActivity = execution.getProcessDefinition()
    .findActivity(activityId);

  if(eventSubprocessActivity != null) {
    execution.executeEventHandlerActivity(eventSubprocessActivity);

  } else {
    throw new ProcessEngineException("Error while triggering event subprocess using timer start event: cannot find activity with id '"+configuration+"'.");
  }

}
 
Example #26
Source File: ExecutionCachedEntityStateTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testExecutionTasksParallel() {
  runtimeService.startProcessInstanceByKey("testProcess");

  ExecutionEntity processInstance = (ExecutionEntity) runtimeService.createProcessInstanceQuery().singleResult();
  assertEquals(0, processInstance.getCachedEntityStateRaw());

  ExecutionEntity execution = (ExecutionEntity) runtimeService.createExecutionQuery().activityId("userTask").singleResult();
  assertEquals(BitMaskUtil.getMaskForBit(ExecutionEntity.TASKS_STATE_BIT), execution.getCachedEntityStateRaw());

}
 
Example #27
Source File: CallActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void onParseMigratingInstance(MigratingInstanceParseContext parseContext, MigratingActivityInstance migratingInstance) {
  ActivityImpl callActivity = (ActivityImpl) migratingInstance.getSourceScope();

  // A call activity is typically scope and since we guarantee stability of scope executions during migration,
  // the superExecution link does not have to be maintained during migration.
  // There are some exceptions, though: A multi-instance call activity is not scope and therefore
  // does not have a dedicated scope execution. In this case, the link to the super execution
  // must be maintained throughout migration
  if (!callActivity.isScope()) {
    ExecutionEntity callActivityExecution = migratingInstance.resolveRepresentativeExecution();
    ExecutionEntity calledProcessInstance = callActivityExecution.getSubProcessInstance();
    migratingInstance.addMigratingDependentInstance(new MigratingCalledProcessInstance(calledProcessInstance));
  }
}
 
Example #28
Source File: MigrateProcessInstanceCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void ensureOperationAllowed(CommandContext commandContext,
                                      ExecutionEntity processInstance,
                                      ProcessDefinitionEntity targetProcessDefinition) {
  List<CommandChecker> commandCheckers = commandContext.getProcessEngineConfiguration()
      .getCommandCheckers();
  for(CommandChecker checker : commandCheckers) {
    checker.checkMigrateProcessInstance(processInstance, targetProcessDefinition);
  }
}
 
Example #29
Source File: MigratingActivityInstance.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void detachState() {
  ExecutionEntity currentExecution = resolveRepresentativeExecution();

  currentExecution.setActivity(null);
  currentExecution.leaveActivityInstance();
  currentExecution.setActive(false);

  getParent().destroyAttachableExecution(currentExecution);
}
 
Example #30
Source File: MigrateProcessInstanceCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void ensureSameProcessDefinition(ExecutionEntity processInstance,
                                           String processDefinitionId) {
  if (!processDefinitionId.equals(processInstance.getProcessDefinitionId())) {
    throw LOGGER.processDefinitionOfInstanceDoesNotMatchMigrationPlan(processInstance,
        processDefinitionId);
  }
}