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

The following examples show how to use org.flowable.engine.impl.persistence.entity.ExecutionEntity#isMultiInstanceRoot() . 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: AddMultiInstanceExecutionCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected ExecutionEntity searchForMultiInstanceActivity(String activityId, String parentExecutionId, ExecutionEntityManager executionEntityManager) {
    List<ExecutionEntity> childExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(parentExecutionId);
    
    ExecutionEntity miExecution = null;
    for (ExecutionEntity childExecution : childExecutions) {
        if (activityId.equals(childExecution.getActivityId()) && childExecution.isMultiInstanceRoot()) {
            if (miExecution != null) {
                throw new FlowableException("Multiple multi instance executions found for activity id " + activityId);
            }
            miExecution = childExecution;
        }
        
        ExecutionEntity childMiExecution = searchForMultiInstanceActivity(activityId, childExecution.getId(), executionEntityManager);
        if (childMiExecution != null) {
            if (miExecution != null) {
                throw new FlowableException("Multiple multi instance executions found for activity id " + activityId);
            }
            miExecution = childMiExecution;
        }
    }
    
    return miExecution;
}
 
Example 2
Source File: ContinueProcessOperation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected boolean hasMultiInstanceRootExecution(ExecutionEntity execution, FlowNode flowNode) {
    ExecutionEntity currentExecution = execution.getParent();
    while (currentExecution != null) {
        if (currentExecution.isMultiInstanceRoot() && flowNode.getId().equals(currentExecution.getActivityId())) {
            return true;
        }
        currentExecution = currentExecution.getParent();
    }
    return false;
}
 
Example 3
Source File: DeleteMultiInstanceExecutionCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected ExecutionEntity getMultiInstanceRootExecution(ExecutionEntity executionEntity) {
    ExecutionEntity multiInstanceRootExecution = null;
    ExecutionEntity currentExecution = executionEntity;
    while (currentExecution != null && multiInstanceRootExecution == null && currentExecution.getParent() != null) {
        if (currentExecution.isMultiInstanceRoot()) {
            multiInstanceRootExecution = currentExecution;
        } else {
            currentExecution = currentExecution.getParent();
        }
    }
    return multiInstanceRootExecution;
}
 
Example 4
Source File: AsyncHistoryManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void recordHistoricDetailVariableCreate(VariableInstanceEntity variable, ExecutionEntity sourceActivityExecution, boolean useActivityId,
    String activityInstanceId, Date createTime) {

    String processDefinitionId = getProcessDefinitionId(variable, sourceActivityExecution);
    
    if (isHistoryLevelAtLeast(HistoryLevel.FULL, processDefinitionId)) {
        ObjectNode data = processEngineConfiguration.getObjectMapper().createObjectNode();
        addCommonVariableFields(variable, data);
        
        if (sourceActivityExecution != null && sourceActivityExecution.isMultiInstanceRoot()) {
            putIfNotNull(data, HistoryJsonConstants.IS_MULTI_INSTANCE_ROOT_EXECUTION, true);
        }
       
        putIfNotNull(data, HistoryJsonConstants.CREATE_TIME, createTime);

        putIfNotNull(data, HistoryJsonConstants.RUNTIME_ACTIVITY_INSTANCE_ID, activityInstanceId);
        if (useActivityId && sourceActivityExecution != null) {
            String activityId = getActivityIdForExecution(sourceActivityExecution);
            if (activityId != null) {
                putIfNotNull(data, HistoryJsonConstants.ACTIVITY_ID, activityId);
                putIfNotNull(data, HistoryJsonConstants.SOURCE_EXECUTION_ID, sourceActivityExecution.getId());
            }
        }
        
        getAsyncHistorySession().addHistoricData(getJobServiceConfiguration(), HistoryJsonConstants.TYPE_HISTORIC_DETAIL_VARIABLE_UPDATE, data);
    }
}
 
Example 5
Source File: DynamicMultiInstanceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/bpmn/multiinstance/MultiInstanceTest.testNestedParallelCallActivity.bpmn20.xml",
    "org/flowable/engine/test/bpmn/multiinstance/MultiInstanceTest.externalSubProcess.bpmn20.xml" })
