Java源码示例:org.flowable.engine.RuntimeService

示例1
private void setVariableInParentProcess(DelegateExecution execution, String variablePrefix, Object variableValue) {
    CloudApplicationExtended cloudApplication = VariableHandling.get(execution, Variables.APP_TO_PROCESS);
    if (cloudApplication == null) {
        throw new IllegalStateException(Messages.CANNOT_DETERMINE_CURRENT_APPLICATION);
    }

    String moduleName = cloudApplication.getModuleName();
    if (moduleName == null) {
        throw new IllegalStateException(Messages.CANNOT_DETERMINE_MODULE_NAME);
    }
    String exportedVariableName = variablePrefix + moduleName;

    RuntimeService runtimeService = Context.getProcessEngineConfiguration()
                                           .getRuntimeService();

    String superExecutionId = execution.getParentId();
    Execution superExecutionResult = runtimeService.createExecutionQuery()
                                                   .executionId(superExecutionId)
                                                   .singleResult();
    superExecutionId = superExecutionResult.getSuperExecutionId();

    byte[] binaryJson = variableValue == null ? null : JsonUtil.toJsonBinary(variableValue);
    runtimeService.setVariable(superExecutionId, exportedVariableName, binaryJson);
}
 
示例2
@Override
public void notify(DelegateExecution execution) {
    boolean isServiceUpdated = VariableHandling.get(execution, Variables.IS_SERVICE_UPDATED);
    String serviceName = VariableHandling.get(execution, Variables.SERVICE_TO_PROCESS_NAME);
    if (serviceName == null) {
        throw new IllegalStateException("Unable to determine service update status.");
    }
    String exportedVariableName = Constants.VAR_IS_SERVICE_UPDATED_VAR_PREFIX + serviceName;

    RuntimeService runtimeService = Context.getProcessEngineConfiguration()
                                           .getRuntimeService();

    String superExecutionId = execution.getParentId();
    Execution superExecutionResult = runtimeService.createExecutionQuery()
                                                   .executionId(superExecutionId)
                                                   .singleResult();
    superExecutionId = superExecutionResult.getSuperExecutionId();

    runtimeService.setVariable(superExecutionId, exportedVariableName, isServiceUpdated);

}
 
示例3
@Test
@Deployment(resources = { "org/activiti/engine/test/bpmn/async/AsyncTaskTest.testAsyncTask.bpmn20.xml" })
public void testWaitForJobs() {
    RuntimeService runtimeService = activitiRule.getRuntimeService();
    ManagementService managementService = activitiRule.getManagementService();

    // start process
    runtimeService.startProcessInstanceByKey("asyncTask");

    // now there should be one job in the database:
    assertEquals(1, managementService.createJobQuery().count());

    JobTestHelper.waitForJobExecutorToProcessAllJobs(activitiRule, 7000L, 500L);

    // the job is done
    assertEquals(0, managementService.createJobQuery().count());
}
 
示例4
@Bean
CommandLineRunner init(
        final AnalysingService analysingService,
        final RuntimeService runtimeService) {
    return new CommandLineRunner() {
        @Override
        public void run(String... strings) throws Exception {

            String integrationGatewayProcess = "integrationGatewayProcess";

            runtimeService.startProcessInstanceByKey(
                    integrationGatewayProcess, Collections.singletonMap("customerId", (Object) 232L));

            System.out.println("projectId=" + analysingService.getStringAtomicReference().get());

        }
    };
}
 
示例5
@Test
public void testLaunchingGatewayProcessDefinition() throws Exception {
    RepositoryService repositoryService = applicationContext.getBean(RepositoryService.class);
    RuntimeService runtimeService = applicationContext.getBean(RuntimeService.class);
    ProcessEngine processEngine = applicationContext.getBean(ProcessEngine.class);

    assertThat(processEngine).as("the process engine should not be null").isNotNull();
    assertThat(repositoryService).as("we should have a default repositoryService included").isNotNull();
    String integrationGatewayProcess = "integrationGatewayProcess";
    List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery()
            .processDefinitionKey(integrationGatewayProcess)
            .list();
    ProcessDefinition processDefinition = processDefinitionList.iterator().next();
    assertThat(processDefinition.getKey()).isEqualTo(integrationGatewayProcess);
    Map<String, Object> vars = new HashMap<>();
    vars.put("customerId", 232);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(integrationGatewayProcess, vars);
    assertThat(processInstance).as("the processInstance should not be null").isNotNull();
    assertThat(applicationContext.getBean(Application.AnalysingService.class)
            .getStringAtomicReference().get()).isEqualTo(projectId);
}
 
