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

The following examples show how to use org.camunda.bpm.engine.impl.pvm.process.ScopeImpl. 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: MigratingProcessInstance.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public MigratingEventScopeInstance addEventScopeInstance(
    MigrationInstruction migrationInstruction,
    ExecutionEntity eventScopeExecution,
    ScopeImpl sourceScope,
    ScopeImpl targetScope,
    MigrationInstruction eventSubscriptionInstruction,
    EventSubscriptionEntity eventSubscription,
    ScopeImpl eventSubscriptionSourceScope,
    ScopeImpl eventSubscriptionTargetScope) {

  MigratingEventScopeInstance compensationInstance = new MigratingEventScopeInstance(
      migrationInstruction,
      eventScopeExecution,
      sourceScope,
      targetScope,
      eventSubscriptionInstruction,
      eventSubscription,
      eventSubscriptionSourceScope,
      eventSubscriptionTargetScope);

  migratingEventScopeInstances.add(compensationInstance);

  return compensationInstance;
}
 
Example #2
Source File: CustomBpmnParse.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
protected void parseMessageEventDefinitionElement(Element parentElement, ScopeImpl scope, Element endEventElement,
        ActivityImpl activity, Element messageEventDefinitionElement) {
    if (isServiceTaskLike(messageEventDefinitionElement)) {

        // CAM-436 same behaviour as service task
        ActivityImpl act = parseServiceTaskLike(ActivityTypes.END_EVENT_MESSAGE, messageEventDefinitionElement,
                scope);
        activity.getProperties().set(BpmnProperties.TYPE, ActivityTypes.END_EVENT_MESSAGE);
        activity.setActivityBehavior(act.getActivityBehavior());
        scope.getActivities().remove(act);
    } else {
        // default to non behavior if no service task
        // properties have been specified
        activity.setActivityBehavior(new IntermediateThrowNoneEventActivityBehavior());
    }
}
 
Example #3
Source File: AbstractInstantiationCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ExecutionEntity getSingleExecutionForScope(ActivityExecutionTreeMapping mapping, ScopeImpl scope) {
  Set<ExecutionEntity> executions = mapping.getExecutions(scope);

  if (!executions.isEmpty()) {
    if (executions.size() > 1) {
      throw new ProcessEngineException("Executions for activity " + scope + " ambiguous");
    }

    return executions.iterator().next();
  }
  else {
    return null;
  }
}
 
Example #4
Source File: TransitionInstanceHandler.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(MigratingInstanceParseContext parseContext, TransitionInstance transitionInstance) {

  if (!isAsyncTransitionInstance(transitionInstance)) {
    return;
  }

  MigrationInstruction applyingInstruction = parseContext.getInstructionFor(transitionInstance.getActivityId());

  ScopeImpl sourceScope = parseContext.getSourceProcessDefinition().findActivity(transitionInstance.getActivityId());
  ScopeImpl targetScope = null;

  if (applyingInstruction != null) {
    String activityId = applyingInstruction.getTargetActivityId();
    targetScope = parseContext.getTargetProcessDefinition().findActivity(activityId);
  }

  ExecutionEntity asyncExecution = Context
      .getCommandContext()
      .getExecutionManager()
      .findExecutionById(transitionInstance.getExecutionId());

  MigratingTransitionInstance migratingTransitionInstance = parseContext.getMigratingProcessInstance()
    .addTransitionInstance(
      applyingInstruction,
      transitionInstance,
      sourceScope,
      targetScope,
      asyncExecution);

  MigratingActivityInstance parentInstance = parseContext.getMigratingActivityInstanceById(transitionInstance.getParentActivityInstanceId());
  migratingTransitionInstance.setParent(parentInstance);

  List<JobEntity> jobs = asyncExecution.getJobs();
  parseContext.handleDependentTransitionInstanceJobs(migratingTransitionInstance, jobs);

  parseContext.handleDependentVariables(migratingTransitionInstance, collectTransitionInstanceVariables(migratingTransitionInstance));

}
 
