Java Code Examples for org.flowable.engine.impl.persistence.entity.ExecutionEntity#getParentId()

The following examples show how to use org.flowable.engine.impl.persistence.entity.ExecutionEntity#getParentId() . 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: ExecutionTreeUtil.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public static ExecutionTree buildExecutionTree(DelegateExecution executionEntity) {

        // Find highest parent
        ExecutionEntity parentExecution = (ExecutionEntity) executionEntity;
        while (parentExecution.getParentId() != null || parentExecution.getSuperExecutionId() != null) {
            if (parentExecution.getParentId() != null) {
                parentExecution = parentExecution.getParent();
            } else {
                parentExecution = parentExecution.getSuperExecution();
            }
        }

        // Collect all child executions now we have the parent
        List<ExecutionEntity> allExecutions = new ArrayList<>();
        allExecutions.add(parentExecution);
        collectChildExecutions(parentExecution, allExecutions);
        return buildExecutionTree(allExecutions);
    }
 
Example 2
Source File: ExecutionTreeUtil.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public static ExecutionTree buildExecutionTree(Collection<ExecutionEntity> executions) {
    ExecutionTree executionTree = new ExecutionTree();

    // Map the executions to their parents. Catch and store the root element (process instance execution) while were at it
    Map<String, List<ExecutionEntity>> parentMapping = new HashMap<>();
    for (ExecutionEntity executionEntity : executions) {
        String parentId = executionEntity.getParentId();

        // Support for call activity
        if (parentId == null) {
            parentId = executionEntity.getSuperExecutionId();
        }

        if (parentId != null) {
            if (!parentMapping.containsKey(parentId)) {
                parentMapping.put(parentId, new ArrayList<>());
            }
            parentMapping.get(parentId).add(executionEntity);
        } else if (executionEntity.getSuperExecutionId() == null) {
            executionTree.setRoot(new ExecutionTreeNode(executionEntity));
        }
    }

    fillExecutionTree(executionTree, parentMapping);
    return executionTree;
}
 
Example 3
Source File: ExecutionTreeUtil.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public static ExecutionTree buildExecutionTreeForProcessInstance(Collection<ExecutionEntity> executions) {
    ExecutionTree executionTree = new ExecutionTree();
    if (executions.size() == 0) {
        return executionTree;
    }

    // Map the executions to their parents. Catch and store the root element (process instance execution) while were at it
    Map<String, List<ExecutionEntity>> parentMapping = new HashMap<>();
    for (ExecutionEntity executionEntity : executions) {
        String parentId = executionEntity.getParentId();

        if (parentId != null) {
            if (!parentMapping.containsKey(parentId)) {
                parentMapping.put(parentId, new ArrayList<>());
            }
            parentMapping.get(parentId).add(executionEntity);
        } else {
            executionTree.setRoot(new ExecutionTreeNode(executionEntity));
        }
    }

    fillExecutionTree(executionTree, parentMapping);
    return executionTree;
}
 
Example 4
Source File: TakeOutgoingSequenceFlowsOperation.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * @param executionEntityToIgnore
 *            The execution entity which we can ignore to be ended, as it's the execution currently being handled in this operation.
 */
protected ExecutionEntity findNextParentScopeExecutionWithAllEndedChildExecutions(ExecutionEntity executionEntity, ExecutionEntity executionEntityToIgnore) {
    if (executionEntity.getParentId() != null) {
        ExecutionEntity scopeExecutionEntity = executionEntity.getParent();

        // Find next scope
        while (!scopeExecutionEntity.isScope() || !scopeExecutionEntity.isProcessInstanceType()) {
            scopeExecutionEntity = scopeExecutionEntity.getParent();
        }

        // Return when all child executions for it are ended
        if (allChildExecutionsEnded(scopeExecutionEntity, executionEntityToIgnore)) {
            return scopeExecutionEntity;
        }

    }
    return null;
}
 
