org.camunda.bpm.engine.impl.pvm.process.ActivityImpl Java Examples

The following examples show how to use org.camunda.bpm.engine.impl.pvm.process.ActivityImpl. 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: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * This returns true only if the provided execution has reached its wait state in a legacy engine version, because
 * only in that case, it can be async and waiting at the inner activity wrapped by the miBody. In versions >= 7.3,
 * the execution would reference the multi-instance body instead.
 */
protected static boolean isLegacyAsyncAtMultiInstance(PvmExecutionImpl execution) {
  ActivityImpl activity = execution.getActivity();

  if (activity != null) {
    boolean isAsync = execution.getActivityInstanceId() == null;
    boolean isAtMultiInstance = activity.getParentFlowScopeActivity() != null
        && activity.getParentFlowScopeActivity().getActivityBehavior() instanceof MultiInstanceActivityBehavior;


    return isAsync && isAtMultiInstance;
  }
  else {
    return false;
  }
}
 
Example #2
Source File: ConditionalEventHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, Object localPayload, String businessKey, CommandContext commandContext) {
  VariableEvent variableEvent;
  if (payload == null || payload instanceof VariableEvent) {
    variableEvent = (VariableEvent) payload;
  } else {
    throw new ProcessEngineException("Payload have to be " + VariableEvent.class.getName() + ", to evaluate condition.");
  }

  ActivityImpl activity = eventSubscription.getActivity();
  ActivityBehavior activityBehavior = activity.getActivityBehavior();
  if (activityBehavior instanceof ConditionalEventBehavior) {
    ConditionalEventBehavior conditionalBehavior = (ConditionalEventBehavior) activityBehavior;
    conditionalBehavior.leaveOnSatisfiedCondition(eventSubscription, variableEvent);
  } else {
    throw new ProcessEngineException("Conditional Event has not correct behavior: " + activityBehavior);
  }
}
 
Example #3
Source File: CompensationInstanceHandler.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected MigratingProcessElementInstance createMigratingEventSubscriptionInstance(MigratingInstanceParseContext parseContext,
    EventSubscriptionEntity element) {
  ActivityImpl compensationHandler = parseContext.getSourceProcessDefinition().findActivity(element.getActivityId());

  MigrationInstruction migrationInstruction = getMigrationInstruction(parseContext, compensationHandler);

  ActivityImpl targetScope = null;
  if (migrationInstruction != null) {
    ActivityImpl targetEventScope = (ActivityImpl) parseContext.getTargetActivity(migrationInstruction).getEventScope();
    targetScope = targetEventScope.findCompensationHandler();
  }

  MigratingCompensationEventSubscriptionInstance migratingCompensationInstance =
      parseContext.getMigratingProcessInstance().addCompensationSubscriptionInstance(
          migrationInstruction,
          element,
          compensationHandler,
          targetScope);

  parseContext.consume(element);

  return migratingCompensationInstance;
}
 
Example #4
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 #5
Source File: AbstractBpmnActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void createCompensateEventSubscription(ActivityExecution execution, ActivityImpl compensationHandler) {
  // the compensate event subscription is created at subprocess or miBody of the the current activity
  PvmActivity currentActivity = execution.getActivity();
  ActivityExecution scopeExecution = execution.findExecutionForFlowScope(currentActivity.getFlowScope());

  EventSubscriptionEntity.createAndInsert((ExecutionEntity) scopeExecution, EventType.COMPENSATE, compensationHandler);
}
 
Example #6
Source File: FoxFailedJobParseListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testMultiInstanceBodyWithFailedJobRetryTimeCycle() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("process");

  ActivityImpl miBody = findMultiInstanceBody(pi, "task");
  checkFoxFailedJobConfig(miBody);

  ActivityImpl innerActivity = findActivity(pi, "task");
  checkNotContainingFoxFailedJobConfig(innerActivity);
}
 
