Search in sources :

Example 1 with ScopeImpl

use of org.activiti.engine.impl.pvm.process.ScopeImpl in project Activiti by Activiti.

the class StartEventParseHandler method createScopeStartEvent.

protected void createScopeStartEvent(BpmnParse bpmnParse, ActivityImpl startEventActivity, StartEvent startEvent) {
    ScopeImpl scope = bpmnParse.getCurrentScope();
    Object triggeredByEvent = scope.getProperty("triggeredByEvent");
    boolean isTriggeredByEvent = triggeredByEvent != null && ((Boolean) triggeredByEvent == true);
    if (isTriggeredByEvent) {
        // event subprocess
        // all start events of an event subprocess share common behavior
        EventSubProcessStartEventActivityBehavior activityBehavior = bpmnParse.getActivityBehaviorFactory().createEventSubProcessStartEventActivityBehavior(startEvent, startEventActivity.getId());
        startEventActivity.setActivityBehavior(activityBehavior);
        if (!startEvent.getEventDefinitions().isEmpty()) {
            EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
            if (eventDefinition instanceof org.activiti.bpmn.model.ErrorEventDefinition || eventDefinition instanceof MessageEventDefinition || eventDefinition instanceof SignalEventDefinition) {
                bpmnParse.getBpmnParserHandlers().parseElement(bpmnParse, eventDefinition);
            } else {
                logger.warn("start event of event subprocess must be of type 'error', 'message' or 'signal' for start event " + startEvent.getId());
            }
        }
    } else {
        if (!startEvent.getEventDefinitions().isEmpty()) {
            logger.warn("event definitions only allowed on start event if subprocess is an event subprocess " + bpmnParse.getCurrentSubProcess().getId());
        }
        if (scope.getProperty(PROPERTYNAME_INITIAL) == null) {
            scope.setProperty(PROPERTYNAME_INITIAL, startEventActivity);
            startEventActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createNoneStartEventActivityBehavior(startEvent));
        } else {
            logger.warn("multiple start events not supported for subprocess", bpmnParse.getCurrentSubProcess().getId());
        }
    }
}
Also used : EventSubProcessStartEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.EventSubProcessStartEventActivityBehavior) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition)

Example 2 with ScopeImpl

use of org.activiti.engine.impl.pvm.process.ScopeImpl in project Activiti by Activiti.

the class ErrorPropagation method executeCatch.

private static void executeCatch(String errorHandlerId, ActivityExecution execution, String errorCode) {
    ProcessDefinitionImpl processDefinition = ((ExecutionEntity) execution).getProcessDefinition();
    ActivityImpl errorHandler = processDefinition.findActivity(errorHandlerId);
    if (errorHandler == null) {
        throw new ActivitiException(errorHandlerId + " not found in process definition");
    }
    boolean matchingParentFound = false;
    ActivityExecution leavingExecution = execution;
    ActivityImpl currentActivity = (ActivityImpl) execution.getActivity();
    ScopeImpl catchingScope = errorHandler.getParent();
    if (catchingScope instanceof ActivityImpl) {
        ActivityImpl catchingScopeActivity = (ActivityImpl) catchingScope;
        if (!catchingScopeActivity.isScope()) {
            // event subprocesses
            catchingScope = catchingScopeActivity.getParent();
        }
    }
    if (catchingScope instanceof PvmProcessDefinition) {
        executeEventHandler(errorHandler, ((ExecutionEntity) execution).getProcessInstance(), errorCode);
    } else {
        if (currentActivity.getId().equals(catchingScope.getId())) {
            matchingParentFound = true;
        } else {
            currentActivity = (ActivityImpl) currentActivity.getParent();
            // and matches the activity the boundary event is defined on
            while (!matchingParentFound && leavingExecution != null && currentActivity != null) {
                if (!leavingExecution.isConcurrent() && currentActivity.getId().equals(catchingScope.getId())) {
                    matchingParentFound = true;
                } else if (leavingExecution.isConcurrent()) {
                    leavingExecution = leavingExecution.getParent();
                } else {
                    currentActivity = currentActivity.getParentActivity();
                    leavingExecution = leavingExecution.getParent();
                }
            }
            // Follow parents up until matching scope can't be found anymore (needed to support for multi-instance)
            while (leavingExecution != null && leavingExecution.getParent() != null && leavingExecution.getParent().getActivity() != null && leavingExecution.getParent().getActivity().getId().equals(catchingScope.getId())) {
                leavingExecution = leavingExecution.getParent();
            }
        }
        if (matchingParentFound && leavingExecution != null) {
            executeEventHandler(errorHandler, leavingExecution, errorCode);
        } else {
            throw new ActivitiException("No matching parent execution for activity " + errorHandlerId + " found");
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinitionImpl(org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) PvmProcessDefinition(org.activiti.engine.impl.pvm.PvmProcessDefinition) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl)

Example 3 with ScopeImpl

use of org.activiti.engine.impl.pvm.process.ScopeImpl in project Activiti by Activiti.

the class CompensateEventDefinitionParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, CompensateEventDefinition eventDefinition) {
    ScopeImpl scope = bpmnParse.getCurrentScope();
    if (StringUtils.isNotEmpty(eventDefinition.getActivityRef())) {
        if (scope.findActivity(eventDefinition.getActivityRef()) == null) {
            logger.warn("Invalid attribute value for 'activityRef': no activity with id '" + eventDefinition.getActivityRef() + "' in current scope " + scope.getId());
        }
    }
    org.activiti.engine.impl.bpmn.parser.CompensateEventDefinition compensateEventDefinition = new org.activiti.engine.impl.bpmn.parser.CompensateEventDefinition();
    compensateEventDefinition.setActivityRef(eventDefinition.getActivityRef());
    compensateEventDefinition.setWaitForCompletion(eventDefinition.isWaitForCompletion());
    ActivityImpl activity = bpmnParse.getCurrentActivity();
    if (bpmnParse.getCurrentFlowElement() instanceof ThrowEvent) {
        activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowCompensationEventActivityBehavior((ThrowEvent) bpmnParse.getCurrentFlowElement(), compensateEventDefinition));
    } else if (bpmnParse.getCurrentFlowElement() instanceof BoundaryEvent) {
        BoundaryEvent boundaryEvent = (BoundaryEvent) bpmnParse.getCurrentFlowElement();
        boolean interrupting = boundaryEvent.isCancelActivity();
        activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createBoundaryEventActivityBehavior(boundaryEvent, interrupting, activity));
        activity.setProperty("type", "compensationBoundaryCatch");
    } else {
    // What to do?
    }
}
Also used : ThrowEvent(org.activiti.bpmn.model.ThrowEvent) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition)