Example 5
Source File: EscalationPropagation.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public static void propagateEscalation(String escalationCode, String escalationName, DelegateExecution execution) {
    Map<String, List<Event>> eventMap = new HashMap<>();
    Set<String> rootProcessDefinitionIds = new HashSet<>();
    if (!execution.getProcessInstanceId().equals(execution.getRootProcessInstanceId())) {
        ExecutionEntity parentExecution = (ExecutionEntity) execution;
        while (parentExecution.getParentId() != null || parentExecution.getSuperExecutionId() != null) {
            if (parentExecution.getParentId() != null) {
                parentExecution = parentExecution.getParent();
            } else {
                parentExecution = parentExecution.getSuperExecution();
                rootProcessDefinitionIds.add(parentExecution.getProcessDefinitionId());
            }
        }
    }
    
    if (rootProcessDefinitionIds.size() > 0) {
        for (String processDefinitionId : rootProcessDefinitionIds) {
            eventMap.putAll(findCatchingEventsForProcess(processDefinitionId, escalationCode));
        }
    }
    
    eventMap.putAll(findCatchingEventsForProcess(execution.getProcessDefinitionId(), escalationCode));
    if (eventMap.size() > 0) {
        executeCatch(eventMap, execution, escalationCode, escalationName);
    }
}
 
Example 6
Source File: GatewayActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void lockFirstParentScope(DelegateExecution execution) {

        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();

        boolean found = false;
        ExecutionEntity parentScopeExecution = null;
        ExecutionEntity currentExecution = (ExecutionEntity) execution;
        while (!found && currentExecution != null && currentExecution.getParentId() != null) {
            parentScopeExecution = executionEntityManager.findById(currentExecution.getParentId());
            if (parentScopeExecution != null && parentScopeExecution.isScope()) {
                found = true;
            }
            currentExecution = parentScopeExecution;
        }

        parentScopeExecution.forceUpdate();
    }
 
Example 7
Source File: ParallelMultiInstanceBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void lockFirstParentScope(DelegateExecution execution) {

        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();

        boolean found = false;
        ExecutionEntity parentScopeExecution = null;
        ExecutionEntity currentExecution = (ExecutionEntity) execution;
        while (!found && currentExecution != null && currentExecution.getParentId() != null) {
            parentScopeExecution = executionEntityManager.findById(currentExecution.getParentId());
            if (parentScopeExecution != null && parentScopeExecution.isScope()) {
                found = true;
            }
            currentExecution = parentScopeExecution;
        }

        parentScopeExecution.forceUpdate();
    }
 
Example 8
Source File: ExecutionsByProcessInstanceIdEntityMatcher.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isRetained(ExecutionEntity entity, Object parameter) {
    // parameter = process instance execution id
    return entity.getProcessInstanceId() != null
            && entity.getProcessInstanceId().equals((String) parameter)
            && entity.getParentId() != null;
}
 
Example 9
Source File: ExecutionsByParentExecutionIdAndActivityIdEntityMatcher.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isRetained(ExecutionEntity executionEntity, Object parameter) {
    Map<String, Object> paramMap = (Map<String, Object>) parameter;
    String parentExecutionId = (String) paramMap.get("parentExecutionId");
    Collection<String> activityIds = (Collection<String>) paramMap.get("activityIds");

    return executionEntity.getParentId() != null && executionEntity.getParentId().equals(parentExecutionId)
            && executionEntity.getActivityId() != null && activityIds.contains(executionEntity.getActivityId());
}
 
Example 10
Source File: ErrorPropagation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static void propagateError(String errorCode, DelegateExecution execution) {
    Map<String, List<Event>> eventMap = new HashMap<>();
    Set<String> rootProcessDefinitionIds = new HashSet<>();
    if (!execution.getProcessInstanceId().equals(execution.getRootProcessInstanceId())) {
        ExecutionEntity parentExecution = (ExecutionEntity) execution;
        while (parentExecution.getParentId() != null || parentExecution.getSuperExecutionId() != null) {
            if (parentExecution.getParentId() != null) {
                parentExecution = parentExecution.getParent();
            } else {
                parentExecution = parentExecution.getSuperExecution();
                rootProcessDefinitionIds.add(parentExecution.getProcessDefinitionId());
            }
        }
    }
    
    if (rootProcessDefinitionIds.size() > 0) {
        for (String processDefinitionId : rootProcessDefinitionIds) {
            eventMap.putAll(findCatchingEventsForProcess(processDefinitionId, errorCode));
        }
    }
    
    eventMap.putAll(findCatchingEventsForProcess(execution.getProcessDefinitionId(), errorCode));
    if (eventMap.size() > 0) {
        executeCatch(eventMap, execution, errorCode);
    }

    if (eventMap.size() == 0) {
        throw new BpmnError(errorCode, "No catching boundary event found for error with errorCode '" + errorCode + "', neither in same process nor in parent process");
    }
}
 
