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

The following examples show how to use org.flowable.engine.impl.persistence.entity.ExecutionEntity#getActivityId() . 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: SetProcessDefinitionVersionCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void validateAndSwitchVersionOfExecution(CommandContext commandContext, ExecutionEntity execution, ProcessDefinition newProcessDefinition) {
    // check that the new process definition version contains the current activity
    org.flowable.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(newProcessDefinition.getId());
    if (execution.getActivityId() != null && process.getFlowElement(execution.getActivityId(), true) == null) {
        throw new FlowableException("The new process definition " + "(key = '" + newProcessDefinition.getKey() + "') " + "does not contain the current activity " + "(id = '"
                + execution.getActivityId() + "') " + "of the process instance " + "(id = '" + processInstanceId + "').");
    }

    // switch the process instance to the new process definition version
    execution.setProcessDefinitionId(newProcessDefinition.getId());
    execution.setProcessDefinitionName(newProcessDefinition.getName());
    execution.setProcessDefinitionKey(newProcessDefinition.getKey());

    // and change possible existing tasks (as the process definition id is stored there too)
    List<TaskEntity> tasks = CommandContextUtil.getTaskService(commandContext).findTasksByExecutionId(execution.getId());
    Clock clock = commandContext.getCurrentEngineConfiguration().getClock();
    for (TaskEntity taskEntity : tasks) {
        taskEntity.setProcessDefinitionId(newProcessDefinition.getId());
        CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordTaskInfoChange(taskEntity, clock.getCurrentTime());
    }
}
 
Example 2
Source File: InactiveExecutionsInActivityAndProcInstMatcher.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 activityId = (String) paramMap.get("activityId");
    String processInstanceId = (String) paramMap.get("processInstanceId");

    return executionEntity.getProcessInstanceId() != null
            && executionEntity.getProcessInstanceId().equals(processInstanceId)
            && !executionEntity.isActive()
            && executionEntity.getActivityId() != null
            && executionEntity.getActivityId().equals(activityId);
}
 
Example 3
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 4
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 5
Source File: ExecutionQueryImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked" })
@Override
public List<Execution> executeList(CommandContext commandContext) {
    ensureVariablesInitialized();
    
    ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
    if (processEngineConfiguration.getExecutionQueryInterceptor() != null) {
        processEngineConfiguration.getExecutionQueryInterceptor().beforeExecutionQueryExecute(this);
    }
    
    List<?> executions = CommandContextUtil.getExecutionEntityManager(commandContext).findExecutionsByQueryCriteria(this);

    if (processEngineConfiguration.getPerformanceSettings().isEnableLocalization()) {
        for (ExecutionEntity execution : (List<ExecutionEntity>) executions) {
            String activityId = null;
            if (execution.getId().equals(execution.getProcessInstanceId())) {
                if (execution.getProcessDefinitionId() != null) {
                    ProcessDefinition processDefinition = processEngineConfiguration
                            .getDeploymentManager()
                            .findDeployedProcessDefinitionById(execution.getProcessDefinitionId());
                    activityId = processDefinition.getKey();
                }

            } else {
                activityId = execution.getActivityId();
            }

            if (activityId != null) {
                localize(execution, activityId);
            }
        }
    }
    
    if (processEngineConfiguration.getExecutionQueryInterceptor() != null) {
        processEngineConfiguration.getExecutionQueryInterceptor().afterExecutionQueryExecute(this, (List<Execution>) executions);
    }

    return (List<Execution>) executions;
}
 
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: InactiveExecutionsInActivityMatcher.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isRetained(ExecutionEntity entity, Object parameter) {
    Map<String, Object> paramMap = (Map<String, Object>) parameter;
    String activityId = (String) paramMap.get("activityId");
    return !entity.isActive() && entity.getActivityId() != null && entity.getActivityId().equals(activityId);
}
 
Example 8
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);
    }
}