ExecutionEntityManagerImpl extends AbstractEntityManager<ExecutionEntity> implements ExecutionEntityManager { @Override public ExecutionEntity createSubprocessInstance(ProcessDefinition processDefinition, ExecutionEntity superExecutionEntity, String businessKey) { ExecutionEntity subProcessInstance = executionDataManager.create(); inheritCommonProperties(superExecutionEntity, subProcessInstance); subProcessInstance.setProcessDefinitionId(processDefinition.getId()); subProcessInstance.setProcessDefinitionKey(processDefinition.getKey()); subProcessInstance.setSuperExecution(superExecutionEntity); subProcessInstance.setRootProcessInstanceId(superExecutionEntity.getRootProcessInstanceId()); subProcessInstance.setScope(true); subProcessInstance.setStartUserId(Authentication.getAuthenticatedUserId()); subProcessInstance.setBusinessKey(businessKey); subProcessInstance.setAppVersion(processDefinition.getAppVersion()); insert(subProcessInstance, false); if (logger.isDebugEnabled()) { logger.debug("Child execution {} created with super execution {}", subProcessInstance, superExecutionEntity.getId()); } subProcessInstance.setProcessInstanceId(subProcessInstance.getId()); superExecutionEntity.setSubProcessInstance(subProcessInstance); if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) { Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, subProcessInstance)); } return subProcessInstance; } ExecutionEntityManagerImpl(ProcessEngineConfigurationImpl processEngineConfiguration, ExecutionDataManager executionDataManager); @Override void delete(ExecutionEntity entity); @Override void delete(ExecutionEntity entity, boolean fireDeleteEvent); @Override ExecutionEntity findSubProcessInstanceBySuperExecutionId(String superExecutionId); @Override List<ExecutionEntity> findChildExecutionsByParentExecutionId(String parentExecutionId); @Override List<ExecutionEntity> findChildExecutionsByProcessInstanceId(String processInstanceId); @Override List<ExecutionEntity> findExecutionsByParentExecutionAndActivityIds(final String parentExecutionId, final Collection<String> activityIds); @Override long findExecutionCountByQueryCriteria(ExecutionQueryImpl executionQuery); @Override List<ExecutionEntity> findExecutionsByQueryCriteria(ExecutionQueryImpl executionQuery, Page page); @Override long findProcessInstanceCountByQueryCriteria(ProcessInstanceQueryImpl executionQuery); @Override List<ProcessInstance> findProcessInstanceByQueryCriteria(ProcessInstanceQueryImpl executionQuery); @Override ExecutionEntity findByRootProcessInstanceId(String rootProcessInstanceId); @Override List<ProcessInstance> findProcessInstanceAndVariablesByQueryCriteria(ProcessInstanceQueryImpl executionQuery); @Override Collection<ExecutionEntity> findInactiveExecutionsByProcessInstanceId(final String processInstanceId); @Override Collection<ExecutionEntity> findInactiveExecutionsByActivityIdAndProcessInstanceId(final String activityId, final String processInstanceId); @Override List<Execution> findExecutionsByNativeQuery(Map<String, Object> parameterMap, int firstResult, int maxResults); @Override List<ProcessInstance> findProcessInstanceByNativeQuery(Map<String, Object> parameterMap, int firstResult, int maxResults); @Override long findExecutionCountByNativeQuery(Map<String, Object> parameterMap); @Override ExecutionEntity createProcessInstanceExecution(ProcessDefinition processDefinition, String businessKey, String tenantId, String initiatorVariableName); ExecutionEntity updateProcessInstanceStartDate(ExecutionEntity processInstanceExecution); @Override ExecutionEntity createChildExecution(ExecutionEntity parentExecutionEntity); @Override ExecutionEntity createSubprocessInstance(ProcessDefinition processDefinition, ExecutionEntity superExecutionEntity, String businessKey); @Override void updateExecutionTenantIdForDeployment(String deploymentId, String newTenantId); @Override void deleteProcessInstancesByProcessDefinition(String processDefinitionId, String deleteReason, boolean cascade); @Override void deleteProcessInstance(String processInstanceId, String deleteReason, boolean cascade); @Override void deleteExecutionAndRelatedData(ExecutionEntity executionEntity, String deleteReason); @Override void cancelExecutionAndRelatedData(ExecutionEntity executionEntity, String deleteReason); @Override void deleteProcessInstanceExecutionEntity(String processInstanceId,
      String currentFlowElementId, String deleteReason, boolean cascade, boolean cancel); @Override void deleteChildExecutions(ExecutionEntity executionEntity, String deleteReason); @Override void cancelChildExecutions(ExecutionEntity executionEntity, String deleteReason); List<ExecutionEntity> collectChildren(ExecutionEntity executionEntity); @Override ExecutionEntity findFirstScope(ExecutionEntity executionEntity); @Override ExecutionEntity findFirstMultiInstanceRoot(ExecutionEntity executionEntity); @Override void updateProcessInstanceLockTime(String processInstanceId); @Override void clearProcessInstanceLockTime(String processInstanceId); @Override String updateProcessInstanceBusinessKey(ExecutionEntity executionEntity, String businessKey); ExecutionDataManager getExecutionDataManager(); void setExecutionDataManager(ExecutionDataManager executionDataManager);  }
@Test public void should_createSubProcess() { ProcessDefinitionEntity processDefinition = new ProcessDefinitionEntityImpl(); processDefinition.setId("processDefinitionId"); processDefinition.setKey("processDefinitionKey"); processDefinition.setAppVersion(5); ExecutionEntityImpl superExecution = new ExecutionEntityImpl(); superExecution.executions = new ArrayList<>(); superExecution.setSubProcessInstance(null); superExecution.setRootProcessInstanceId("rootProcessInstanceId"); superExecution.setTenantId("tenantId"); superExecution.setProcessInstanceId("superProcessInstanceId"); String businessKey = "businessKey"; ExecutionEntity subProcessInstance = new ExecutionEntityImpl(); subProcessInstance.setId("subProcessInstanceId"); given(executionDataManager.create()).willReturn(subProcessInstance); Date startTime = new Date(); given(clock.getCurrentTime()).willReturn(startTime); ExecutionEntity subProcessResult = executionEntityManager.createSubprocessInstance(processDefinition, superExecution, businessKey); assertThat(subProcessResult.isActive()).isTrue(); assertThat(subProcessResult.getRootProcessInstanceId()).isEqualTo("rootProcessInstanceId"); assertThat(subProcessResult.getStartTime()).isEqualTo(startTime); assertThat(subProcessResult.getTenantId()).isEqualTo("tenantId"); assertThat(subProcessResult.getSuperExecution()).isEqualTo(superExecution); assertThat(subProcessResult.getProcessDefinitionId()).isEqualTo("processDefinitionId"); assertThat(subProcessResult.getProcessDefinitionKey()).isEqualTo("processDefinitionKey"); assertThat(subProcessResult.getProcessInstanceId()).isEqualTo("subProcessInstanceId"); assertThat(subProcessResult.getParentProcessInstanceId()).isEqualTo("superProcessInstanceId"); assertThat(subProcessResult.isScope()).isTrue(); assertThat(subProcessResult.getBusinessKey()).isEqualTo(businessKey); assertThat(subProcessResult.getAppVersion()).isEqualTo(5); verify(executionDataManager).insert(subProcessInstance); verify(eventDispatcher).isEnabled(); assertThat(superExecution.getSubProcessInstance()).isEqualTo(subProcessInstance); }