public void testDeleteNestedParallelCallActivity() {
    if (!processEngineConfiguration.isAsyncHistoryEnabled()) {
        String procId = runtimeService.startProcessInstanceByKey("miNestedParallelCallActivity").getId();
        
        List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(procId).onlyChildExecutions().list();
        List<Execution> childExecutions = null;
        for (Execution execution : executions) {
            ExecutionEntity executionEntity = (ExecutionEntity) execution;
            if (executionEntity.isMultiInstanceRoot()) {
                childExecutions = runtimeService.createExecutionQuery().parentId(executionEntity.getId()).list();
            }
        }
        
        List<org.flowable.task.api.Task> tasks = taskService.createTaskQuery().list();
        assertEquals(14, tasks.size());
        
        assertNotNull(childExecutions);
        assertEquals(7, childExecutions.size());
        runtimeService.deleteMultiInstanceExecution(childExecutions.get(2).getId(), false);
        
        tasks = taskService.createTaskQuery().list();
        assertEquals(12, tasks.size());
        
        for (int i = 0; i < 12; i++) {
            taskService.complete(tasks.get(i).getId());
        }
        
        assertProcessEnded(procId);
    }
}
 
Example 6
Source File: DynamicMultiInstanceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {"org/flowable/engine/test/bpmn/multiinstance/DynamicMultiInstanceTest.testSequentialSubProcessCompletionCondition.bpmn20.xml"})
public void testDeleteSequentialSubProcessCompletionCondition() {
    if (!processEngineConfiguration.isAsyncHistoryEnabled()) {
        String procId = runtimeService.startProcessInstanceByKey("miSequentialSubprocessCompletionCondition").getId();
        
        List<Execution> executions = runtimeService.createExecutionQuery().parentId(procId).list();
        ExecutionEntity miExecution = null;
        for (Execution execution : executions) {
            ExecutionEntity executionEntity = (ExecutionEntity) execution;
            if (executionEntity.isMultiInstanceRoot()) {
                miExecution = executionEntity;
                break;
            }
        }
        
        assertNotNull(miExecution);
        
        List<Execution> childExecutions = runtimeService.createExecutionQuery().parentId(miExecution.getId()).list();
        runtimeService.deleteMultiInstanceExecution(childExecutions.get(0).getId(), false);

        TaskQuery query = taskService.createTaskQuery().orderByTaskName().asc();
        for (int i = 0; i < 3; i++) {
            List<org.flowable.task.api.Task> tasks = query.list();
            assertEquals(2, tasks.size());

            assertEquals("task one", tasks.get(0).getName());
            assertEquals("task two", tasks.get(1).getName());

            taskService.complete(tasks.get(0).getId());
            taskService.complete(tasks.get(1).getId());
        }

        assertProcessEnded(procId);
    }
}
 
Example 7
Source File: DynamicMultiInstanceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {"org/flowable/engine/test/bpmn/multiinstance/DynamicMultiInstanceTest.testSequentialSubProcessCompletionCondition.bpmn20.xml"})
public void testDeleteSequentialSubProcessAsCompleted() {
    if (!processEngineConfiguration.isAsyncHistoryEnabled()) {
        String procId = runtimeService.startProcessInstanceByKey("miSequentialSubprocessCompletionCondition").getId();
        
        List<Execution> executions = runtimeService.createExecutionQuery().parentId(procId).list();
        ExecutionEntity miExecution = null;
        for (Execution execution : executions) {
            ExecutionEntity executionEntity = (ExecutionEntity) execution;
            if (executionEntity.isMultiInstanceRoot()) {
                miExecution = executionEntity;
                break;
            }
        }
        
        assertNotNull(miExecution);
        
        List<Execution> childExecutions = runtimeService.createExecutionQuery().parentId(miExecution.getId()).list();
        runtimeService.deleteMultiInstanceExecution(childExecutions.get(0).getId(), true);

        TaskQuery query = taskService.createTaskQuery().orderByTaskName().asc();
        for (int i = 0; i < 2; i++) {
            List<org.flowable.task.api.Task> tasks = query.list();
            assertEquals(2, tasks.size());

            assertEquals("task one", tasks.get(0).getName());
            assertEquals("task two", tasks.get(1).getName());

            taskService.complete(tasks.get(0).getId());
            taskService.complete(tasks.get(1).getId());
        }

        assertProcessEnded(procId);
    }
}