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

The following examples show how to use org.flowable.engine.impl.persistence.entity.ExecutionEntity#getCurrentFlowElement() . 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: AbstractDynamicStateManager.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected ExecutionEntity deleteParentExecutions(String parentExecutionId, Collection<FlowElementMoveEntry> moveToFlowElements, Collection<String> executionIdsNotToDelete, CommandContext commandContext) {
    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);

    ExecutionEntity parentExecution = executionEntityManager.findById(parentExecutionId);
    if (parentExecution != null && parentExecution.getCurrentFlowElement() instanceof SubProcess) {
        SubProcess parentSubProcess = (SubProcess) parentExecution.getCurrentFlowElement();
        if (!isSubProcessAncestorOfAnyNewFlowElements(parentSubProcess.getId(), moveToFlowElements)) {
            ExecutionEntity toDeleteParentExecution = resolveParentExecutionToDelete(parentExecution, moveToFlowElements);
            ExecutionEntity finalDeleteExecution = null;
            if (toDeleteParentExecution != null) {
                finalDeleteExecution = toDeleteParentExecution;
            } else {
                finalDeleteExecution = parentExecution;
            }

            parentExecution = finalDeleteExecution.getParent();

            String flowElementIdsLine = printFlowElementIds(moveToFlowElements);
            executionEntityManager.deleteChildExecutions(finalDeleteExecution, executionIdsNotToDelete, null, "Change activity to " + flowElementIdsLine, true, null);
            executionEntityManager.deleteExecutionAndRelatedData(finalDeleteExecution, "Change activity to " + flowElementIdsLine, false, true, finalDeleteExecution.getCurrentFlowElement());
        }
    }

    return parentExecution;
}
 
Example 3
Source File: MultiInstanceActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void cleanupMiRoot(DelegateExecution execution) {
    // Delete multi instance root and all child executions.
    // Create a fresh execution to continue
    
    ExecutionEntity multiInstanceRootExecution = (ExecutionEntity) getMultiInstanceRootExecution(execution);
    FlowElement flowElement = multiInstanceRootExecution.getCurrentFlowElement();
    ExecutionEntity parentExecution = multiInstanceRootExecution.getParent();
    
    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();
    Collection<String> executionIdsNotToSendCancelledEventsFor = execution.isMultiInstanceRoot() ? null : Collections.singletonList(execution.getId());
    executionEntityManager.deleteChildExecutions(multiInstanceRootExecution, null, executionIdsNotToSendCancelledEventsFor, DELETE_REASON_END, true, flowElement);
    executionEntityManager.deleteRelatedDataForExecution(multiInstanceRootExecution, DELETE_REASON_END);
    executionEntityManager.delete(multiInstanceRootExecution);

    ExecutionEntity newExecution = executionEntityManager.createChildExecution(parentExecution);
    newExecution.setCurrentFlowElement(flowElement);
    super.leave(newExecution);
}
 
Example 4
Source File: EventSubscriptionUtil.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected static void scheduleEventAsync(EventSubscriptionEntity eventSubscriptionEntity, Object payload) {
    CommandContext commandContext = CommandContextUtil.getCommandContext();
    JobService jobService = CommandContextUtil.getJobService(commandContext);
    JobEntity message = jobService.createJob();
    message.setJobType(JobEntity.JOB_TYPE_MESSAGE);
    message.setJobHandlerType(ProcessEventJobHandler.TYPE);
    message.setElementId(eventSubscriptionEntity.getActivityId());
    message.setJobHandlerConfiguration(eventSubscriptionEntity.getId());
    message.setTenantId(eventSubscriptionEntity.getTenantId());
    
    String executionId = eventSubscriptionEntity.getExecutionId();
    
    if (StringUtils.isNotEmpty(executionId)) {
        ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager(commandContext).findById(executionId);
        FlowNode currentFlowElement = (FlowNode) execution.getCurrentFlowElement();

        if (currentFlowElement == null) {
            throw new FlowableException("Error while sending signal for event subscription '" + eventSubscriptionEntity.getId() + "': " + "no activity associated with event subscription");
        }
        
        EventSubscriptionUtil.processPayloadMap(payload, execution, currentFlowElement, commandContext);
    }

    jobService.scheduleAsyncJob(message);
}
 
