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

The following examples show how to use org.flowable.engine.impl.persistence.entity.ExecutionEntity#getExecutions() . 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: CompleteAdhocSubProcessCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);
    ExecutionEntity execution = executionEntityManager.findById(executionId);
    if (execution == null) {
        throw new FlowableObjectNotFoundException("No execution found for id '" + executionId + "'", ExecutionEntity.class);
    }

    if (!(execution.getCurrentFlowElement() instanceof AdhocSubProcess)) {
        throw new FlowableException("The current flow element of the requested execution is not an ad-hoc sub process");
    }

    List<? extends ExecutionEntity> childExecutions = execution.getExecutions();
    if (childExecutions.size() > 0) {
        throw new FlowableException("Ad-hoc sub process has running child executions that need to be completed first");
    }

    ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(execution.getParent());
    outgoingFlowExecution.setCurrentFlowElement(execution.getCurrentFlowElement());

    executionEntityManager.deleteExecutionAndRelatedData(execution, null, false);

    CommandContextUtil.getAgenda().planTakeOutgoingSequenceFlowsOperation(outgoingFlowExecution, true);

    return null;
}
 
Example 2
Source File: ExecutionTreeUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static void collectChildExecutions(ExecutionEntity rootExecutionEntity, List<ExecutionEntity> allExecutions) {
    for (ExecutionEntity childExecutionEntity : rootExecutionEntity.getExecutions()) {
        allExecutions.add(childExecutionEntity);
        collectChildExecutions(childExecutionEntity, allExecutions);
    }

    if (rootExecutionEntity.getSubProcessInstance() != null) {
        allExecutions.add(rootExecutionEntity.getSubProcessInstance());
        collectChildExecutions(rootExecutionEntity.getSubProcessInstance(), allExecutions);
    }
}
 
Example 3
Source File: TakeOutgoingSequenceFlowsOperation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected boolean allChildExecutionsEnded(ExecutionEntity parentExecutionEntity, ExecutionEntity executionEntityToIgnore) {
    for (ExecutionEntity childExecutionEntity : parentExecutionEntity.getExecutions()) {
        if (executionEntityToIgnore == null || !executionEntityToIgnore.getId().equals(childExecutionEntity.getId())) {
            if (!childExecutionEntity.isEnded()) {
                return false;
            }
            if (childExecutionEntity.getExecutions() != null && childExecutionEntity.getExecutions().size() > 0) {
                if (!allChildExecutionsEnded(childExecutionEntity, executionEntityToIgnore)) {
                    return false;
                }
            }
        }
    }
    return true;
}
 
Example 4
Source File: EndExecutionOperation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected boolean allChildExecutionsEnded(ExecutionEntity parentExecutionEntity, ExecutionEntity executionEntityToIgnore) {
    for (ExecutionEntity childExecutionEntity : parentExecutionEntity.getExecutions()) {
        if (executionEntityToIgnore == null || !executionEntityToIgnore.getId().equals(childExecutionEntity.getId())) {
            if (!childExecutionEntity.isEnded()) {
                return false;
            }
            if (childExecutionEntity.getExecutions() != null && childExecutionEntity.getExecutions().size() > 0) {
                if (!allChildExecutionsEnded(childExecutionEntity, executionEntityToIgnore)) {
                    return false;
                }
            }
        }
    }
    return true;
}
 
Example 5
Source File: FindActiveActivityIdsCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void collectActiveActivityIds(ExecutionEntity executionEntity, List<String> activeActivityIds) {
    if (executionEntity.isActive() && executionEntity.getActivityId() != null) {
        activeActivityIds.add(executionEntity.getActivityId());
    }

    for (ExecutionEntity childExecution : executionEntity.getExecutions()) {
        collectActiveActivityIds(childExecution, activeActivityIds);
    }
}
 
