Java Code Examples for org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity#getCompensateEventSubscriptions()

The following examples show how to use org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity#getCompensateEventSubscriptions() . 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: CompensationEventSubscriptionWalker.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected Collection<EventSubscriptionEntity> nextElements() {
  EventSubscriptionEntity eventSubscriptionEntity = getCurrentElement();
  ExecutionEntity compensatingExecution = CompensationUtil.getCompensatingExecution(eventSubscriptionEntity);
  if (compensatingExecution != null) {
    return compensatingExecution.getCompensateEventSubscriptions();
  }
  else {
    return Collections.emptyList();
  }
}
 
Example 2
Source File: CompensationEventHandler.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, Object localPayload, String businessKey, CommandContext commandContext) {
  eventSubscription.delete();

  String configuration = eventSubscription.getConfiguration();
  ensureNotNull("Compensating execution not set for compensate event subscription with id " + eventSubscription.getId(), "configuration", configuration);

  ExecutionEntity compensatingExecution = commandContext.getExecutionManager().findExecutionById(configuration);

  ActivityImpl compensationHandler = eventSubscription.getActivity();

  // activate execution
  compensatingExecution.setActive(true);

  if (compensatingExecution.getActivity().getActivityBehavior() instanceof CompositeActivityBehavior) {
    compensatingExecution.getParent().setActivityInstanceId(compensatingExecution.getActivityInstanceId());
  }

  if (compensationHandler.isScope() && !compensationHandler.isCompensationHandler()) {
    // descend into scope:
    List<EventSubscriptionEntity> eventsForThisScope = compensatingExecution.getCompensateEventSubscriptions();
    CompensationUtil.throwCompensationEvent(eventsForThisScope, compensatingExecution, false);

  } else {
    try {


      if (compensationHandler.isSubProcessScope() && compensationHandler.isTriggeredByEvent()) {
        compensatingExecution.executeActivity(compensationHandler);
      }
      else {
        // since we already have a scope execution, we don't need to create another one
        // for a simple scoped compensation handler
        compensatingExecution.setActivity(compensationHandler);
        compensatingExecution.performOperation(PvmAtomicOperation.ACTIVITY_START);
      }


    } catch (Exception e) {
      throw new ProcessEngineException("Error while handling compensation event " + eventSubscription, e);
    }
  }
}
 
Example 3
Source File: CompensationUtil.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * creates an event scope for the given execution:
 *
 * create a new event scope execution under the parent of the given execution
 * and move all event subscriptions to that execution.
 *
 * this allows us to "remember" the event subscriptions after finishing a
 * scope
 */
public static void createEventScopeExecution(ExecutionEntity execution) {

  // parent execution is a subprocess or a miBody
  ActivityImpl activity = execution.getActivity();
  ExecutionEntity scopeExecution = (ExecutionEntity) execution.findExecutionForFlowScope(activity.getFlowScope());

  List<EventSubscriptionEntity> eventSubscriptions = execution.getCompensateEventSubscriptions();

  if (eventSubscriptions.size() > 0 || hasCompensationEventSubprocess(activity)) {

    ExecutionEntity eventScopeExecution = scopeExecution.createExecution();
    eventScopeExecution.setActivity(execution.getActivity());
    eventScopeExecution.activityInstanceStarting();
    eventScopeExecution.enterActivityInstance();
    eventScopeExecution.setActive(false);
    eventScopeExecution.setConcurrent(false);
    eventScopeExecution.setEventScope(true);

    // copy local variables to eventScopeExecution by value. This way,
    // the eventScopeExecution references a 'snapshot' of the local variables
    Map<String, Object> variables = execution.getVariablesLocal();
    for (Entry<String, Object> variable : variables.entrySet()) {
      eventScopeExecution.setVariableLocal(variable.getKey(), variable.getValue());
    }

    // set event subscriptions to the event scope execution:
    for (EventSubscriptionEntity eventSubscriptionEntity : eventSubscriptions) {
      EventSubscriptionEntity newSubscription =
              EventSubscriptionEntity.createAndInsert(
                      eventScopeExecution,
                      EventType.COMPENSATE,
                      eventSubscriptionEntity.getActivity());
      newSubscription.setConfiguration(eventSubscriptionEntity.getConfiguration());
      // use the original date
      newSubscription.setCreated(eventSubscriptionEntity.getCreated());
    }

    // set existing event scope executions as children of new event scope execution
    // (ensuring they don't get removed when 'execution' gets removed)
    for (PvmExecutionImpl childEventScopeExecution : execution.getEventScopeExecutions()) {
      childEventScopeExecution.setParent(eventScopeExecution);
    }

    ActivityImpl compensationHandler = getEventScopeCompensationHandler(execution);
    EventSubscriptionEntity eventSubscription = EventSubscriptionEntity
            .createAndInsert(
              scopeExecution,
              EventType.COMPENSATE,
              compensationHandler
            );
    eventSubscription.setConfiguration(eventScopeExecution.getId());

  }
}