Example #5
Source File: JobDefinitionCreationAndDeletionWithParseListenerTest.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(false);
      activity.setAsyncAfter(true);
    }
  });

  configuration.setCustomPreBPMNParseListeners(listeners);
  return configuration;
}
 
Example #6
Source File: ValidatingMigrationInstructions.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public List<ValidatingMigrationInstruction> getInstructionsBySourceScope(ScopeImpl scope) {
  List<ValidatingMigrationInstruction> instructions = instructionsBySourceScope.get(scope);

  if (instructions == null) {
    return Collections.emptyList();
  }
  else {
    return instructions;
  }
}
 
Example #7
Source File: MigratingActivityInstance.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an emerged activity instance
 */
public MigratingActivityInstance(ScopeImpl targetScope, ExecutionEntity scopeExecution) {

  this.targetScope = targetScope;
  this.currentScope = targetScope;
  this.representativeExecution = scopeExecution;
  this.instanceBehavior = determineBehavior(targetScope);
}
 
Example #8
Source File: ValidatingMigrationInstructions.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public List<ValidatingMigrationInstruction> getInstructionsByTargetScope(ScopeImpl scope) {
  List<ValidatingMigrationInstruction> instructions = instructionsByTargetScope.get(scope);

  if (instructions == null) {
    return Collections.emptyList();
  }
  else {
    return instructions;
  }
}
 
Example #9
Source File: DefaultFailedJobParseListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void parseBoundaryEvent(Element boundaryEventElement, ScopeImpl scopeElement, ActivityImpl nestedActivity) {
  String type = nestedActivity.getProperties().get(BpmnProperties.TYPE);
  if ((type != null && type.equals(BOUNDARY_TIMER)) || isAsync(nestedActivity)) {
    setFailedJobRetryTimeCycleValue(boundaryEventElement, nestedActivity);
  }
}
 
Example #10
Source File: MigrationCompensationInstanceVisitor.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected void instantiateScopes(
    MigratingScopeInstance ancestorScopeInstance,
    MigratingScopeInstanceBranch executionBranch,
    List<ScopeImpl> scopesToInstantiate) {

  if (scopesToInstantiate.isEmpty()) {
    return;
  }

  ExecutionEntity ancestorScopeExecution = ancestorScopeInstance.resolveRepresentativeExecution();

  ExecutionEntity parentExecution = ancestorScopeExecution;

  for (ScopeImpl scope : scopesToInstantiate) {
    ExecutionEntity compensationScopeExecution = parentExecution.createExecution();
    compensationScopeExecution.setScope(true);
    compensationScopeExecution.setEventScope(true);

    compensationScopeExecution.setActivity((PvmActivity) scope);
    compensationScopeExecution.setActive(false);
    compensationScopeExecution.activityInstanceStarting();
    compensationScopeExecution.enterActivityInstance();

    EventSubscriptionEntity eventSubscription = EventSubscriptionEntity.createAndInsert(parentExecution, EventType.COMPENSATE, (ActivityImpl) scope);
    eventSubscription.setConfiguration(compensationScopeExecution.getId());

    executionBranch.visited(new MigratingEventScopeInstance(eventSubscription, compensationScopeExecution, scope));

    parentExecution = compensationScopeExecution;
  }

}
 
Example #11
Source File: ActivityExecutionTreeMapping.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public ExecutionEntity getExecution(ActivityInstance activityInstance) {
  ScopeImpl scope = null;

  if (activityInstance.getId().equals(activityInstance.getProcessInstanceId())) {
    scope = processDefinition;
  }
  else {
    scope = processDefinition.findActivity(activityInstance.getActivityId());
  }

  return intersect(
      getExecutions(scope),
      activityInstance.getExecutionIds());
}
 
Example #12
Source File: ActivityExecutionTreeMapping.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public Set<ExecutionEntity> getExecutions(ScopeImpl activity) {
  Set<ExecutionEntity> executionsForActivity = activityExecutionMapping.get(activity);
  if (executionsForActivity == null) {
    executionsForActivity = new HashSet<ExecutionEntity>();
    activityExecutionMapping.put(activity, executionsForActivity);
  }

  return executionsForActivity;
}
 