Example #7
Source File: GatewayMappingValidator.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void validateSingleInstruction(ValidatingMigrationInstruction instruction, ValidatingMigrationInstructions instructions,
    MigrationInstructionValidationReportImpl report) {
  ActivityImpl targetActivity = instruction.getTargetActivity();
  List<ValidatingMigrationInstruction> instructionsToTargetGateway =
      instructions.getInstructionsByTargetScope(targetActivity);

  if (instructionsToTargetGateway.size() > 1) {
    report.addFailure("Only one gateway can be mapped to gateway '" + targetActivity.getId() + "'");
  }
}
 
Example #8
Source File: BpmnParseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ActivityImpl findActivityInDeployedProcessDefinition(String activityId) {
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
  assertNotNull(processDefinition);

  ProcessDefinitionEntity cachedProcessDefinition = processEngineConfiguration.getDeploymentCache()
                                                      .getProcessDefinitionCache()
                                                      .get(processDefinition.getId());
  return cachedProcessDefinition.findActivity(activityId);
}
 
Example #9
Source File: JobDefinitionCreationBothAsyncWithParseListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessEngineConfiguration configureEngine(ProcessEngineConfigurationImpl configuration) {
  List<BpmnParseListener> listeners = new ArrayList<>();
  listeners.add(new AbstractBpmnParseListener(){

    @Override
    public void parseServiceTask(Element serviceTaskElement, ScopeImpl scope, ActivityImpl activity) {
      activity.setAsyncBefore(true);
      activity.setAsyncAfter(true);
    }
  });

  configuration.setCustomPreBPMNParseListeners(listeners);
  return configuration;
}
 
Example #10
Source File: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * When executing an async job for an activity wrapped in an miBody, set the execution to the
 * miBody except the wrapped activity is marked as async.
 *
 * Background: in <= 7.2 async jobs were created for the inner activity, although the
 * semantics are that they are executed before the miBody is entered
 */
public static void repairMultiInstanceAsyncJob(ExecutionEntity execution) {
  ActivityImpl activity = execution.getActivity();

  if (!isAsync(activity) && isActivityWrappedInMultiInstanceBody(activity)) {
    execution.setActivity((ActivityImpl) activity.getFlowScope());
  }
}
 
Example #11
Source File: DefaultConditionHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected List<ActivityImpl> findConditionalStartEventActivities(ProcessDefinitionEntity processDefinition) {
  List<ActivityImpl> activities = new ArrayList<ActivityImpl>();
  for (EventSubscriptionDeclaration declaration : ConditionalEventDefinition.getDeclarationsForScope(processDefinition).values()) {
    if (isConditionStartEvent(declaration)) {
      activities.add(((ConditionalEventDefinition) declaration).getConditionalActivity());
    }
  }
  return activities;
}
 
Example #12
Source File: MigratingInstanceParseContext.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public ActivityImpl getTargetActivity(MigrationInstruction instruction) {
  if (instruction != null) {
    return targetProcessDefinition.findActivity(instruction.getTargetActivityId());
  }
  else {
    return null;
  }
}
 
Example #13
Source File: BpmnParseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
@Test
public void testParseEventSubprocessConditionalStartEvent() {
  ActivityImpl conditionalStartEventSubProcess = findActivityInDeployedProcessDefinition("conditionalStartEventSubProcess");

  assertEquals(ActivityTypes.START_EVENT_CONDITIONAL, conditionalStartEventSubProcess.getProperties().get(BpmnProperties.TYPE));
  assertEquals(EventSubProcessStartConditionalEventActivityBehavior.class, conditionalStartEventSubProcess.getActivityBehavior().getClass());

}
 
Example #14
Source File: BpmnParseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
@Test
public void testParseSignalStartEvent(){
  ActivityImpl signalStartActivity = findActivityInDeployedProcessDefinition("start");

  assertEquals(ActivityTypes.START_EVENT_SIGNAL, signalStartActivity.getProperty("type"));
  assertEquals(NoneStartEventActivityBehavior.class, signalStartActivity.getActivityBehavior().getClass());
}
 