Example 6
Source File: EscalationPropagation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected static void executeEventHandler(Event event, ExecutionEntity parentExecution, ExecutionEntity currentExecution, String escalationCode, String escalationName) {
    ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
    FlowableEventDispatcher eventDispatcher = null;
    if (processEngineConfiguration != null) {
        eventDispatcher = processEngineConfiguration.getEventDispatcher();
    }
    
    if (eventDispatcher != null && eventDispatcher.isEnabled()) {
        processEngineConfiguration.getEventDispatcher().dispatchEvent(
                FlowableEventBuilder.createEscalationEvent(FlowableEngineEventType.ACTIVITY_ESCALATION_RECEIVED, event.getId(), escalationCode, 
                                escalationName, parentExecution.getId(), parentExecution.getProcessInstanceId(), parentExecution.getProcessDefinitionId()));
    }

    if (event instanceof StartEvent) {
        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();

        ExecutionEntity eventSubProcessExecution = executionEntityManager.createChildExecution(parentExecution);
        eventSubProcessExecution.setCurrentFlowElement(event.getSubProcess() != null ? event.getSubProcess() : event);
        CommandContextUtil.getAgenda().planContinueProcessOperation(eventSubProcessExecution);

    } else {
        ExecutionEntity boundaryExecution = null;
        List<? extends ExecutionEntity> childExecutions = parentExecution.getExecutions();
        for (ExecutionEntity childExecution : childExecutions) {
            if (childExecution != null
                    && childExecution.getActivityId() != null
                    && childExecution.getActivityId().equals(event.getId())) {
                boundaryExecution = childExecution;
            }
        }

        CommandContextUtil.getAgenda().planTriggerExecutionOperation(boundaryExecution);
    }
}
 
Example 7
Source File: ErrorPropagation.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
protected static void executeEventHandler(Event event, ExecutionEntity parentExecution, ExecutionEntity currentExecution, String errorId) {
    ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
    FlowableEventDispatcher eventDispatcher = null;
    if (processEngineConfiguration != null) {
        eventDispatcher = processEngineConfiguration.getEventDispatcher();
    }
    if (eventDispatcher != null && eventDispatcher.isEnabled()) {
        BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(parentExecution.getProcessDefinitionId());
        if (bpmnModel != null) {

            String errorCode = bpmnModel.getErrors().get(errorId);
            if (errorCode == null) {
                errorCode = errorId;
            }

            processEngineConfiguration.getEventDispatcher().dispatchEvent(
                    FlowableEventBuilder.createErrorEvent(FlowableEngineEventType.ACTIVITY_ERROR_RECEIVED, event.getId(), errorId, errorCode, parentExecution.getId(),
                            parentExecution.getProcessInstanceId(), parentExecution.getProcessDefinitionId()));
        }
    }

    if (event instanceof StartEvent) {
        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();

        if (parentExecution.isProcessInstanceType()) {
            executionEntityManager.deleteChildExecutions(parentExecution, null, true);
        } else if (!currentExecution.getParentId().equals(parentExecution.getId())) {
            CommandContextUtil.getAgenda().planDestroyScopeOperation(currentExecution);
        } else {
            executionEntityManager.deleteExecutionAndRelatedData(currentExecution, null, false);
        }

        ExecutionEntity eventSubProcessExecution = executionEntityManager.createChildExecution(parentExecution);
        if (event.getSubProcess() != null) {
            eventSubProcessExecution.setCurrentFlowElement(event.getSubProcess());
            CommandContextUtil.getActivityInstanceEntityManager().recordActivityStart(eventSubProcessExecution);
            ExecutionEntity subProcessStartEventExecution = executionEntityManager.createChildExecution(eventSubProcessExecution);
            subProcessStartEventExecution.setCurrentFlowElement(event);
            CommandContextUtil.getAgenda().planContinueProcessOperation(subProcessStartEventExecution);
            
        } else {
            eventSubProcessExecution.setCurrentFlowElement(event);
            CommandContextUtil.getAgenda().planContinueProcessOperation(eventSubProcessExecution);
        }

    } else {
        ExecutionEntity boundaryExecution = null;
        List<? extends ExecutionEntity> childExecutions = parentExecution.getExecutions();
        for (ExecutionEntity childExecution : childExecutions) {
            if (childExecution != null
                    && childExecution.getActivityId() != null
                    && childExecution.getActivityId().equals(event.getId())) {
                boundaryExecution = childExecution;
            }
        }

        CommandContextUtil.getAgenda().planTriggerExecutionOperation(boundaryExecution);
    }
}