Search in sources :

Example 6 with ActivityBehavior

use of org.activiti.engine.impl.pvm.delegate.ActivityBehavior in project Activiti by Activiti.

the class AtomicOperationActivityEnd method eventNotificationsCompleted.

@SuppressWarnings("unchecked")
@Override
protected void eventNotificationsCompleted(InterpretableExecution execution) {
    ActivityImpl activity = (ActivityImpl) execution.getActivity();
    ActivityImpl parentActivity = activity.getParentActivity();
    if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        if (execution instanceof ExecutionEntity) {
            ExecutionEntity executionEntity = (ExecutionEntity) execution;
            Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPLETED, execution.getActivity().getId(), (String) executionEntity.getActivity().getProperties().get("name"), execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), (String) executionEntity.getActivity().getProperties().get("type"), executionEntity.getActivity().getActivityBehavior().getClass().getCanonicalName()));
        }
    }
    // if the execution is a single path of execution inside the process definition scope
    if ((parentActivity != null) && (!parentActivity.isScope())) {
        execution.setActivity(parentActivity);
        execution.performOperation(ACTIVITY_END);
    } else if (execution.isProcessInstanceType()) {
        // dispatch process completed event
        if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
            Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.PROCESS_COMPLETED, execution));
        }
        execution.performOperation(PROCESS_END);
    } else if (execution.isScope()) {
        ActivityBehavior parentActivityBehavior = (parentActivity != null ? parentActivity.getActivityBehavior() : null);
        if (parentActivityBehavior instanceof CompositeActivityBehavior) {
            CompositeActivityBehavior compositeActivityBehavior = (CompositeActivityBehavior) parentActivity.getActivityBehavior();
            if (activity.isScope() && activity.getOutgoingTransitions().isEmpty()) {
                // there is no transition destroying the scope
                InterpretableExecution parentScopeExecution = (InterpretableExecution) execution.getParent();
                execution.destroy();
                execution.remove();
                parentScopeExecution.setActivity(parentActivity);
                compositeActivityBehavior.lastExecutionEnded(parentScopeExecution);
            } else {
                execution.setActivity(parentActivity);
                compositeActivityBehavior.lastExecutionEnded(execution);
            }
        } else {
            // default destroy scope behavior
            InterpretableExecution parentScopeExecution = (InterpretableExecution) execution.getParent();
            execution.destroy();
            execution.remove();
            // and have no outgoing transitions: end the process instance here
            if (activity.getParent() == activity.getProcessDefinition()) {
                parentScopeExecution.setActivity(activity);
                if (activity.getOutgoingTransitions().isEmpty()) {
                    // we call end() because it sets isEnded on the execution
                    parentScopeExecution.end();
                } else {
                    // dispatch process completed event
                    if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
                        Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.PROCESS_COMPLETED, execution));
                    }
                    parentScopeExecution.performOperation(PROCESS_END);
                }
            } else {
                parentScopeExecution.setActivity(parentActivity);
                parentScopeExecution.performOperation(ACTIVITY_END);
            }
        }
    } else {
        // execution.isConcurrent() && !execution.isScope()
        execution.remove();
        // prune if necessary
        InterpretableExecution concurrentRoot = (InterpretableExecution) execution.getParent();
        if (concurrentRoot.getExecutions().size() == 1) {
            InterpretableExecution lastConcurrent = (InterpretableExecution) concurrentRoot.getExecutions().get(0);
            if (!lastConcurrent.isScope()) {
                concurrentRoot.setActivity((ActivityImpl) lastConcurrent.getActivity());
                lastConcurrent.setReplacedBy(concurrentRoot);
                // Move children of lastConcurrent one level up
                if (!lastConcurrent.getExecutions().isEmpty()) {
                    concurrentRoot.getExecutions().clear();
                    for (ActivityExecution childExecution : lastConcurrent.getExecutions()) {
                        InterpretableExecution childInterpretableExecution = (InterpretableExecution) childExecution;
                        // casting ... damn generics
                        ((List) concurrentRoot.getExecutions()).add(childExecution);
                        childInterpretableExecution.setParent(concurrentRoot);
                    }
                    lastConcurrent.getExecutions().clear();
                }
                // Copy execution-local variables of lastConcurrent
                concurrentRoot.setVariablesLocal(lastConcurrent.getVariablesLocal());
                // Make sure parent execution is re-activated when the last concurrent child execution is active
                if (!concurrentRoot.isActive() && lastConcurrent.isActive()) {
                    concurrentRoot.setActive(true);
                }
                lastConcurrent.remove();
            } else {
                lastConcurrent.setConcurrent(false);
            }
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) CompositeActivityBehavior(org.activiti.engine.impl.pvm.delegate.CompositeActivityBehavior) ActivityBehavior(org.activiti.engine.impl.pvm.delegate.ActivityBehavior) CompositeActivityBehavior(org.activiti.engine.impl.pvm.delegate.CompositeActivityBehavior) List(java.util.List) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution)