Example 5
Source File: BpmnLoggingSessionUtil.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public static void fillLoggingData(ObjectNode loggingNode, ExecutionEntity executionEntity) {
    loggingNode.put("scopeDefinitionId", executionEntity.getProcessDefinitionId());
    
    fillScopeDefinitionInfo(executionEntity.getProcessDefinitionId(), loggingNode);
    
    FlowElement flowElement = executionEntity.getCurrentFlowElement();
    if (flowElement == null) {
        flowElement = executionEntity.getOriginatingCurrentFlowElement();
    }
    
    if (flowElement != null) {
        loggingNode.put("elementId", flowElement.getId());
        putIfNotNull("elementName", flowElement.getName(), loggingNode);
        loggingNode.put("elementType", flowElement.getClass().getSimpleName());
    }
}
 
Example 6
Source File: AbstractDynamicStateManager.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected ExecutionEntity deleteDirectParentExecutions(String parentExecutionId, Collection<FlowElementMoveEntry> moveToFlowElements, Collection<String> executionIdsNotToDelete, CommandContext commandContext) {
    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);

    ExecutionEntity parentExecution = executionEntityManager.findById(parentExecutionId);
    if (parentExecution.getCurrentFlowElement() instanceof SubProcess) {
        SubProcess parentSubProcess = (SubProcess) parentExecution.getCurrentFlowElement();
        if (!isSubProcessContainerOfAnyFlowElement(parentSubProcess.getId(), moveToFlowElements)) {
            ExecutionEntity toDeleteParentExecution = resolveParentExecutionToDelete(parentExecution, moveToFlowElements);
            ExecutionEntity finalDeleteExecution = null;
            if (toDeleteParentExecution != null) {
                finalDeleteExecution = toDeleteParentExecution;
            } else {
                finalDeleteExecution = parentExecution;
            }

            parentExecution = finalDeleteExecution.getParent();

            String flowElementIdsLine = printFlowElementIds(moveToFlowElements);
            executionEntityManager.deleteChildExecutions(finalDeleteExecution, executionIdsNotToDelete, null, "Change activity to " + flowElementIdsLine, true, null);
            executionEntityManager.deleteExecutionAndRelatedData(finalDeleteExecution, "Change activity to " + flowElementIdsLine, false, true, finalDeleteExecution.getCurrentFlowElement());
        }
    }

    return parentExecution;
}
 
Example 7
Source File: EndExecutionOperation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected boolean isInEventSubProcess(ExecutionEntity executionEntity) {
    ExecutionEntity currentExecutionEntity = executionEntity;
    while (currentExecutionEntity != null) {
        if (currentExecutionEntity.getCurrentFlowElement() instanceof EventSubProcess) {
            return true;
        }
        currentExecutionEntity = currentExecutionEntity.getParent();
    }
    return false;
}
 
Example 8
Source File: DefaultProcessInstanceService.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public List<IOParameter> getOutputParametersOfCaseTask(String executionId) {
    ExecutionEntity execution = (ExecutionEntity) processEngineConfiguration.getExecutionEntityManager().findById(executionId);
    if (execution == null) {
        throw new FlowableException("No execution could be found for id " + executionId);
    }
    
    FlowElement flowElement = execution.getCurrentFlowElement();
    if (!(flowElement instanceof CaseServiceTask)) {
        // The execution already processed this stage, there is no need to copy parameters anymore.
        // One possible reason for this is that the case task was terminated by a boundary event.
        return Collections.emptyList();
    }
    
    List<IOParameter> cmmnParameters = new ArrayList<>();
    
    CaseServiceTask caseServiceTask = (CaseServiceTask) flowElement;
    List<org.flowable.bpmn.model.IOParameter> parameters = caseServiceTask.getOutParameters();
    for (org.flowable.bpmn.model.IOParameter ioParameter : parameters) {
        IOParameter parameter = new IOParameter();
        parameter.setSource(ioParameter.getSource());
        parameter.setSourceExpression(ioParameter.getSourceExpression());
        parameter.setTarget(ioParameter.getTarget());
        parameter.setTargetExpression(ioParameter.getTargetExpression());
        cmmnParameters.add(parameter);
    }
    
    return cmmnParameters;
}
 
Example 9
Source File: AsyncContinuationJobHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
    ExecutionEntity executionEntity = (ExecutionEntity) variableScope;
    
    if (CommandContextUtil.getProcessEngineConfiguration(commandContext).isLoggingSessionEnabled()) {
        FlowElement flowElement = executionEntity.getCurrentFlowElement();
        BpmnLoggingSessionUtil.addAsyncActivityLoggingData("Executing async job for " + flowElement.getId() + ", with job id " + job.getId(),
                        LoggingSessionConstants.TYPE_SERVICE_TASK_EXECUTE_ASYNC_JOB, job, flowElement, executionEntity);
    }

    CommandContextUtil.getAgenda(commandContext).planContinueProcessSynchronousOperation(executionEntity);
}
 
