Java Code Examples for org.activiti.engine.ProcessEngine#getRuntimeService()

The following examples show how to use org.activiti.engine.ProcessEngine#getRuntimeService() . 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: MuleHttpTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@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").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();
}
 
Example 2
Source File: ApprovalTestApplication.java    From crnk-framework with Apache License 2.0 6 votes vote down vote up
public ApprovalTestApplication() {
    property(CrnkProperties.RESOURCE_DEFAULT_DOMAIN, "http://test.local");

    CrnkFeature feature = new CrnkFeature();
    initObjectMapper(feature);

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    TaskService taskService = processEngine.getTaskService();
    ModuleRegistry moduleRegistry = feature.getBoot().getModuleRegistry();

    processEngine.getRepositoryService().createDeployment()
            .addClasspathResource("approval.bpmn20.xml")
            .deploy();

    ActivitiResourceMapper resourceMapper =
            new ActivitiResourceMapper(moduleRegistry.getTypeParser(), new DefaultDateTimeMapper());
    ApprovalMapper mapper = new ApprovalMapper();
    ApprovalManager approvalManager = new ApprovalManagerFactory().getInstance();
    approvalManager.init(runtimeService, taskService, resourceMapper, mapper, moduleRegistry);
    feature.addModule(createApprovalModule(approvalManager));
    feature.addModule(createActivitiModule(processEngine));
    feature.addModule(new TestModule());

    registerInstances(feature);
}
 
Example 3
Source File: MuleHttpBasicAuthTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@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").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();
}
 
Example 4
Source File: MuleVMTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
public void send() throws Exception {
  Assert.assertTrue(muleContext.isStarted());

  ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  RepositoryService repositoryService = processEngine.getRepositoryService();
  Deployment deployment = repositoryService.createDeployment()
      .addClasspathResource("org/activiti5/mule/testVM.bpmn20.xml")
      .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_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();
}
 
Example 5
Source File: MuleHttpBasicAuthTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
public void httpWithBasicAuth() throws Exception {
  Assert.assertTrue(muleContext.isStarted());

  ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  Deployment deployment = processEngine.getRepositoryService()
      .createDeployment()
      .addClasspathResource("org/activiti5/mule/testHttpBasicAuth.bpmn20.xml")
      .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_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();
}
 
Example 6
Source File: JavaDelegateTestDataGenerator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void generateTestData(ProcessEngine processEngine) {
  RepositoryService repositoryService = processEngine.getRepositoryService();
  repositoryService.createDeployment().addClasspathResource("javaDelegateProcess.bpmn20.xml").deploy();
  
  RuntimeService runtimeService = processEngine.getRuntimeService();
  runtimeService.startProcessInstanceByKey("javaDelegateTestProcess");
}
 
Example 7
Source File: AsyncFailingJobTestDataGenerator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void generateTestData(ProcessEngine processEngine) {
    RepositoryService repositoryService = processEngine.getRepositoryService();
    repositoryService.createDeployment().addClasspathResource("async-failing-expression.bpmn20.xml").deploy();

    RuntimeService runtimeService = processEngine.getRuntimeService();
    runtimeService.startProcessInstanceByKey("asyncFailingExpression");
}
 
Example 8
Source File: ParseHandlerTestDataGenerator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void generateTestData(ProcessEngine processEngine) {
  RepositoryService repositoryService = processEngine.getRepositoryService();
  repositoryService.createDeployment().addClasspathResource("parseHandlerProcess.bpmn20.xml").deploy();
  
  RuntimeService runtimeService = processEngine.getRuntimeService();
  runtimeService.startProcessInstanceByKey("parseHandlerTestProcess");
}
 
Example 9
Source File: JavaDelegateTestDataGenerator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void generateTestData(ProcessEngine processEngine) {
    RepositoryService repositoryService = processEngine.getRepositoryService();
    repositoryService.createDeployment().addClasspathResource("javaDelegateProcess.bpmn20.xml").deploy();

    RuntimeService runtimeService = processEngine.getRuntimeService();
    runtimeService.startProcessInstanceByKey("javaDelegateTestProcess");
}
 
Example 10
Source File: ProcessExecutionIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test(expected = ActivitiException.class)
public void givenProcessDefinition_whenSuspend_thenNoProcessInstanceCreated() {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    repositoryService.createDeployment()
      .addClasspathResource("org/activiti/test/vacationRequest.bpmn20.xml")
      .deploy();

    RuntimeService runtimeService = processEngine.getRuntimeService();
    repositoryService.suspendProcessDefinitionByKey("vacationRequest");
    runtimeService.startProcessInstanceByKey("vacationRequest");
}
 