Example 11
Source File: TerminateEndEventActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void sendProcessInstanceCompletedEvent(ExecutionEntity execution, FlowElement terminateEndEvent) {
    Process process = ProcessDefinitionUtil.getProcess(execution.getProcessDefinitionId());
    CommandContextUtil.getProcessEngineConfiguration().getListenerNotificationHelper()
        .executeExecutionListeners(process, execution, ExecutionListener.EVENTNAME_END);

    FlowableEventDispatcher eventDispatcher = CommandContextUtil.getProcessEngineConfiguration().getEventDispatcher();
    if (eventDispatcher != null && eventDispatcher.isEnabled()) {
        if ((execution.isProcessInstanceType() && execution.getSuperExecutionId() == null) ||
                (execution.getParentId() == null && execution.getSuperExecutionId() != null)) {

            // This event should only be fired if terminate end event is part of the process definition for the process instance execution,
            // otherwise a regular cancel event of the process instance will be fired (see above).
            boolean fireEvent = true;
            if (!terminateAll) {
                Process processForExecution = ProcessDefinitionUtil.getProcess(execution.getProcessDefinitionId());
                Process processForTerminateEndEvent = getProcessForTerminateEndEvent(terminateEndEvent);
                fireEvent = processForExecution.getId().equals(processForTerminateEndEvent.getId());
            }
            
            if (fireEvent) {
                eventDispatcher
                    .dispatchEvent(FlowableEventBuilder.createTerminateEvent(execution, terminateEndEvent));
            }
            
        }
    }

}
 
Example 12
Source File: ProcessExecutionLogger.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected List<DebugInfoExecutionTree> generateExecutionTrees() {

        // Gather information
        List<ExecutionEntity> processInstances = new ArrayList<>();
        Map<String, List<ExecutionEntity>> parentMapping = new HashMap<>();

        for (ExecutionEntity executionEntity : createdExecutions.values()) {
            if (!deletedExecutions.containsKey(executionEntity.getId())) {
                if (executionEntity.getParentId() == null) {
                    processInstances.add(executionEntity);
                } else {
                    if (!parentMapping.containsKey(executionEntity.getParentId())) {
                        parentMapping.put(executionEntity.getParentId(), new ArrayList<>());
                    }
                    parentMapping.get(executionEntity.getParentId()).add(executionEntity);
                }
            }
        }

        // Build tree representation
        List<DebugInfoExecutionTree> executionTrees = new ArrayList<>();
        for (ExecutionEntity processInstance : processInstances) {

            DebugInfoExecutionTree executionTree = new DebugInfoExecutionTree();
            executionTrees.add(executionTree);

            DebugInfoExecutionTreeNode rootNode = new DebugInfoExecutionTreeNode();
            executionTree.setProcessInstance(rootNode);
            rootNode.setId(processInstance.getId());

            internalPopulateExecutionTree(rootNode, parentMapping);
        }

        return executionTrees;
    }
 
Example 13
Source File: ProcessInstancesByProcessDefinitionMatcher.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isRetained(ExecutionEntity entity, Object parameter) {
    return entity.getParentId() == null && entity.getProcessDefinitionId() != null && entity.getProcessDefinitionId().equals(parameter);
}
 
Example 14
Source File: ExecutionsByParentExecutionIdEntityMatcher.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isRetained(ExecutionEntity entity, Object parameter) {
    // parameter = parent execution id
    return entity.getParentId() != null && entity.getParentId().equals((String) parameter);
}
 