Example 10
Source File: AsyncSendEventJobHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
    ExecutionEntity executionEntity = (ExecutionEntity) variableScope;
    FlowElement flowElement = executionEntity.getCurrentFlowElement();

    if (!(flowElement instanceof SendEventServiceTask)) {
        throw new FlowableException(String.format("unexpected activity type found for job %s, at activity %s", job.getId(), flowElement.getId()));
    }

    SendEventServiceTask sendEventServiceTask = (SendEventServiceTask) flowElement;
    SendEventTaskActivityBehavior sendEventTaskBehavior = CommandContextUtil.getProcessEngineConfiguration(commandContext).getActivityBehaviorFactory()
        .createSendEventTaskBehavior(sendEventServiceTask);
    sendEventTaskBehavior.setExecutedAsAsyncJob(true);
    sendEventTaskBehavior.execute(executionEntity);
}
 
Example 11
Source File: AbstractEventHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, CommandContext commandContext) {
    String executionId = eventSubscription.getExecutionId();
    ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager(commandContext).findById(executionId);
    FlowNode currentFlowElement = (FlowNode) execution.getCurrentFlowElement();

    if (currentFlowElement == null) {
        throw new FlowableException("Error while sending signal for event subscription '" + eventSubscription.getId() + "': " + "no activity associated with event subscription");
    }

    EventSubscriptionUtil.processPayloadMap(payload, execution, currentFlowElement, commandContext);

    CommandContextUtil.getAgenda().planTriggerExecutionOperation(execution);
}
 
Example 12
Source File: EndExecutionOperation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected List<ExecutionEntity> getActiveChildExecutionsForExecution(ExecutionEntityManager executionEntityManager, String executionId) {
    List<ExecutionEntity> activeChildExecutions = new ArrayList<>();
    List<ExecutionEntity> executions = executionEntityManager.findChildExecutionsByParentExecutionId(executionId);

    for (ExecutionEntity activeExecution : executions) {
        if (!(activeExecution.getCurrentFlowElement() instanceof BoundaryEvent)) {
            activeChildExecutions.add(activeExecution);
        }
    }

    return activeChildExecutions;
}
 
Example 13
Source File: EndExecutionOperation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected int getNumberOfActiveChildExecutionsForExecution(ExecutionEntityManager executionEntityManager, String executionId) {
    List<ExecutionEntity> executions = executionEntityManager.findChildExecutionsByParentExecutionId(executionId);
    int activeExecutions = 0;

    // Filter out the boundary events
    for (ExecutionEntity activeExecution : executions) {
        if (!(activeExecution.getCurrentFlowElement() instanceof BoundaryEvent)) {
            activeExecutions++;
        }
    }

    return activeExecutions;
}
 
Example 14
Source File: AbstractDynamicStateManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected boolean isSubProcessAncestorOfAnyExecution(String subProcessId, List<ExecutionEntity> executions) {
    for (ExecutionEntity execution : executions) {
        FlowElement executionElement = execution.getCurrentFlowElement();

        if (isSubProcessAncestor(subProcessId, executionElement)) {
            return true;
        }
    }
    return false;
}
 
Example 15
Source File: EndExecutionOperation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected ExecutionEntity handleRegularExecutionEnd(ExecutionEntityManager executionEntityManager, ExecutionEntity parentExecution) {
    ExecutionEntity executionToContinue = null;

    if (!parentExecution.isProcessInstanceType()
            && !(parentExecution.getCurrentFlowElement() instanceof SubProcess)) {
        parentExecution.setCurrentFlowElement(execution.getCurrentFlowElement());
    }

    if (execution.getCurrentFlowElement() instanceof SubProcess) {
        SubProcess currentSubProcess = (SubProcess) execution.getCurrentFlowElement();
        if (currentSubProcess.getOutgoingFlows().size() > 0) {
            // create a new execution to take the outgoing sequence flows
            executionToContinue = executionEntityManager.createChildExecution(parentExecution);
            executionToContinue.setCurrentFlowElement(execution.getCurrentFlowElement());

        } else {
            if (!parentExecution.getId().equals(parentExecution.getProcessInstanceId())) {
                // create a new execution to take the outgoing sequence flows
                executionToContinue = executionEntityManager.createChildExecution(parentExecution.getParent());
                executionToContinue.setCurrentFlowElement(parentExecution.getCurrentFlowElement());

                executionEntityManager.deleteChildExecutions(parentExecution, null, false);
                executionEntityManager.deleteExecutionAndRelatedData(parentExecution, null, false);

            } else {
                executionToContinue = parentExecution;
            }
        }

    } else {
        executionToContinue = parentExecution;
    }
    return executionToContinue;
}
 