示例6
@Test
public void http() throws Exception {
    Assert.assertTrue(muleContext.isStarted());

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    Deployment deployment = processEngine.getRepositoryService().createDeployment()
            .addClasspathResource("org/activiti/mule/testHttp.bpmn20.xml")
            .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
            .deploy();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
    Assert.assertFalse(processInstance.isEnded());
    Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
    Assert.assertEquals(20, result);
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
    processEngine.getRepositoryService().deleteDeployment(deployment.getId());
    assertAndEnsureCleanDb(processEngine);
    ProcessEngines.destroy();
}
 
示例7
@Test
public void httpWithBasicAuth() throws Exception {
    Assert.assertTrue(muleContext.isStarted());

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    Deployment deployment = processEngine.getRepositoryService()
            .createDeployment()
            .addClasspathResource("org/activiti/mule/testHttpBasicAuth.bpmn20.xml")
            .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
            .deploy();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
    Assert.assertFalse(processInstance.isEnded());
    Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
    Assert.assertEquals(10, result);
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
    processEngine.getRepositoryService().deleteDeployment(deployment.getId());
    assertAndEnsureCleanDb(processEngine);
    ProcessEngines.destroy();
}
 
示例8
@Test
public void send() throws Exception {
    Assert.assertTrue(muleContext.isStarted());

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    Deployment deployment = repositoryService.createDeployment()
            .addClasspathResource("org/activiti/mule/testVM.bpmn20.xml")
            .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
            .deploy();

    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
    Assert.assertFalse(processInstance.isEnded());
    Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
    Assert.assertEquals(30, result);
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");

    processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
    repositoryService.deleteDeployment(deployment.getId());
    assertAndEnsureCleanDb(processEngine);
    ProcessEngines.destroy();
}
 
示例9
@Test
public void http() throws Exception {
    Assert.assertTrue(muleContext.isStarted());

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    Deployment deployment = processEngine.getRepositoryService().createDeployment().addClasspathResource("org/flowable/mule/testHttp.bpmn20.xml").deploy();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
    Assert.assertFalse(processInstance.isEnded());
    Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
    Assert.assertEquals(20, result);
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
    processEngine.getRepositoryService().deleteDeployment(deployment.getId());
    assertAndEnsureCleanDb(processEngine);
    ProcessEngines.destroy();
}
 
示例10
@Test
public void httpWithBasicAuth() throws Exception {
    Assert.assertTrue(muleContext.isStarted());

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    Deployment deployment = processEngine.getRepositoryService().createDeployment().addClasspathResource("org/flowable/mule/testHttpBasicAuth.bpmn20.xml").deploy();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
    Assert.assertFalse(processInstance.isEnded());
    Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
    Assert.assertEquals(10, result);
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
    processEngine.getRepositoryService().deleteDeployment(deployment.getId());
    assertAndEnsureCleanDb(processEngine);
    ProcessEngines.destroy();
}
 
示例11
@Test
public void send() throws Exception {
    Assert.assertTrue(muleContext.isStarted());

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    Deployment deployment = repositoryService.createDeployment().addClasspathResource("org/flowable/mule/testVM.bpmn20.xml").deploy();

    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
    Assert.assertFalse(processInstance.isEnded());
    Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
    Assert.assertEquals(30, result);
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");

    processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
    repositoryService.deleteDeployment(deployment.getId());
    assertAndEnsureCleanDb(processEngine);
    ProcessEngines.destroy();
}
 
示例12
@Test
@Deployment(resources = { "org/flowable/engine/test/bpmn/async/AsyncTaskTest.testAsyncTask.bpmn20.xml" })
public void testWaitForJobs() {
    RuntimeService runtimeService = activitiRule.getRuntimeService();
    ManagementService managementService = activitiRule.getManagementService();

    // start process
    runtimeService.startProcessInstanceByKey("asyncTask");

    // now there should be one job in the database:
    assertThat(managementService.createJobQuery().count()).isEqualTo(1);

    JobTestHelper.waitForJobExecutorToProcessAllJobs(activitiRule, 7000L, 500L);

    // the job is done
    assertThat(managementService.createJobQuery().count()).isZero();
}
 
