Search in sources :

Example 6 with RuntimeService

use of org.activiti.engine.RuntimeService in project Activiti by Activiti.

the class ReplayRunTest method testProcessInstanceStartEvents.

@Test
public void testProcessInstanceStartEvents() throws Exception {
    ProcessEngineImpl processEngine = initProcessEngine();
    TaskService taskService = processEngine.getTaskService();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    Map<String, Object> variables = new HashMap<String, Object>();
    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();
}
Also used : ReplaySimulationRun(org.activiti.crystalball.simulator.ReplaySimulationRun) Task(org.activiti.engine.task.Task) RuntimeService(org.activiti.engine.RuntimeService) TaskService(org.activiti.engine.TaskService) SimulationDebugger(org.activiti.crystalball.simulator.SimulationDebugger) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl) Test(org.junit.Test)

Example 7 with RuntimeService

use of org.activiti.engine.RuntimeService in project Activiti by Activiti.

the class MuleVMTest method send.

@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").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();
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) Deployment(org.activiti.engine.repository.Deployment) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService) Test(org.junit.Test)

Example 8 with RuntimeService

use of org.activiti.engine.RuntimeService in project midpoint by Evolveum.

the class ActivitiInterface method startActivitiProcessInstance.

public void startActivitiProcessInstance(StartProcessCommand spic, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
    String owner = spic.getProcessOwner();
    if (owner != null) {
        activitiEngine.getIdentityService().setAuthenticatedUserId(owner);
    }
    RuntimeService rs = activitiEngine.getProcessEngine().getRuntimeService();
    ProcessInstanceBuilder builder = rs.createProcessInstanceBuilder().processDefinitionKey(spic.getProcessName()).processInstanceName(spic.getProcessInstanceName());
    for (Map.Entry<String, Object> varEntry : spic.getVariables().entrySet()) {
        builder.addVariable(varEntry.getKey(), varEntry.getValue());
    }
    ProcessInstance pi = builder.start();
    if (spic.isSendStartConfirmation()) {
        // let us send a reply back (useful for listener-free processes)
        ProcessStartedEvent event = new ProcessStartedEvent(pi.getProcessInstanceId(), // a bit of hack...
        ((ExecutionEntity) pi).getVariables(), processInterfaceFinder);
        event.setRunning(!pi.isEnded());
        LOGGER.trace("Event to be sent to IDM: {}", event);
        wfTaskController.onProcessEvent(event, task, result);
    }
}
Also used : ProcessInstanceBuilder(org.activiti.engine.runtime.ProcessInstanceBuilder) RuntimeService(org.activiti.engine.RuntimeService) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with RuntimeService

use of org.activiti.engine.RuntimeService in project midpoint by Evolveum.

the class ProcessInstanceManager method stopProcessInstance.

public void stopProcessInstance(String instanceId, String username, OperationResult parentResult) {
    OperationResult result = parentResult.createSubresult(OPERATION_STOP_PROCESS_INSTANCE);
    result.addParam("instanceId", instanceId);
    RuntimeService rs = activitiEngine.getRuntimeService();
    try {
        LOGGER.trace("Stopping process instance {} on the request of {}", instanceId, username);
        String deletionMessage = "Process instance stopped on the request of " + username;
        rs.setVariable(instanceId, CommonProcessVariableNames.VARIABLE_PROCESS_INSTANCE_IS_STOPPING, Boolean.TRUE);
        rs.deleteProcessInstance(instanceId, deletionMessage);
    } catch (RuntimeException e) {
        result.recordFatalError("Process instance couldn't be stopped: " + e.getMessage(), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 10 with RuntimeService

use of org.activiti.engine.RuntimeService in project Activiti by Activiti.

the class StartProcessInstanceTestDelegate method execute.

public void execute(DelegateExecution execution) throws Exception {
    RuntimeService runtimeService = execution.getEngineServices().getRuntimeService();
    runtimeService.startProcessInstanceByKey("oneTaskProcess");
}
Also used : RuntimeService(org.activiti.engine.RuntimeService)

Aggregations

RuntimeService (org.activiti.engine.RuntimeService)19 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 Test (org.junit.Test)9 ProcessEngine (org.activiti.engine.ProcessEngine)6 TaskService (org.activiti.engine.TaskService)6 Task (org.activiti.engine.task.Task)5 HashMap (java.util.HashMap)4 RepositoryService (org.activiti.engine.RepositoryService)4 Deployment (org.activiti.engine.repository.Deployment)3 ReplaySimulationRun (org.activiti.crystalball.simulator.ReplaySimulationRun)2 SimulationDebugger (org.activiti.crystalball.simulator.SimulationDebugger)2 ManagementService (org.activiti.engine.ManagementService)2 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)2 StandaloneProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration)2 NoExecutionVariableScope (org.activiti.engine.impl.el.NoExecutionVariableScope)2 Deployment (org.activiti.engine.test.Deployment)2 SearchResultList (com.evolveum.midpoint.schema.SearchResultList)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1 Map (java.util.Map)1