Example #13
Source File: HistoryParseListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity) {
  ensureHistoryLevelInitialized();
  addActivityHandlers(activity);

  if (historyLevel.isHistoryEventProduced(HistoryEventTypes.TASK_INSTANCE_CREATE, null)) {
    TaskDefinition taskDefinition = ((UserTaskActivityBehavior) activity.getActivityBehavior()).getTaskDefinition();
    taskDefinition.addBuiltInTaskListener(TaskListener.EVENTNAME_ASSIGNMENT, USER_TASK_ASSIGNMENT_HANDLER);
    taskDefinition.addBuiltInTaskListener(TaskListener.EVENTNAME_CREATE, USER_TASK_ID_HANDLER);
  }
}
 
Example #14
Source File: CancelEndEventActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void doLeave(ActivityExecution execution) {
  // continue via the appropriate cancel boundary event
  ScopeImpl eventScope = (ScopeImpl) cancelBoundaryEvent.getEventScope();

  ActivityExecution boundaryEventScopeExecution = execution.findExecutionForFlowScope(eventScope);
  boundaryEventScopeExecution.executeActivity(cancelBoundaryEvent);
}
 
Example #15
Source File: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected static ScopeImpl getTopMostScope(List<ScopeImpl> scopes) {
  ScopeImpl topMostScope = null;

  for (ScopeImpl candidateScope : scopes) {
    if (topMostScope == null || candidateScope.isAncestorFlowScopeOf(topMostScope)) {
      topMostScope = candidateScope;
    }
  }

  return topMostScope;
}
 
Example #16
Source File: ActivityExecutionTreeMapping.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public ActivityExecutionTreeMapping(CommandContext commandContext, String processInstanceId) {
  this.activityExecutionMapping = new HashMap<ScopeImpl, Set<ExecutionEntity>>();
  this.commandContext = commandContext;
  this.processInstanceId = processInstanceId;

  initialize();
}
 
Example #17
Source File: CustomBpmnParse.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
protected void parseServiceTaskLikeAttributesType(String elementName, Element serviceTaskElement, ScopeImpl scope,
        ActivityImpl activity, String type) {
    if (type.equalsIgnoreCase("mail")) {
        parseEmailServiceTask(activity, serviceTaskElement, parseFieldDeclarations(serviceTaskElement));
    } else if (type.equalsIgnoreCase("shell")) {
        parseShellServiceTask(activity, serviceTaskElement, parseFieldDeclarations(serviceTaskElement));
    } else if (type.equalsIgnoreCase("external")) {
        parseExternalServiceTask(activity, serviceTaskElement);
    } else {
        addError("Invalid usage of type attribute on " + elementName + ": '" + type + "'", serviceTaskElement);
    }
}
 
Example #18
Source File: MigratingExternalTaskInstance.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void migrateState() {
  ScopeImpl targetActivity = migratingActivityInstance.getTargetScope();
  ProcessDefinition targetProcessDefinition = (ProcessDefinition) targetActivity.getProcessDefinition();

  externalTask.setActivityId(targetActivity.getId());
  externalTask.setProcessDefinitionId(targetProcessDefinition.getId());
  externalTask.setProcessDefinitionKey(targetProcessDefinition.getKey());
}
 
Example #19
Source File: CustomBpmnParse.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
protected void parseServiceTaskLikeAttributesDelegateExpression(String elementName, Element serviceTaskElement,
        ScopeImpl scope, ActivityImpl activity, String delegateExpression, String resultVariableName) {
    if (resultVariableName != null) {
        addError(PREFIX_ERROR_MSG_VARIABLE_NAME + elementName + " elements using 'delegateExpression'",
                serviceTaskElement);
    }
    activity.setActivityBehavior(new ServiceTaskDelegateExpressionActivityBehavior(
            expressionManager.createExpression(delegateExpression), parseFieldDeclarations(serviceTaskElement)));
}
 