示例13
@Test
@Deployment(resources = {
        "org/flowable/form/engine/test/deployment/oneTaskProcess.bpmn20.xml",
        "org/flowable/form/engine/test/deployment/simpleInt.form"
})
public void startProcessInstanceWithFormVariables() {
    RuntimeService runtimeService = flowableRule.getProcessEngine().getRuntimeService();
    FormInfo formInfo = formRepositoryService.getFormModelByKey("simpleIntForm");
    String procId = runtimeService.createProcessInstanceBuilder()
            .processDefinitionKey("oneTaskProcess")
            .formVariables(Collections.singletonMap("intVar", "42"), formInfo, "simple")
            .start()
            .getId();

    assertThat(runtimeService.getVariables(procId))
            .containsOnly(
                    entry("intVar", 42L),
                    entry("form_simpleIntForm_outcome", "simple")
            );
}
 
示例14
@Test
public void completeTaskWithoutValidationOnConfiguration(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService, TaskService taskService) {
    ((ProcessEngineConfigurationImpl) processEngineConfiguration).setFormFieldValidationEnabled(false);
    try {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskWithFormSideEffectProcess");
        assertThat(SideEffectExecutionListener.getSideEffect()).isEqualTo(1);
        SideEffectExecutionListener.reset();

        Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

        FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService();
        FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey("form1").singleResult();

        taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator"));

        assertThat(SideEffectExecutionListener.getSideEffect()).isEqualTo(1);
    } finally {
        ((ProcessEngineConfigurationImpl) processEngineConfiguration).setFormFieldValidationEnabled(true);
    }
}
 
示例15
@Test
public void completeTaskWithoutValidationOnModelLevel(RuntimeService runtimeService,
    TaskService taskService, RepositoryService repositoryService) {

    Deployment deployment = repositoryService.createDeployment().
        addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml",
            ONE_TASK_PROCESS.
                replace("START_EVENT_VALIDATION", "false").
                replace("USER_TASK_VALIDATION", "false")
        ).
        deploy();
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceWithForm(processDefinition.getId(),"__COMPLETE", Collections.emptyMap(),
        "oneTaskWithFormSideEffectProcess");
    assertThat(SideEffectExecutionListener.getSideEffect()).isEqualTo(1);
    SideEffectExecutionListener.reset();

    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService();
    FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey("form1").singleResult();

    taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator"));

    assertThat(SideEffectExecutionListener.getSideEffect()).isEqualTo(1);
}
 
示例16
private ExecutionQuery createExecutionQueryMock() {
    RuntimeService mockRuntimeService = Mockito.mock(RuntimeService.class);
    when(processEngineConfiguration.getRuntimeService()).thenReturn(mockRuntimeService);
    ExecutionQuery mockExecutionQuery = Mockito.mock(ExecutionQuery.class);
    when(mockRuntimeService.createExecutionQuery()).thenReturn(mockExecutionQuery);
    return mockExecutionQuery;
}
 
示例17
@Override
public void setCamelContext(CamelContext context) {
    super.setCamelContext(context);
    identityService = getByType(context, IdentityService.class);
    runtimeService = getByType(context, RuntimeService.class);
    repositoryService = getByType(context, RepositoryService.class);
    managementService = getByType(context, ManagementService.class);
}
 
示例18
public static RuntimeService getRuntimeService() {
    Stack<ProcessEngine> stack = getStack(processEngineThreadLocal);
    if (stack.isEmpty()) {
        return null;
    }
    return stack.peek().getRuntimeService();
}
 
示例19
@Test
public void testStep() throws Exception {

    recordEvents();

    SimulationDebugger simDebugger = createDebugger();

    simDebugger.init(new NoExecutionVariableScope());

    RuntimeService runtimeService = SimulationRunContext.getRuntimeService();
    TaskService taskService = SimulationRunContext.getTaskService();
    HistoryService historyService = SimulationRunContext.getHistoryService();

    // debugger step - deploy processDefinition
    simDebugger.step();
    step0Check(SimulationRunContext.getRepositoryService());

    // debugger step - start process and stay on the userTask
    simDebugger.step();
    step1Check(runtimeService, taskService);

    // debugger step - complete userTask and finish process
    simDebugger.step();
    step2Check(runtimeService, taskService);

    checkStatus(historyService);

    simDebugger.close();
    ProcessEngines.destroy();
}
 