Example 7 with ActivityBehavior

use of org.activiti.engine.impl.pvm.delegate.ActivityBehavior in project Activiti by Activiti.

the class AtomicOperationActivityExecute method execute.

public void execute(InterpretableExecution execution) {
    ActivityImpl activity = (ActivityImpl) execution.getActivity();
    ActivityBehavior activityBehavior = activity.getActivityBehavior();
    if (activityBehavior == null) {
        throw new PvmException("no behavior specified in " + activity);
    }
    log.debug("{} executes {}: {}", execution, activity, activityBehavior.getClass().getName());
    try {
        if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
            Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_STARTED, execution.getActivity().getId(), (String) execution.getActivity().getProperty("name"), execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), (String) activity.getProperties().get("type"), activity.getActivityBehavior().getClass().getCanonicalName()));
        }
        activityBehavior.execute(execution);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        LogMDC.putMDCExecution(execution);
        throw new PvmException("couldn't execute activity <" + activity.getProperty("type") + " id=\"" + activity.getId() + "\" ...>: " + e.getMessage(), e);
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ActivityBehavior(org.activiti.engine.impl.pvm.delegate.ActivityBehavior) PvmException(org.activiti.engine.impl.pvm.PvmException) PvmException(org.activiti.engine.impl.pvm.PvmException)

Aggregations

ActivityBehavior (org.activiti.engine.impl.pvm.delegate.ActivityBehavior)7 BoundaryEventActivityBehavior (org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior)5 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)5 ActivitiException (org.activiti.engine.ActivitiException)3 CallActivityBehavior (org.activiti.engine.impl.bpmn.behavior.CallActivityBehavior)3 EventSubProcessStartEventActivityBehavior (org.activiti.engine.impl.bpmn.behavior.EventSubProcessStartEventActivityBehavior)3 AbstractBpmnActivityBehavior (org.activiti.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior)2 BusinessRuleTaskActivityBehavior (org.activiti.engine.impl.bpmn.behavior.BusinessRuleTaskActivityBehavior)2 CancelBoundaryEventActivityBehavior (org.activiti.engine.impl.bpmn.behavior.CancelBoundaryEventActivityBehavior)2 CancelEndEventActivityBehavior (org.activiti.engine.impl.bpmn.behavior.CancelEndEventActivityBehavior)2 ErrorEndEventActivityBehavior (org.activiti.engine.impl.bpmn.behavior.ErrorEndEventActivityBehavior)2 EventBasedGatewayActivityBehavior (org.activiti.engine.impl.bpmn.behavior.EventBasedGatewayActivityBehavior)2 ExclusiveGatewayActivityBehavior (org.activiti.engine.impl.bpmn.behavior.ExclusiveGatewayActivityBehavior)2 InclusiveGatewayActivityBehavior (org.activiti.engine.impl.bpmn.behavior.InclusiveGatewayActivityBehavior)2 IntermediateCatchEventActivityBehavior (org.activiti.engine.impl.bpmn.behavior.IntermediateCatchEventActivityBehavior)2 IntermediateThrowCompensationEventActivityBehavior (org.activiti.engine.impl.bpmn.behavior.IntermediateThrowCompensationEventActivityBehavior)2 IntermediateThrowNoneEventActivityBehavior (org.activiti.engine.impl.bpmn.behavior.IntermediateThrowNoneEventActivityBehavior)2 IntermediateThrowSignalEventActivityBehavior (org.activiti.engine.impl.bpmn.behavior.IntermediateThrowSignalEventActivityBehavior)2 MailActivityBehavior (org.activiti.engine.impl.bpmn.behavior.MailActivityBehavior)2 ManualTaskActivityBehavior (org.activiti.engine.impl.bpmn.behavior.ManualTaskActivityBehavior)2