Java Code Examples for org.camunda.bpm.engine.impl.pvm.process.ActivityImpl#getFlowScope()

The following examples show how to use org.camunda.bpm.engine.impl.pvm.process.ActivityImpl#getFlowScope() . 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: CannotAddMultiInstanceBodyValidator.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void validate(ValidatingMigrationInstruction instruction, final ValidatingMigrationInstructions instructions,
    MigrationInstructionValidationReportImpl report) {
  ActivityImpl targetActivity = instruction.getTargetActivity();

  FlowScopeWalker flowScopeWalker = new FlowScopeWalker(targetActivity.getFlowScope());
  MiBodyCollector miBodyCollector = new MiBodyCollector();
  flowScopeWalker.addPreVisitor(miBodyCollector);

  // walk until a target scope is found that is mapped
  flowScopeWalker.walkWhile(new WalkCondition<ScopeImpl>() {
    @Override
    public boolean isFulfilled(ScopeImpl element) {
      return element == null || !instructions.getInstructionsByTargetScope(element).isEmpty();
    }
  });

  if (miBodyCollector.firstMiBody != null) {
    report.addFailure("Target activity '" + targetActivity.getId() + "' is a descendant of multi-instance body '" +
      miBodyCollector.firstMiBody.getId() + "' that is not mapped from the source process definition.");
  }
}
 
Example 2
Source File: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Required for migrating active sequential MI receive tasks. These activities were formerly not scope,
 * but are now. This has the following implications:
 *
 * <p>Before migration:
 * <ul><li> the event subscription is attached to the miBody scope execution</ul>
 *
 * <p>After migration:
 * <ul><li> a new subscription is created for every instance
 * <li> the new subscription is attached to a dedicated scope execution as a child of the miBody scope
 *   execution</ul>
 *
 * <p>Thus, this method removes the subscription on the miBody scope
 */
public static void removeLegacySubscriptionOnParent(ExecutionEntity execution, EventSubscriptionEntity eventSubscription) {
  ActivityImpl activity = execution.getActivity();
  if (activity == null) {
    return;
  }

  ActivityBehavior behavior = activity.getActivityBehavior();
  ActivityBehavior parentBehavior = (ActivityBehavior) (activity.getFlowScope() != null ? activity.getFlowScope().getActivityBehavior() : null);

  if (behavior instanceof ReceiveTaskActivityBehavior &&
      parentBehavior instanceof MultiInstanceActivityBehavior) {
    List<EventSubscriptionEntity> parentSubscriptions = execution.getParent().getEventSubscriptions();

    for (EventSubscriptionEntity subscription : parentSubscriptions) {
      // distinguish a boundary event on the mi body with the same message name from the receive task subscription
      if (areEqualEventSubscriptions(subscription, eventSubscription)) {
        subscription.delete();
      }
    }
  }

}
 
Example 3
Source File: CompensationUtil.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private static String getSubscriptionActivityId(ActivityExecution execution, String activityRef) {
  ActivityImpl activityToCompensate = ((ExecutionEntity) execution).getProcessDefinition().findActivity(activityRef);

  if (activityToCompensate.isMultiInstance()) {

    ActivityImpl flowScope = (ActivityImpl) activityToCompensate.getFlowScope();
    return flowScope.getActivityId();
  } else {

    ActivityImpl compensationHandler = activityToCompensate.findCompensationHandler();
    if (compensationHandler != null) {
      return compensationHandler.getActivityId();
    } else {
      // if activityRef = subprocess and subprocess has no compensation handler
      return activityRef;
    }
  }
}
 
Example 4
Source File: GatewayMappingValidator.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void validateParentScopeMigrates(ValidatingMigrationInstruction instruction, ValidatingMigrationInstructions instructions,
    MigrationInstructionValidationReportImpl report) {
  ActivityImpl sourceActivity = instruction.getSourceActivity();
  ScopeImpl flowScope = sourceActivity.getFlowScope();

  if (flowScope != flowScope.getProcessDefinition()) {
    if (instructions.getInstructionsBySourceScope(flowScope).isEmpty()) {
      report.addFailure("The gateway's flow scope '" + flowScope.getId() + "' must be mapped");
    }
  }
}
 