Example 4 with ScopeImpl

use of org.activiti.engine.impl.pvm.process.ScopeImpl in project Activiti by Activiti.

the class IntermediateCatchEventParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, IntermediateCatchEvent event) {
    ActivityImpl nestedActivity = null;
    EventDefinition eventDefinition = null;
    if (!event.getEventDefinitions().isEmpty()) {
        eventDefinition = event.getEventDefinitions().get(0);
    }
    if (eventDefinition == null) {
        nestedActivity = createActivityOnCurrentScope(bpmnParse, event, BpmnXMLConstants.ELEMENT_EVENT_CATCH);
        nestedActivity.setAsync(event.isAsynchronous());
        nestedActivity.setExclusive(!event.isNotExclusive());
    } else {
        ScopeImpl scope = bpmnParse.getCurrentScope();
        String eventBasedGatewayId = getPrecedingEventBasedGateway(bpmnParse, event);
        if (eventBasedGatewayId != null) {
            ActivityImpl gatewayActivity = scope.findActivity(eventBasedGatewayId);
            nestedActivity = createActivityOnScope(bpmnParse, event, BpmnXMLConstants.ELEMENT_EVENT_CATCH, gatewayActivity);
        } else {
            nestedActivity = createActivityOnScope(bpmnParse, event, BpmnXMLConstants.ELEMENT_EVENT_CATCH, scope);
        }
        nestedActivity.setAsync(event.isAsynchronous());
        nestedActivity.setExclusive(!event.isNotExclusive());
        // Catch event behavior is the same for all types
        nestedActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateCatchEventActivityBehavior(event));
        if (eventDefinition instanceof TimerEventDefinition || eventDefinition instanceof SignalEventDefinition || eventDefinition instanceof MessageEventDefinition) {
            bpmnParse.getBpmnParserHandlers().parseElement(bpmnParse, eventDefinition);
        } else {
            logger.warn("Unsupported intermediate catch event type for event " + event.getId());
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition)

Example 5 with ScopeImpl

use of org.activiti.engine.impl.pvm.process.ScopeImpl in project Activiti by Activiti.

the class AbstractEventAtomicOperation method execute.

public void execute(InterpretableExecution execution) {
    ScopeImpl scope = getScope(execution);
    List<ExecutionListener> exectionListeners = scope.getExecutionListeners(getEventName());
    int executionListenerIndex = execution.getExecutionListenerIndex();
    if (exectionListeners.size() > executionListenerIndex) {
        execution.setEventName(getEventName());
        execution.setEventSource(scope);
        ExecutionListener listener = exectionListeners.get(executionListenerIndex);
        try {
            listener.notify(execution);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new PvmException("couldn't execute event listener : " + e.getMessage(), e);
        }
        execution.setExecutionListenerIndex(executionListenerIndex + 1);
        execution.performOperation(this);
    } else {
        execution.setExecutionListenerIndex(0);
        execution.setEventName(null);
        execution.setEventSource(null);
        eventNotificationsCompleted(execution);
    }
}
Also used : ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl) PvmException(org.activiti.engine.impl.pvm.PvmException) PvmException(org.activiti.engine.impl.pvm.PvmException) ExecutionListener(org.activiti.engine.delegate.ExecutionListener)

Aggregations

ScopeImpl (org.activiti.engine.impl.pvm.process.ScopeImpl)14 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)11 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)3 EventDefinition (org.activiti.bpmn.model.EventDefinition)3 List (java.util.List)2 ErrorEventDefinition (org.activiti.bpmn.model.ErrorEventDefinition)2 MessageEventDefinition (org.activiti.bpmn.model.MessageEventDefinition)2 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)2 StartEvent (org.activiti.bpmn.model.StartEvent)2 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)2 EventSubscriptionDeclaration (org.activiti.engine.impl.bpmn.parser.EventSubscriptionDeclaration)2 ProcessDefinitionImpl (org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl)2 TransitionImpl (org.activiti.engine.impl.pvm.process.TransitionImpl)2 ArrayList (java.util.ArrayList)1 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 CancelEventDefinition (org.activiti.bpmn.model.CancelEventDefinition)1 CompensateEventDefinition (org.activiti.bpmn.model.CompensateEventDefinition)1 IntermediateCatchEvent (org.activiti.bpmn.model.IntermediateCatchEvent)1 Message (org.activiti.bpmn.model.Message)1 TerminateEventDefinition (org.activiti.bpmn.model.TerminateEventDefinition)1