Example 11
Source File: ExpressionInJavaDelegateTestDataGenerator.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void generateTestData(ProcessEngine processEngine) {
  RepositoryService repositoryService = processEngine.getRepositoryService();
  repositoryService.createDeployment().addClasspathResource("expressionInJavaDelegateProcess.bpmn20.xml").deploy();
  
  RuntimeService runtimeService = processEngine.getRuntimeService();
  runtimeService.startProcessInstanceByKey("expressionInJavaDelegate");
}
 
Example 12
Source File: StartProcessInstanceTestDataGenerator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void generateTestData(ProcessEngine processEngine) {
    RepositoryService repositoryService = processEngine.getRepositoryService();
    repositoryService.createDeployment().addClasspathResource("oneTaskProcess.bpmn20.xml").deploy();

    RuntimeService runtimeService = processEngine.getRuntimeService();
    runtimeService.startProcessInstanceByKey("oneTaskProcess", "activitiv5-one-task-process");
}
 
Example 13
Source File: ActivitiUtil.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ActivitiUtil(ProcessEngine engine, boolean deployWorkflowsInTenant)
{
    this.repoService = engine.getRepositoryService();
    this.runtimeService = engine.getRuntimeService();
    this.taskService = engine.getTaskService();
    this.historyService = engine.getHistoryService();
    this.formService = engine.getFormService();
    this.managementService = engine.getManagementService();
    this.deployWorkflowsInTenant = deployWorkflowsInTenant;
}
 
Example 14
Source File: ActivitiUtil.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ActivitiUtil(ProcessEngine engine, boolean deployWorkflowsInTenant, boolean retentionHistoricProcessInstance)
{
    this.repoService = engine.getRepositoryService();
    this.runtimeService = engine.getRuntimeService();
    this.taskService = engine.getTaskService();
    this.historyService = engine.getHistoryService();
    this.formService = engine.getFormService();
    this.managementService = engine.getManagementService();
    this.deployWorkflowsInTenant = deployWorkflowsInTenant;
    this.retentionHistoricProcessInstance = retentionHistoricProcessInstance;
}
 
Example 15
Source File: ActivitiTypeConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ActivitiTypeConverter(ProcessEngine processEngine, 
            WorkflowObjectFactory factory,
            ActivitiPropertyConverter propertyConverter, boolean deployWorkflowsInTenant)
{
    this.runtimeService = processEngine.getRuntimeService();
    this.formService = processEngine.getFormService();
    this.historyService = processEngine.getHistoryService();
    this.factory = factory;
    this.propertyConverter =propertyConverter;
    this.activitiUtil = new ActivitiUtil(processEngine, deployWorkflowsInTenant);
}
 
Example 16
Source File: ActivitiSmokeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testDeploy() throws Exception
    {
        ProcessEngine engine = buildProcessEngine();

        RepositoryService repoService = engine.getRepositoryService();

        Deployment deployment = deployDefinition(repoService);

        assertNotNull(deployment);

        RuntimeService runtimeService = engine.getRuntimeService();
        try
        {
            ProcessInstance instance = runtimeService.startProcessInstanceByKey("testTask");
            assertNotNull(instance);
            
            String instanceId = instance.getId();
            ProcessInstance instanceInDb = findProcessInstance(runtimeService, instanceId);
            assertNotNull(instanceInDb);
            runtimeService.deleteProcessInstance(instanceId, "");
        }
        finally
        {
            
//            List<Deployment> deployments = repoService.createDeploymentQuery().list();
//            for (Deployment deployment2 : deployments)
//            {
//                repoService.deleteDeployment(deployment2.getId());
//            }
            
            repoService.deleteDeployment(deployment.getId());
        }
    }
 
Example 17
Source File: App.java    From CrazyWorkflowHandoutsActiviti6 with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	// 新建流程引擎
	ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
	// 存储服务
	RepositoryService repositoryService = engine.getRepositoryService();
	// 运行时服务
	RuntimeService runtimeService = engine.getRuntimeService();
	// 任务服务
	TaskService taskService =engine.getTaskService();
	// 部署服务
	repositoryService.createDeployment().addClasspathResource("MyFirstProcess.bpmn").deploy();
	// process的id属性
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess");
	
	// 普通员工完成请假的任务
	Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("当前流程节点:" + task.getName());
	taskService.complete(task.getId());
	
	// 经理审批任务
	task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("当前流程节点:" + task.getName());
	taskService.complete(task.getId());
	
	// 流程结束
	task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
	System.out.println("流程结束:" + task);
	// 关闭流程引擎
	engine.close();
}
 
Example 18
Source File: AbstractProcessEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public RuntimeService runtimeServiceBean(ProcessEngine processEngine) {
  return processEngine.getRuntimeService();
}
 