Example 5
Source File: SameEventScopeInstructionValidator.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void validate(ValidatingMigrationInstruction instruction, ValidatingMigrationInstructions instructions, MigrationInstructionValidationReportImpl report) {
  ActivityImpl sourceActivity = instruction.getSourceActivity();
  if (isCompensationBoundaryEvent(sourceActivity)) {
    // this is not required for compensation boundary events since their
    // event scopes need not be active at runtime
    return;
  }

  ScopeImpl sourceEventScope = instruction.getSourceActivity().getEventScope();
  ScopeImpl targetEventScope = instruction.getTargetActivity().getEventScope();

  if (sourceEventScope == null || sourceEventScope == sourceActivity.getFlowScope()) {
    // event scopes must only match if the event scopes are not the flow scopes
    // => validation necessary for boundary events;
    // => validation not necessary for event subprocesses
    return;
  }

  if (targetEventScope == null) {
    // target event scope is allowed to be null for user tasks with timeout listeners
    // if all listeners are removed in the target
    if (!isUserTaskWithTimeoutListener(sourceActivity)) {
      report.addFailure("The source activity's event scope (" + sourceEventScope.getId() + ") must be mapped but the "
          + "target activity has no event scope");
    }
  }
  else {
    ScopeImpl mappedSourceEventScope = findMappedEventScope(sourceEventScope, instruction, instructions);
    if (mappedSourceEventScope == null || !mappedSourceEventScope.getId().equals(targetEventScope.getId())) {
      report.addFailure("The source activity's event scope (" + sourceEventScope.getId() + ") "
          + "must be mapped to the target activity's event scope (" + targetEventScope.getId() + ")");
    }
  }
}
 
Example 6
Source File: LegacyBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected static boolean wasNoScope72(ActivityImpl activity) {
  ActivityBehavior activityBehavior = activity.getActivityBehavior();
  ActivityBehavior parentActivityBehavior = (ActivityBehavior) (activity.getFlowScope() != null ? activity.getFlowScope().getActivityBehavior() : null);
  return (activityBehavior instanceof EventSubProcessActivityBehavior)
      || (activityBehavior instanceof SubProcessActivityBehavior
            && parentActivityBehavior instanceof SequentialMultiInstanceActivityBehavior)
      || (activityBehavior instanceof ReceiveTaskActivityBehavior
            && parentActivityBehavior instanceof MultiInstanceActivityBehavior);
}
 
Example 7
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 8
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 9
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 10
Source File: BpmnParseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/compensate/CompensateEventTest.compensationMiActivity.bpmn20.xml")
@Test
public void testParseCompensationHandlerOfMiActivity() {
  ActivityImpl miActivity = findActivityInDeployedProcessDefinition("undoBookHotel");
  ScopeImpl flowScope = miActivity.getFlowScope();

  assertEquals(ActivityTypes.MULTI_INSTANCE_BODY, flowScope.getProperty(BpmnParse.PROPERTYNAME_TYPE));
  assertEquals("bookHotel" + BpmnParse.MULTI_INSTANCE_BODY_ID_SUFFIX, ((ActivityImpl) flowScope).getActivityId());
}
 
Example 11
Source File: BpmnParseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/compensate/CompensateEventTest.compensationMiSubprocess.bpmn20.xml")
@Test
public void testParseCompensationHandlerOfMiSubprocess() {
  ActivityImpl miActivity = findActivityInDeployedProcessDefinition("undoBookHotel");
  ScopeImpl flowScope = miActivity.getFlowScope();

  assertEquals(ActivityTypes.MULTI_INSTANCE_BODY, flowScope.getProperty(BpmnParse.PROPERTYNAME_TYPE));
  assertEquals("scope" + BpmnParse.MULTI_INSTANCE_BODY_ID_SUFFIX, ((ActivityImpl) flowScope).getActivityId());
}
 
Example 12
Source File: AsyncProcessStartMigrationValidator.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected boolean isTopLevelActivity(ActivityImpl activity) {
  return activity.getFlowScope() == activity.getProcessDefinition();
}