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

The following examples show how to use org.flowable.engine.impl.persistence.entity.ExecutionEntity#getProcessInstanceId() . 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: FlowableProcessStartedEventImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public FlowableProcessStartedEventImpl(final Object entity, final Map variables, final boolean localScope) {
    super(entity, variables, localScope, FlowableEngineEventType.PROCESS_STARTED);
    if (entity instanceof ExecutionEntity) {
        ExecutionEntity executionEntity = (ExecutionEntity) entity;
        if (!executionEntity.isProcessInstanceType()) {
            executionEntity = executionEntity.getParent();
        }

        final ExecutionEntity superExecution = executionEntity.getSuperExecution();
        if (superExecution != null) {
            this.nestedProcessDefinitionId = superExecution.getProcessDefinitionId();
            this.nestedProcessInstanceId = superExecution.getProcessInstanceId();
        } else {
            this.nestedProcessDefinitionId = null;
            this.nestedProcessInstanceId = null;
        }

    } else {
        this.nestedProcessDefinitionId = null;
        this.nestedProcessInstanceId = null;
    }
}
 
Example 2
Source File: EndExecutionOperation.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void scheduleAsyncCompleteCallActivity(ExecutionEntity superExecutionEntity, ExecutionEntity childProcessInstanceExecutionEntity) {
    JobService jobService = CommandContextUtil.getJobService(commandContext);
    
    JobEntity job = jobService.createJob();
    
    // Needs to be the parent process instance, as the parent needs to be locked to avoid concurrency when multiple call activities are ended
    job.setExecutionId(superExecutionEntity.getId()); 
    
    // Child execution of subprocess is passed as configuration
    job.setJobHandlerConfiguration(childProcessInstanceExecutionEntity.getId());
    
    String processInstanceId = superExecutionEntity.getProcessInstanceId() != null ? superExecutionEntity.getProcessInstanceId() : superExecutionEntity.getId();
    job.setProcessInstanceId(processInstanceId);
    job.setProcessDefinitionId(childProcessInstanceExecutionEntity.getProcessDefinitionId());
    job.setElementId(superExecutionEntity.getCurrentFlowElement().getId());
    job.setElementName(superExecutionEntity.getCurrentFlowElement().getName());
    job.setTenantId(childProcessInstanceExecutionEntity.getTenantId());
    job.setJobHandlerType(AsyncCompleteCallActivityJobHandler.TYPE);
    
    superExecutionEntity.getJobs().add(job);
    
    jobService.createAsyncJob(job, true); // Always exclusive to avoid concurrency problems
    jobService.scheduleAsyncJob(job);
}
 
Example 3
Source File: SetProcessInstanceBusinessKeyCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
    ExecutionEntityManager executionManager = CommandContextUtil.getExecutionEntityManager(commandContext);
    ExecutionEntity processInstance = executionManager.findById(processInstanceId);
    if (processInstance == null) {
        throw new FlowableObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
    } else if (!processInstance.isProcessInstanceType()) {
        throw new FlowableIllegalArgumentException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'"
                + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
    }

    if (Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, processInstance.getProcessDefinitionId())) {
        CommandContextUtil.getProcessEngineConfiguration(commandContext).getFlowable5CompatibilityHandler().updateBusinessKey(processInstanceId, businessKey);
        return null;
    }

    executionManager.updateProcessInstanceBusinessKey(processInstance, businessKey);

    return null;
}
 
Example 4
Source File: LogMDC.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static void putMDCExecution(ExecutionEntity e) {
    if (e.getId() != null)
        MDC.put(LOG_MDC_EXECUTION_ID, e.getId());
    if (e.getProcessDefinitionId() != null)
        MDC.put(LOG_MDC_PROCESSDEFINITION_ID, e.getProcessDefinitionId());
    if (e.getProcessInstanceId() != null)
        MDC.put(LOG_MDC_PROCESSINSTANCE_ID, e.getProcessInstanceId());
    if (e.getProcessInstanceBusinessKey() != null)
        MDC.put(LOG_MDC_BUSINESS_KEY, e.getProcessInstanceBusinessKey());

}
 
Example 5
Source File: FlowableProcessTerminatedEventImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public FlowableProcessTerminatedEventImpl(ExecutionEntity execution, Object cause) {
    super(execution, FlowableEngineEventType.PROCESS_COMPLETED_WITH_TERMINATE_END_EVENT);
    if (!execution.isProcessInstanceType()) {
        throw new FlowableException("Execution '"+ execution +"' is not a processInstance");
    }
    
    this.subScopeId = execution.getId();
    this.scopeId = execution.getProcessInstanceId();
    this.scopeDefinitionId = execution.getProcessDefinitionId();
    this.scopeType = ScopeTypes.BPMN;
    this.cause = cause;
}
 
Example 6
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 7
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 8
Source File: InactiveExecutionsByProcInstMatcher.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 processInstanceId = (String) paramMap.get("processInstanceId");

    return executionEntity.getProcessInstanceId() != null
            && executionEntity.getProcessInstanceId().equals(processInstanceId)
            && !executionEntity.isActive();
}
 
Example 9
Source File: SetProcessDefinitionVersionCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
    // check that the new process definition is just another version of the same
    // process definition that the process instance is using
    ExecutionEntityManager executionManager = CommandContextUtil.getExecutionEntityManager(commandContext);
    ExecutionEntity processInstance = executionManager.findById(processInstanceId);
    if (processInstance == null) {
        throw new FlowableObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
    } else if (!processInstance.isProcessInstanceType()) {
        throw new FlowableIllegalArgumentException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'"
                + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
    }

    DeploymentManager deploymentCache = CommandContextUtil.getProcessEngineConfiguration(commandContext).getDeploymentManager();
    ProcessDefinition currentProcessDefinition = deploymentCache.findDeployedProcessDefinitionById(processInstance.getProcessDefinitionId());

    ProcessDefinition newProcessDefinition = deploymentCache
            .findDeployedProcessDefinitionByKeyAndVersionAndTenantId(currentProcessDefinition.getKey(), processDefinitionVersion, currentProcessDefinition.getTenantId());

    if (Flowable5Util.isFlowable5ProcessDefinition(currentProcessDefinition, commandContext) && !Flowable5Util
        .isFlowable5ProcessDefinition(newProcessDefinition, commandContext)) {
        throw new FlowableIllegalArgumentException("The current process definition (id = '" + currentProcessDefinition.getId() + "') is a v5 definition."
            + " However the new process definition (id = '" + newProcessDefinition.getId() + "') is not a v5 definition.");
    }

    validateAndSwitchVersionOfExecution(commandContext, processInstance, newProcessDefinition);

    // switch the historic process instance to the new process definition version
    CommandContextUtil.getHistoryManager(commandContext).recordProcessDefinitionChange(processInstanceId, newProcessDefinition.getId());

    // switch all sub-executions of the process instance to the new process definition version
    Collection<ExecutionEntity> childExecutions = executionManager.findChildExecutionsByProcessInstanceId(processInstanceId);
    for (ExecutionEntity executionEntity : childExecutions) {
        validateAndSwitchVersionOfExecution(commandContext, executionEntity, newProcessDefinition);
    }

    return null;
}
 
Example 10
Source File: ExecutionByProcessInstanceMatcher.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.getProcessInstanceId() != null && entity.getProcessInstanceId().equals((String) parameter);
}