Example 15
Source File: EscalationPropagation.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
protected static void executeCatch(Map<String, List<Event>> eventMap, DelegateExecution delegateExecution, String escalationCode, String escalationName) {
    Set<String> toDeleteProcessInstanceIds = new HashSet<>();
    
    Event matchingEvent = null;
    ExecutionEntity currentExecution = (ExecutionEntity) delegateExecution;
    ExecutionEntity parentExecution = null;

    if (eventMap.containsKey(currentExecution.getActivityId() + "#" + currentExecution.getProcessDefinitionId())) {
        // Check for multi instance
        if (currentExecution.getParentId() != null && currentExecution.getParent().isMultiInstanceRoot()) {
            parentExecution = currentExecution.getParent();
        } else {
            parentExecution = currentExecution;
        }
        
        matchingEvent = getCatchEventFromList(eventMap.get(currentExecution.getActivityId() + 
                        "#" + currentExecution.getProcessDefinitionId()), parentExecution);

    } else {
        parentExecution = currentExecution.getParent();
        
        // Traverse parents until one is found that is a scope and matches the activity the boundary event is defined on
        while (matchingEvent == null && parentExecution != null) {
            FlowElementsContainer currentContainer = null;
            if (parentExecution.getCurrentFlowElement() instanceof FlowElementsContainer) {
                currentContainer = (FlowElementsContainer) parentExecution.getCurrentFlowElement();
            } else if (parentExecution.getId().equals(parentExecution.getProcessInstanceId())) {
                currentContainer = ProcessDefinitionUtil.getProcess(parentExecution.getProcessDefinitionId());
            }

            if (currentContainer != null) {
                for (String refId : eventMap.keySet()) {
                    List<Event> events = eventMap.get(refId);
                    if (CollectionUtil.isNotEmpty(events) && events.get(0) instanceof StartEvent) {
                        String refActivityId = refId.substring(0, refId.indexOf('#'));
                        String refProcessDefinitionId = refId.substring(refId.indexOf('#') + 1);
                        if (parentExecution.getProcessDefinitionId().equals(refProcessDefinitionId) && 
                                        currentContainer.getFlowElement(refActivityId) != null) {
                            
                            matchingEvent = getCatchEventFromList(events, parentExecution);
                            EscalationEventDefinition escalationEventDef = getEscalationEventDefinition(matchingEvent);
                            if (StringUtils.isNotEmpty(escalationEventDef.getEscalationCode())) {
                                break;
                            }
                        }
                    }
                }
            }

            if (matchingEvent == null) {
                if (eventMap.containsKey(parentExecution.getActivityId() + "#" + parentExecution.getProcessDefinitionId())) {
                    // Check for multi instance
                    if (parentExecution.getParentId() != null && parentExecution.getParent().isMultiInstanceRoot()) {
                        parentExecution = parentExecution.getParent();
                    }
                    
                    matchingEvent = getCatchEventFromList(eventMap.get(parentExecution.getActivityId() + 
                                    "#" + parentExecution.getProcessDefinitionId()), parentExecution);

                } else if (StringUtils.isNotEmpty(parentExecution.getParentId())) {
                    parentExecution = parentExecution.getParent();
                    
                } else {
                    if (parentExecution.getProcessInstanceId().equals(parentExecution.getRootProcessInstanceId()) == false) {
                        toDeleteProcessInstanceIds.add(parentExecution.getProcessInstanceId());
                        parentExecution = parentExecution.getSuperExecution();
                    } else {
                        parentExecution = null;
                    }
                }
            }
        }
    }

    if (matchingEvent != null && parentExecution != null) {
        
        for (String processInstanceId : toDeleteProcessInstanceIds) {
            ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();
            ExecutionEntity processInstanceEntity = executionEntityManager.findById(processInstanceId);

            // Event
            ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
            FlowableEventDispatcher eventDispatcher = null;
            if (processEngineConfiguration != null) {
                eventDispatcher = processEngineConfiguration.getEventDispatcher();
            }
            if (eventDispatcher != null && eventDispatcher.isEnabled()) {
                processEngineConfiguration.getEventDispatcher()
                        .dispatchEvent(FlowableEventBuilder.createEntityEvent(FlowableEngineEventType.PROCESS_COMPLETED_WITH_ESCALATION_END_EVENT, processInstanceEntity));
            }
        }
        
        executeEventHandler(matchingEvent, parentExecution, currentExecution, escalationCode, escalationName);   
    }
}