Example #15
Source File: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected static boolean isActivityWrappedInMultiInstanceBody(ActivityImpl activity) {
  ScopeImpl flowScope = activity.getFlowScope();

  if (flowScope != activity.getProcessDefinition()) {
    ActivityImpl flowScopeActivity = (ActivityImpl) flowScope;

    return flowScopeActivity.getActivityBehavior() instanceof MultiInstanceActivityBehavior;
  } else {
    return false;
  }
}
 
Example #16
Source File: CannotRemoveMultiInstanceInnerActivityValidator.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(ValidatingMigrationInstruction instruction, ValidatingMigrationInstructions instructions,
    MigrationInstructionValidationReportImpl report) {
  ActivityImpl sourceActivity = instruction.getSourceActivity();

  if (isMultiInstance(sourceActivity)) {
    ActivityImpl innerActivity = getInnerActivity(sourceActivity);

    if (instructions.getInstructionsBySourceScope(innerActivity).isEmpty()) {
      report.addFailure("Cannot remove the inner activity of a multi-instance body when the body is mapped");
    }
  }
}
 
Example #17
Source File: MigratingEventScopeInstance.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void migrateState() {
  migratingEventSubscription.migrateState();

  eventScopeExecution.setActivity((ActivityImpl) targetScope);
  eventScopeExecution.setProcessDefinition(targetScope.getProcessDefinition());

  currentScope = targetScope;
}
 
Example #18
Source File: FoxFailedJobParseListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testInnerMultiInstanceActivityWithFailedJobRetryTimeCycle() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("process");

  ActivityImpl miBody = findMultiInstanceBody(pi, "task");
  checkNotContainingFoxFailedJobConfig(miBody);

  ActivityImpl innerActivity = findActivity(pi, "task");
  checkFoxFailedJobConfig(innerActivity);
}
 
Example #19
Source File: ProcessDefinitionEntity.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ExecutionEntity createProcessInstance(String businessKey, String caseInstanceId, ActivityImpl initial) {
  ensureNotSuspended();

  ExecutionEntity processInstance = (ExecutionEntity) createProcessInstanceForInitial(initial);

  // do not reset executions (CAM-2557)!
  // processInstance.setExecutions(new ArrayList<ExecutionEntity>());

  processInstance.setProcessDefinition(processDefinition);

  // Do not initialize variable map (let it happen lazily)

  // reset the process instance in order to have the db-generated process instance id available
  processInstance.setProcessInstance(processInstance);

  // initialize business key
  if (businessKey != null) {
    processInstance.setBusinessKey(businessKey);
  }

  // initialize case instance id
  if (caseInstanceId != null) {
    processInstance.setCaseInstanceId(caseInstanceId);
  }

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

  return processInstance;
}
 
Example #20
Source File: FoxFailedJobParseListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ActivityImpl findActivity(ProcessInstance pi, String activityId) {

    ProcessInstanceWithVariablesImpl entity = (ProcessInstanceWithVariablesImpl) pi;
    ProcessDefinitionEntity processDefEntity = entity.getExecutionEntity().getProcessDefinition();

    assertNotNull(processDefEntity);
    ActivityImpl activity = processDefEntity.findActivity(activityId);
    assertNotNull(activity);
    return activity;
  }
 
Example #21
Source File: BpmnParseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
@Test
public void testParseEscalationEndEvent() {
  ActivityImpl escalationEndEvent = findActivityInDeployedProcessDefinition("escalationEndEvent");

  assertEquals(ActivityTypes.END_EVENT_ESCALATION, escalationEndEvent.getProperties().get(BpmnProperties.TYPE));
  assertEquals(ThrowEscalationEventActivityBehavior.class, escalationEndEvent.getActivityBehavior().getClass());
}
 
Example #22
Source File: BpmnParseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
@Test
public void testParseAsyncMultiInstanceBody(){
  ActivityImpl innerTask = findActivityInDeployedProcessDefinition("miTask");
  ActivityImpl miBody = innerTask.getParentFlowScopeActivity();

  assertTrue(miBody.isAsyncBefore());
  assertTrue(miBody.isAsyncAfter());

  assertFalse(innerTask.isAsyncBefore());
  assertFalse(innerTask.isAsyncAfter());
}
 