Example 16
Source File: AbstractHistoryManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected String getActivityIdForExecution(ExecutionEntity execution) {
    String activityId = null;
    if (execution.getCurrentFlowElement() instanceof FlowNode) {
        activityId = execution.getCurrentFlowElement().getId();
    } else if (execution.getCurrentFlowElement() instanceof SequenceFlow
                    && execution.getCurrentFlowableListener() == null) { // while executing sequence flow listeners, we don't want historic activities
        activityId = ((SequenceFlow) execution.getCurrentFlowElement()).getSourceFlowElement().getId();
    }
    return activityId;
}
 
Example 17
Source File: ErrorPropagation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static boolean mapException(Exception e, ExecutionEntity execution, List<MapExceptionEntry> exceptionMap) {
    String errorCode = findMatchingExceptionMapping(e, exceptionMap);
    if (errorCode != null) {
        propagateError(errorCode, execution);
        return true;
    } else {
        ExecutionEntity callActivityExecution = null;
        ExecutionEntity parentExecution = execution.getParent();
        while (parentExecution != null && callActivityExecution == null) {
            if (parentExecution.getId().equals(parentExecution.getProcessInstanceId())) {
                if (parentExecution.getSuperExecution() != null) {
                    callActivityExecution = parentExecution.getSuperExecution();
                } else {
                    parentExecution = null;
                }
            } else {
                parentExecution = parentExecution.getParent();
            }
        }

        if (callActivityExecution != null) {
            CallActivity callActivity = (CallActivity) callActivityExecution.getCurrentFlowElement();
            if (CollectionUtil.isNotEmpty(callActivity.getMapExceptions())) {
                errorCode = findMatchingExceptionMapping(e, callActivity.getMapExceptions());
                if (errorCode != null) {
                    propagateError(errorCode, callActivityExecution);
                    return true;
                }
            }
        }

        return false;
    }
}
 
Example 18
Source File: AbstractOperation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to match the activityId of an execution with a FlowElement of the process definition referenced by the execution.
 */
protected FlowElement getCurrentFlowElement(final ExecutionEntity execution) {
    if (execution.getCurrentFlowElement() != null) {
        return execution.getCurrentFlowElement();
    } else if (execution.getCurrentActivityId() != null) {
        String processDefinitionId = execution.getProcessDefinitionId();
        org.flowable.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(processDefinitionId);
        String activityId = execution.getCurrentActivityId();
        FlowElement currentFlowElement = process.getFlowElement(activityId, true);
        return currentFlowElement;
    }
    return null;
}
 
Example 19
Source File: DefaultInternalJobManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void clearJobScopeLockInternal(Job job) {
    ExecutionEntityManager executionEntityManager = getExecutionEntityManager();
    ExecutionEntity execution = executionEntityManager.findById(job.getProcessInstanceId());
    if (execution != null) {
        executionEntityManager.clearProcessInstanceLockTime(execution.getId());
    }

    if (processEngineConfiguration.isLoggingSessionEnabled()) {
        ExecutionEntity localExecution = executionEntityManager.findById(job.getExecutionId());
        FlowElement flowElement = localExecution.getCurrentFlowElement();
        BpmnLoggingSessionUtil.addAsyncActivityLoggingData("Unlocking job for " + flowElement.getId() + ", with job id " + job.getId(),
                        LoggingSessionConstants.TYPE_SERVICE_TASK_UNLOCK_JOB, (JobEntity) job, flowElement, localExecution);
    }
}
 
Example 20
Source File: DebugInfoExecutionCreated.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public DebugInfoExecutionCreated(ExecutionEntity executionEntity) {
    this.executionEntity = executionEntity;
    this.flowElementId = executionEntity.getCurrentFlowElement() != null ? executionEntity.getCurrentFlowElement().getId() : null;
}