示例20
@Test
public void testRunToTime() throws Exception {

    recordEvents();

    SimulationDebugger simDebugger = createDebugger();

    simDebugger.init(new NoExecutionVariableScope());

    RuntimeService runtimeService = SimulationRunContext.getRuntimeService();
    TaskService taskService = SimulationRunContext.getTaskService();
    HistoryService historyService = SimulationRunContext.getHistoryService();

    simDebugger.runTo(0);
    ProcessInstance procInstance = runtimeService.createProcessInstanceQuery().active().processInstanceBusinessKey("oneTaskProcessBusinessKey").singleResult();
    assertNull(procInstance);

    // debugger step - deploy process
    simDebugger.runTo(1);
    step0Check(SimulationRunContext.getRepositoryService());

    // debugger step - start process and stay on the userTask
    simDebugger.runTo(1001);
    step1Check(runtimeService, taskService);

    // process engine should be in the same state as before
    simDebugger.runTo(2000);
    step1Check(runtimeService, taskService);

    // debugger step - complete userTask and finish process
    simDebugger.runTo(2500);
    step2Check(runtimeService, taskService);

    checkStatus(historyService);

    simDebugger.close();
    ProcessEngines.destroy();
}
 
示例21
private void step1Check(RuntimeService runtimeService, TaskService taskService) {
    ProcessInstance procInstance;
    procInstance = runtimeService.createProcessInstanceQuery().active().processInstanceBusinessKey("oneTaskProcessBusinessKey").singleResult();
    assertNotNull(procInstance);
    Task t = taskService.createTaskQuery().active().taskDefinitionKey("userTask").singleResult();
    assertNotNull(t);
}
 