Example 19
Source File: ProcessDefinitionCacheTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {

    // Setup both process engines
    ProcessEngine processEngine1 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test-schema")
        .setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000")
        .setAsyncExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService1 = processEngine1.getRepositoryService();

    ProcessEngine processEngine2 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test")
        .setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000")
        .setAsyncExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService2 = processEngine2.getRepositoryService();
    RuntimeService runtimeService2 = processEngine2.getRuntimeService();
    TaskService taskService2 = processEngine2.getTaskService();

    // Deploy first version of process: start->originalTask->end on first
    // process engine
    String deploymentId = repositoryService1.createDeployment().addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy().getId();

    // Start process instance on second engine
    String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceById(processDefinitionId);
    Task task = taskService2.createTaskQuery().singleResult();
    assertEquals("original task", task.getName());

    // Delete the deployment on second process engine
    repositoryService2.deleteDeployment(deploymentId, true);
    assertEquals(0, repositoryService2.createDeploymentQuery().count());
    assertEquals(0, runtimeService2.createProcessInstanceQuery().count());

    // deploy a revised version of the process: start->revisedTask->end on
    // first process engine
    //
    // Before the bugfix, this would set the cache on the first process
    // engine,
    // but the second process engine still has the original process
    // definition in his cache.
    // Since there is a deployment delete in between, the new generated
    // process definition id is the same
    // as in the original deployment, making the second process engine using
    // the old cached process definition.
    deploymentId = repositoryService1.createDeployment().addClasspathResource("org/activiti/engine/test/cache/revisedProcess.bpmn20.xml").deploy().getId();

    // Start process instance on second process engine -> must use revised
    // process definition
    repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceByKey("oneTaskProcess");
    task = taskService2.createTaskQuery().singleResult();
    assertEquals("revised task", task.getName());

    // cleanup
    repositoryService1.deleteDeployment(deploymentId, true);
    processEngine1.close();
    processEngine2.close();
  }
 
Example 20
Source File: ProcessDefinitionCacheTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {
  
  // Setup both process engines
  StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration();
  standaloneProcessEngineConfiguration.setProcessEngineName("reboot-test-schema");
  standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate(org.activiti5.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
  standaloneProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000");
  standaloneProcessEngineConfiguration.setAsyncExecutorActivate(false);
  standaloneProcessEngineConfiguration.setActiviti5CompatibilityEnabled(true);
  ProcessEngine processEngine1 = standaloneProcessEngineConfiguration.buildProcessEngine();
  RepositoryService repositoryService1 = processEngine1.getRepositoryService();
  
  StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration2 = new StandaloneProcessEngineConfiguration();
  standaloneProcessEngineConfiguration2.setProcessEngineName("reboot-test");
  standaloneProcessEngineConfiguration2.setDatabaseSchemaUpdate(org.activiti5.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE);
  standaloneProcessEngineConfiguration2.setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000");
  standaloneProcessEngineConfiguration2.setAsyncExecutorActivate(false);
  standaloneProcessEngineConfiguration2.setActiviti5CompatibilityEnabled(true);
  ProcessEngine processEngine2  = standaloneProcessEngineConfiguration2.buildProcessEngine();
  RepositoryService repositoryService2 = processEngine2.getRepositoryService();
  RuntimeService runtimeService2 = processEngine2.getRuntimeService();
  TaskService taskService2 = processEngine2.getTaskService();
  
  // Deploy first version of process: start->originalTask->end on first process engine
  String deploymentId = repositoryService1.createDeployment()
    .addClasspathResource("org/activiti5/engine/test/cache/originalProcess.bpmn20.xml")
    .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE)
    .deploy()
    .getId();
  
  // Start process instance on second engine
  String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
  runtimeService2.startProcessInstanceById(processDefinitionId);
  Task task = taskService2.createTaskQuery().singleResult();
  assertEquals("original task", task.getName());
  
  // Delete the deployment on second process engine
  repositoryService2.deleteDeployment(deploymentId, true);
  assertEquals(0, repositoryService2.createDeploymentQuery().count());
  assertEquals(0, runtimeService2.createProcessInstanceQuery().count());
  
  // deploy a revised version of the process: start->revisedTask->end on first process engine
  //
  // Before the bugfix, this would set the cache on the first process engine,
  // but the second process engine still has the original process definition in his cache.
  // Since there is a deployment delete in between, the new generated process definition id is the same 
  // as in the original deployment, making the second process engine using the old cached process definition.
  deploymentId = repositoryService1.createDeployment()
    .addClasspathResource("org/activiti5/engine/test/cache/revisedProcess.bpmn20.xml")
    .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE)
    .deploy()
    .getId();
  
  // Start process instance on second process engine -> must use revised process definition
  repositoryService2.createProcessDefinitionQuery().singleResult().getId();
  runtimeService2.startProcessInstanceByKey("oneTaskProcess");
  task = taskService2.createTaskQuery().singleResult();
  assertEquals("revised task", task.getName());
  
  // cleanup
  repositoryService1.deleteDeployment(deploymentId, true);
  processEngine1.close();
  processEngine2.close();
}