Example #23
Source File: OutputVariablesPropagator.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(ActivityExecution execution) {

  if (isProcessInstanceOfSubprocess(execution)) {

    PvmExecutionImpl superExecution = (PvmExecutionImpl) execution.getSuperExecution();
    ActivityImpl activity = superExecution.getActivity();
    SubProcessActivityBehavior subProcessActivityBehavior = (SubProcessActivityBehavior) activity.getActivityBehavior();

    subProcessActivityBehavior.passOutputVariables(superExecution, execution);
  }
}
 
Example #24
Source File: BpmnParseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
@Test
public void testParseCompensationStartEvent() {
  ActivityImpl compensationStartEvent = findActivityInDeployedProcessDefinition("compensationStartEvent");

  assertEquals("compensationStartEvent", compensationStartEvent.getProperty("type"));
  assertEquals(EventSubProcessStartEventActivityBehavior.class, compensationStartEvent.getActivityBehavior().getClass());

  ActivityImpl compensationEventSubProcess = (ActivityImpl) compensationStartEvent.getFlowScope();
  assertEquals(Boolean.TRUE, compensationEventSubProcess.getProperty(BpmnParse.PROPERTYNAME_IS_FOR_COMPENSATION));

  ScopeImpl subprocess = compensationEventSubProcess.getFlowScope();
  assertEquals(compensationEventSubProcess.getActivityId(), subprocess.getProperty(BpmnParse.PROPERTYNAME_COMPENSATION_HANDLER_ID));
}
 
Example #25
Source File: FoxFailedJobParseListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/parse/FoxFailedJobParseListenerTest.testTimer.bpmn20.xml" })
public void testIntermediateCatchTimerEventWithFailedJobRetryTimeCycle() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("intermediateTimerEventWithFailedJobRetryTimeCycle");

  ActivityImpl timer = findActivity(pi, "timerEventWithFailedJobRetryTimeCycle");
  checkFoxFailedJobConfig(timer);
}
 
Example #26
Source File: SupportedActivityInstanceValidator.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(MigratingActivityInstance migratingInstance, MigratingProcessInstance migratingProcessInstance,
    MigratingActivityInstanceValidationReportImpl instanceReport) {

  ScopeImpl sourceScope = migratingInstance.getSourceScope();

  if (sourceScope != sourceScope.getProcessDefinition()) {
    ActivityImpl sourceActivity = (ActivityImpl) migratingInstance.getSourceScope();

    if (!SupportedActivityValidator.INSTANCE.isSupportedActivity(sourceActivity)) {
      instanceReport.addFailure("The type of the source activity is not supported for activity instance migration");
    }
  }
}
 
Example #27
Source File: AsyncProcessStartMigrationValidator.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(MigratingTransitionInstance migratingInstance, MigratingProcessInstance migratingProcessInstance,
    MigratingTransitionInstanceValidationReportImpl instanceReport) {

  ActivityImpl targetActivity = (ActivityImpl) migratingInstance.getTargetScope();

  if (targetActivity != null) {
    if (isProcessStartJob(migratingInstance.getJobInstance().getJobEntity()) && !isTopLevelActivity(targetActivity)) {
      instanceReport.addFailure("A transition instance that instantiates the process can only be migrated to a process-level flow node");
    }
  }
}
 
Example #28
Source File: PublishDelegateParseListener.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
@Override
public void parseScriptTask(Element scriptTaskElement, ScopeImpl scope, ActivityImpl activity) {
  addExecutionListener(activity);
}
 
Example #29
Source File: RegisterAllBpmnParseListener.java    From camunda-bpm-reactor with Apache License 2.0 4 votes vote down vote up
@Override
public void parseExclusiveGateway(final Element exclusiveGwElement, final ScopeImpl scope, final ActivityImpl activity) {
  addExecutionListener(activity);
}
 
Example #30
Source File: RegisterAllBpmnParseListener.java    From camunda-bpm-reactor with Apache License 2.0 4 votes vote down vote up
@Override
public void parseBoundaryTimerEventDefinition(final Element timerEventDefinition, final boolean interrupting, final ActivityImpl activity) {
  addExecutionListener(activity);
}