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

The following examples show how to use org.activiti.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: IntermediateThrowCompensationEventActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    final String activityRef = compensateEventDefinition.getActivityRef();
    ActivityExecution activityExecution = (ActivityExecution) execution;
    ExecutionEntity scopeExecution = ScopeUtil.findScopeExecutionForScope((ExecutionEntity) execution, (ActivityImpl) activityExecution.getActivity());

    List<CompensateEventSubscriptionEntity> eventSubscriptions;

    if (activityRef != null) {
        eventSubscriptions = scopeExecution.getCompensateEventSubscriptions(activityRef);
    } else {
        eventSubscriptions = scopeExecution.getCompensateEventSubscriptions();
    }

    if (eventSubscriptions.isEmpty()) {
        leave(activityExecution);
    } else {
        // TODO: implement async (waitForCompletion=false in bpmn)
        ScopeUtil.throwCompensationEvent(eventSubscriptions, activityExecution, false);
    }

}
 
Example 2
Source File: ScopeUtil.java    From flowable-engine with Apache License 2.0 5 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) {

    ExecutionEntity eventScope = ScopeUtil.findScopeExecutionForScope(execution, execution.getActivity().getParent());

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

    if (!eventSubscriptions.isEmpty()) {

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

        execution.setConcurrent(false);

        // 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 (CompensateEventSubscriptionEntity eventSubscriptionEntity : eventSubscriptions) {
            eventSubscriptionEntity = eventSubscriptionEntity.moveUnder(eventScopeExecution);
        }

        CompensateEventSubscriptionEntity eventSubscription = CompensateEventSubscriptionEntity.createAndInsert(eventScope);
        eventSubscription.setActivity(execution.getActivity());
        eventSubscription.setConfiguration(eventScopeExecution.getId());

    }
}
 
Example 3
Source File: CompensationEventHandler.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, CommandContext commandContext) {

    String configuration = eventSubscription.getConfiguration();
    if (configuration == null) {
        throw new ActivitiException("Compensating execution not set for compensate event subscription with id " + eventSubscription.getId());
    }

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

    ActivityImpl compensationHandler = eventSubscription.getActivity();

    if ((compensationHandler.getProperty(BpmnParse.PROPERTYNAME_IS_FOR_COMPENSATION) == null
            || !(Boolean) compensationHandler.getProperty(BpmnParse.PROPERTYNAME_IS_FOR_COMPENSATION))
            && compensationHandler.isScope()) {

        // descend into scope:
        List<CompensateEventSubscriptionEntity> eventsForThisScope = compensatingExecution.getCompensateEventSubscriptions();
        ScopeUtil.throwCompensationEvent(eventsForThisScope, compensatingExecution, false);

    } else {
        try {

            if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
                commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                        ActivitiEventBuilder.createActivityEvent(FlowableEngineEventType.ACTIVITY_COMPENSATE,
                                compensationHandler.getId(),
                                (String) compensationHandler.getProperty("name"),
                                compensatingExecution.getId(),
                                compensatingExecution.getProcessInstanceId(),
                                compensatingExecution.getProcessDefinitionId(),
                                (String) compensatingExecution.getActivity().getProperties().get("type"),
                                compensatingExecution.getActivity().getActivityBehavior().getClass().getCanonicalName()));
            }
            compensatingExecution.setActivity(compensationHandler);

            // executing the atomic operation makes sure activity start events are fired
            compensatingExecution.performOperation(AtomicOperation.ACTIVITY_START);

        } catch (Exception e) {
            throw new ActivitiException("Error while handling compensation event " + eventSubscription, e);
        }

    }
}