示例22
@Test
public void testProcessInstanceStartEvents() throws Exception {
    ProcessEngineImpl processEngine = initProcessEngine();

    TaskService taskService = processEngine.getTaskService();
    RuntimeService runtimeService = processEngine.getRuntimeService();

    Map<String, Object> variables = new HashMap<>();
    variables.put(TEST_VARIABLE, TEST_VALUE);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(USERTASK_PROCESS, BUSINESS_KEY, variables);

    Task task = taskService.createTaskQuery().taskDefinitionKey("userTask").singleResult();
    TimeUnit.MILLISECONDS.sleep(50);
    taskService.complete(task.getId());

    final SimulationDebugger simRun = new ReplaySimulationRun(processEngine, getReplayHandlers(processInstance.getId()));

    simRun.init(new NoExecutionVariableScope());

    // original process is finished - there should not be any running process instance/task
    assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
    assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

    simRun.step();

    // replay process was started
    assertEquals(1, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
    // there should be one task
    assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

    simRun.step();

    // userTask was completed - replay process was finished
    assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
    assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

    simRun.close();
    processEngine.close();
    ProcessEngines.destroy();
}
 
示例23
@Test
@Deployment
public void ruleUsageExample() {
    RuntimeService runtimeService = activitiRule.getRuntimeService();
    runtimeService.startProcessInstanceByKey("ruleUsage");

    TaskService taskService = activitiRule.getTaskService();
    org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult();
    assertEquals("My Task", task.getName());

    taskService.complete(task.getId());
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
 
示例24
@Test
public void completeTaskWithValidationOnMissingModelLevel(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService,
    TaskService taskService, RepositoryService repositoryService) {

    repositoryService.createDeployment().
        addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml",
            ONE_TASK_PROCESS.
                replace("flowable:formFieldValidation=\"START_EVENT_VALIDATION\"", "").
                replace("flowable:formFieldValidation=\"USER_TASK_VALIDATION\"", "")
        ).
        deploy();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
        "oneTaskWithFormSideEffectProcess",
        Collections.emptyMap()
    );
    SideEffectExecutionListener.reset();

    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService();
    FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey("form1").singleResult();

    assertThatThrownBy(() -> taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator")))
            .isInstanceOf(RuntimeException.class)
            .hasMessage("validation failed");

    assertThat(SideEffectExecutionListener.getSideEffect()).isZero();
}
 
示例25
@Bean
CommandLineRunner basics(final RuntimeService runtimeService) {
    return new CommandLineRunner() {
        @Override
        public void run(String... strings) throws Exception {
            runtimeService.startProcessInstanceByKey("waiter", Collections.singletonMap("customerId", (Object) 243L));
        }
    };
}
 
示例26
@Bean
CommandLineRunner startProcess(final RuntimeService runtimeService, final TaskService taskService) {
    return new CommandLineRunner() {
        @Override
        public void run(String... strings) throws Exception {
            for (int i = 0; i < 10; i++)
                runtimeService.startProcessInstanceByKey("waiter", Collections.singletonMap("customerId", (Object) i));

            for (int i = 0; i < 7; i++)
                taskService.complete(taskService.createTaskQuery().list().get(0).getId());
        }
    };
}
 
示例27
@Before
public void setupServer() {
    if (serverUrlPrefix == null) {
        TestServer testServer = TestServerUtil.createAndStartServer(ObjectVariableSerializationDisabledApplicationConfiguration.class);
        serverUrlPrefix = testServer.getServerUrlPrefix();

        this.repositoryService = testServer.getApplicationContext().getBean(RepositoryService.class);
        this.runtimeService = testServer.getApplicationContext().getBean(RuntimeService.class);
        this.identityService = testServer.getApplicationContext().getBean(IdentityService.class);
        this.taskService = testServer.getApplicationContext().getBean(TaskService.class);

        User user = identityService.newUser("kermit");
        user.setFirstName("Kermit");
        user.setLastName("the Frog");
        user.setPassword("kermit");
        identityService.saveUser(user);

        Group group = identityService.newGroup("admin");
        group.setName("Administrators");
        identityService.saveGroup(group);

        identityService.createMembership(user.getId(), group.getId());

        this.testUserId = user.getId();
        this.testGroupId = group.getId();
    }
}
 
示例28
@Override
protected void eventReceived(EventInstance eventInstance) {

    // Fetching the event subscriptions happens in one transaction,
    // executing them one per subscription. There is no overarching transaction.
    // The reason for this is that the handling of one event subscription
    // should not influence (i.e. roll back) the handling of another.

    Collection<CorrelationKey> correlationKeys = generateCorrelationKeys(eventInstance.getCorrelationParameterInstances());
    List<EventSubscription> eventSubscriptions = findEventSubscriptions(ScopeTypes.BPMN, eventInstance, correlationKeys);
    RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
    for (EventSubscription eventSubscription : eventSubscriptions) {
        handleEventSubscription(runtimeService, eventSubscription, eventInstance, correlationKeys);
    }
}
 
示例29
@Test
@Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void logProcessTaskEvents(RuntimeService runtimeService, TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    assertThat(processInstance).isNotNull();

    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task).isNotNull();
    try {
        taskService.setAssignee(task.getId(), "newAssignee");
        taskService.setOwner(task.getId(), "newOwner");
        taskService.complete(task.getId());

        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
            assertThat(logEntries).hasSize(4);

            HistoricTaskLogEntry logEntry = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_CREATED").singleResult();
            assertThat(logEntry).isNotNull();
            assertThat(logEntry.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
            assertThat(logEntry.getExecutionId()).isEqualTo(task.getExecutionId());
            assertThat(logEntry.getProcessInstanceId()).isEqualTo(processInstance.getId());

            assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_ASSIGNEE_CHANGED").count()).isEqualTo(1);
            assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_OWNER_CHANGED").count()).isEqualTo(1);
            assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_COMPLETED").count()).isEqualTo(1);
        }

    } finally {
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId());
    }
}
 
示例30
@Test
@Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void logAddCandidateUser(RuntimeService runtimeService, TaskService taskService, HistoryService historyService,
        ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    try {
        assertThat(processInstance).isNotNull();
        assertThat(task).isNotNull();

        taskService.addCandidateUser(task.getId(), "newCandidateUser");

        if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) {
            List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
            assertThat(logEntries).hasSize(2);

            logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId())
                    .type("USER_TASK_IDENTITY_LINK_ADDED")
                    .list();
            assertThat(logEntries).hasSize(1);
            assertThat(logEntries.get(0).getData()).contains(
                    "\"type\":\"candidate\"",
                    "\"userId\":\"newCandidateUser\""
            );
        }

    } finally {
        taskService.complete(task.getId());
        deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId());
    }
}