Search in sources :

Example 1 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class DefaultContextAssociationManager method setVariable.

@Override
public void setVariable(String variableName, Object value) {
    ExecutionEntity execution = getExecutionFromContext();
    if (execution != null) {
        execution.setVariable(variableName, value);
        execution.getVariable(variableName);
    } else {
        getScopedAssociation().setVariable(variableName, value);
    }
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity)

Example 2 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class ErrorPropagation method getSuperExecution.

private static ActivityExecution getSuperExecution(ActivityExecution execution) {
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    ExecutionEntity superExecution = executionEntity.getProcessInstance().getSuperExecution();
    if (superExecution != null && !superExecution.isScope()) {
        return superExecution.getParent();
    }
    return superExecution;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity)

Example 3 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity 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 4 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class ScopeUtil method findScopeExecutionForScope.

/**
   * returns the top-most execution sitting in an activity part of the scope defined by 'scopeActivitiy'.
   */
public static ExecutionEntity findScopeExecutionForScope(ExecutionEntity execution, PvmScope scopeActivity) {
    if (scopeActivity instanceof PvmProcessDefinition) {
        return execution.getProcessInstance();
    } else {
        ActivityImpl currentActivity = execution.getActivity();
        ExecutionEntity candiadateExecution = null;
        ExecutionEntity originalExecution = execution;
        while (execution != null) {
            currentActivity = execution.getActivity();
            if (scopeActivity.getActivities().contains(currentActivity) || /* does not search rec*/
            scopeActivity.equals(currentActivity)) {
                // found a candidate execution; lets still check whether we find an
                // execution which is also sitting in an activity part of this scope
                // higher up the hierarchy
                candiadateExecution = execution;
            } else if (currentActivity != null && currentActivity.contains((ActivityImpl) scopeActivity)) /*searches rec*/
            {
                // now we're too "high", the candidate execution is the one.
                break;
            }
            execution = execution.getParent();
        }
        // if activity is scope, we need to get the parent at least:
        if (originalExecution == candiadateExecution && originalExecution.getActivity().isScope() && !originalExecution.getActivity().equals(scopeActivity)) {
            candiadateExecution = originalExecution.getParent();
        }
        return candiadateExecution;
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) PvmProcessDefinition(org.activiti.engine.impl.pvm.PvmProcessDefinition)

Example 5 with ExecutionEntity

use of org.activiti.engine.impl.persistence.entity.ExecutionEntity in project Activiti by Activiti.

the class ScopeUtil method createEventScopeExecution.

/**
   * 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((ActivityImpl) 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());
    }
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) CompensateEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity)

Aggregations

ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)58 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)15 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)15 ActivitiException (org.activiti.engine.ActivitiException)12 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)11 ActivityExecution (org.activiti.engine.impl.pvm.delegate.ActivityExecution)8 HashMap (java.util.HashMap)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 CompensateEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity)5 Deployment (org.activiti.engine.test.Deployment)5 ArrayList (java.util.ArrayList)4 DeploymentManager (org.activiti.engine.impl.persistence.deploy.DeploymentManager)4 AttachmentEntity (org.activiti.engine.impl.persistence.entity.AttachmentEntity)3 TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)3 PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)3 List (java.util.List)2 ActivitiEntityEvent (org.activiti.engine.delegate.event.ActivitiEntityEvent)2