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();
}
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();
}
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);
}
}
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();
}
}
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");
}
Aggregations