Example #20
Source File: TestBPMNParseListener.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void parseIntermediateThrowEvent(Element intermediateEventElement, ScopeImpl scope, ActivityImpl activity) {
  // Change activity behavior
  Element compensateEventDefinitionElement = intermediateEventElement.element(COMPENSATE_EVENT_DEFINITION);
  if (compensateEventDefinitionElement != null) {
    final String activityRef = compensateEventDefinitionElement.attribute("activityRef");
    CompensateEventDefinition compensateEventDefinition = new CompensateEventDefinition();
    compensateEventDefinition.setActivityRef(activityRef);
    compensateEventDefinition.setWaitForCompletion(false);

    activity.setActivityBehavior(new TestCompensationEventActivityBehavior(compensateEventDefinition));
  }
}
 
Example #21
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 #22
Source File: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static boolean eventSubprocessConcurrentChildExecutionEnded(ActivityExecution scopeExecution, ActivityExecution endedExecution) {
  boolean performLegacyBehavior = isLegacyBehaviorRequired(endedExecution);

  if(performLegacyBehavior) {
    LOG.endConcurrentExecutionInEventSubprocess();
    // notify the grandparent flow scope in a similar way PvmAtomicOperationAcitivtyEnd does
    ScopeImpl flowScope = endedExecution.getActivity().getFlowScope();
    if (flowScope != null) {
      flowScope = flowScope.getFlowScope();

      if (flowScope != null) {
        if (flowScope == endedExecution.getActivity().getProcessDefinition()) {
          endedExecution.remove();
          scopeExecution.tryPruneLastConcurrentChild();
          scopeExecution.forceUpdate();
        }
        else {
          PvmActivity flowScopeActivity = (PvmActivity) flowScope;

          ActivityBehavior activityBehavior = flowScopeActivity.getActivityBehavior();
          if (activityBehavior instanceof CompositeActivityBehavior) {
            ((CompositeActivityBehavior) activityBehavior).concurrentChildExecutionEnded(scopeExecution, endedExecution);
          }
        }
      }
    }
  }

  return performLegacyBehavior;
}
 
Example #23
Source File: TestBPMNParseListener.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void parseEndEvent(Element endEventElement, ScopeImpl scope, ActivityImpl activity) {
  // Change activity behavior
  activity.setActivityBehavior(new TestNoneEndEventActivityBehavior());
}
 
Example #24
Source File: MigratingProcessElementInstanceVisitor.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected abstract void instantiateScopes(
MigratingScopeInstance ancestorScopeInstance,
MigratingScopeInstanceBranch executionBranch,
List<ScopeImpl> scopesToInstantiate);
 
Example #25
Source File: AbstractBpmnParseListener.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void parseStartEvent(Element startEventElement, ScopeImpl scope, ActivityImpl startEventActivity) {
}
 
Example #26
Source File: RegisterAllBpmnParseListener.java    From camunda-bpm-reactor with Apache License 2.0 4 votes vote down vote up
@Override
public void parseIntermediateCatchEvent(final Element intermediateEventElement, final ScopeImpl scope, final ActivityImpl activity) {
  addExecutionListener(activity);
}
 
Example #27
Source File: ActivityStackCollector.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void visit(ScopeImpl scope) {
  if (scope != null && PvmActivity.class.isAssignableFrom(scope.getClass())) {
    activityStack.add((PvmActivity) scope);
  }
}
 
Example #28
Source File: AbstractBpmnParseListener.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void parseTransaction(Element transactionElement, ScopeImpl scope, ActivityImpl 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 parseSubProcess(final Element subProcessElement, final ScopeImpl scope, final ActivityImpl activity) {
  addExecutionListener(activity);
}
 
Example #30
Source File: CdiEventSupportBpmnParseListener.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void parseIntermediateCatchEvent(Element intermediateEventElement, ScopeImpl scope, ActivityImpl activity) {
}